Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / scout / buttons / src / buttons.cpp @ 8de28e68

History | View | Annotate | Download (3.54 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 buttons.cpp
28
 * @brief Contains code to control the buttons.
29
 *
30
 * Implementation of functions for button use.
31
 *
32
 * @author Colony Project, CMU Robotics Club
33
 * @author Priyanka Deo
34
 **/
35

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

    
40
/**
41
 * @defgroup buttons Buttons
42
 * @brief Functions for using the buttons
43
 *
44
 * @{
45
 **/
46

    
47
/* Button state variables
48
 */
49
static int button1_pressed; /**< Whether or not button 1 is pressed. */
50
static int button2_pressed; /**< Whether or not button 2 is pressed. */
51

    
52
/**
53
 * @brief Handles button events
54
 *
55
 * Handles button events based on subscription to the button_event topic.
56
 *
57
 * @param msg The message from the button_event topic, containing buttons
58
 * statuses.
59
 */
60
void event_button(const buttons::button_event::ConstPtr& msg)
61
{
62
    //TODO: What goes here?
63
}
64

    
65

    
66
/**
67
 * @brief Outputs whether or not the buttons are pressed.
68
 *
69
 * Serves the service query_buttons by responding to service requests 
70
 * with the status of the buttons
71
 * @param req The request. The only field is the units requested.
72
 * @param res The response. The fields will be filled with values.
73
 */
74
bool buttons_query(buttons::query_buttons::Request &req,
75
                  buttons::query_buttons::Response &res)
76
{
77
    int units = req.units;
78
    res.button1_pressed = button1_pressed;
79
    res.button2_pressed = button2_pressed;
80

    
81
    ROS_DEBUG("Button status queried");
82
    return true;
83
}
84

    
85

    
86
/**
87
 * @brief Buttons driver. This is a ROS node that queries button status.
88
 *
89
 * This is the main function for the buttons node. It is run
90
 * when the node starts and initializes the buttons. It then 
91
 * subscribes to the event_button topics, and advertises the 
92
 * query_buttons service.
93
 * 
94
 * @param argc The number of command line arguments (should be 1)
95
 * @param argv The array of command line arguments
96
 **/
97
int main(int argc, char **argv)
98
{
99
    /* Initialize in ROS the buttons driver node */
100
    ros::init(argc, argv, "buttons_driver");
101

    
102
    /* Advertise that this serves the query_buttons service */
103
    ros::NodeHandle n;
104
    ros::ServiceServer service = n.advertiseService("query_buttons",
105
                                                    buttons_query);
106

    
107
    /* Subscribe to the button_event topic */
108
    ros::Subscriber sub0 = n.subscribe("button_event", 4, event_button);
109

    
110
    /* Initialize hardware for buttons */
111
    // Hardware init functions here
112

    
113
    ROS_INFO("Ready to query buttons.");
114
    ros::spin();
115

    
116
    return 0;
117
}
118

    
119
/** @} **/