Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / scout / cliffsensor / src / cliffsensor.cpp @ 75a7571a

History | View | Annotate | Download (3.96 KB)

1
/**
2
 * Copyright (c) 2011 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

    
26
/**
27
 * @file cliffsensor.cpp
28
 * @brief Contains code to control the cliffsensor.
29
 *
30
 * Implementation of functions for cliffsensor use.
31
 *
32
 * @author Colony Project, CMU Robotics Club
33
 * @author Priyanka Deo
34
 **/
35

    
36
#include "ros/ros.h"
37
#include "cliffsensor.h"
38
#include <cstdlib>
39

    
40
/**
41
 * @defgroup cliffsensor Cliffsensor
42
 * @brief Functions for using the cliffsensors
43
 *
44
 * @{
45
 **/
46

    
47
/* Cliffsensor state variables
48
 */
49
static int front_raw; /**< The current raw value data of the front cliffsensor. */
50
static int left_raw; /**< The current raw value data of the left cliffsensor. */
51
static int back_raw; /**< The current raw value data of the right cliffsensor. */
52
static bool is_cliff; /**< Boolean to represent whether or not there is a cliff. */
53

    
54
/**
55
 * @brief Changes cliff sensor status
56
 *
57
 * Changes cliff sensor status based on subscription to topic cliff_status_changed
58
 *
59
 * @param msg The message from the cliff_status_changed topic, containing 
60
 * status of all cliff sensors.
61
 */
62
void changed_cliff_status(const cliffsensor::cliff_status_changed::ConstPtr& msg)
63
{
64
  return;
65
}
66

    
67
/**
68
 * @brief Outputs status of cliffsensors
69
 *
70
 * Serves the service query_cliff by responding to service requests with the
71
 * status of the cliff sensors.
72
 * @param req The request. The only field is the units requested.
73
 * @param res The response. The fields will be filled with values.
74
 */
75
bool cliff_query(cliffsensor::query_cliff::Request &req,
76
                  cliffsensor::query_cliff::Response &res)
77
{
78
    int threshold = 500; //TODO fix after figuring out what sensors give us
79
    res.front_raw = front_raw; 
80
    res.left_raw = left_raw;
81
    res.right_raw = back_raw;
82
    res.cliff_status = is_cliff;
83

    
84
    ROS_DEBUG("Cliffsensor status queried");
85
    return true;
86
}
87

    
88
/**
89
 * @brief Cliffsensor driver. This is a ROS node that controls cliffsensor status.
90
 *
91
 * This is the main function for the cliffsensors node. It is run when the node
92
 * starts and initializes the cliffsensors. It then subscribes to the
93
 * cliff_status_changed topics, and advertises the
94
 * query_cliff service.
95
 * 
96
 * @param argc The number of command line arguments (should be 1)
97
 * @param argv The array of command line arguments
98
 **/
99
int main(int argc, char **argv)
100
{
101
    /* Initialize in ROS the cliffsensor driver node */
102
    ros::init(argc, argv, "cliffsensor_driver");
103

    
104
    /* Advertise that this serves the query_cliff service */
105
    ros::NodeHandle n;
106
    ros::ServiceServer service = n.advertiseService("query_cliff",
107
                                                    cliff_query);
108

    
109
    /* Subscribe to the cliff_status_changed topic */
110
    ros::Subscriber sub0 = n.subscribe("cliff_status_changed", 
111
                                        4, changed_cliff_status);
112

    
113
    /* Initialize hardware for cliffsensors */
114
    // Hardware init functions here
115

    
116
    ROS_INFO("Ready to query cliffsensors.");
117
    ros::spin();
118

    
119
    return 0;
120
}
121

    
122
/** @} **/