Project

General

Profile

Revision b00761a0

IDb00761a0e88f934a309a939b653d9f441b127ae8
Parent c492be62
Child 4069a378

Added by Alex Zirbel over 12 years ago

Updated ButtonControl and SonarControl.

Finally, the behavior compiles. Had to fix a lot of problems involving misunderstandings with Publisher/Client/ServiceServer/ServiceClient confusion.

We can now run priya_behavior as an executable, though the process for generating behavior executables still needs some work.

View differences:

scout/buttons/src/buttons.cpp
31 31
 *
32 32
 * @author Colony Project, CMU Robotics Club
33 33
 * @author Priyanka Deo
34
 * @author Alex Zirbel
34 35
 **/
35 36

  
36 37
#include "ros/ros.h"
......
50 51
static int button2_pressed; /**< Whether or not button 2 is pressed. */
51 52

  
52 53
/**
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 54
 * @brief Buttons driver. This is a ROS node that queries button status.
88 55
 *
89 56
 * This is the main function for the buttons node. It is run
......
93 60
 * 
94 61
 * @param argc The number of command line arguments (should be 1)
95 62
 * @param argv The array of command line arguments
96
 **/
63
 */
97 64
int main(int argc, char **argv)
98 65
{
99 66
    /* Initialize in ROS the buttons driver node */
......
101 68

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

  
107
    /* Subscribe to the button_event topic */
108
    ros::Subscriber sub0 = n.subscribe("button_event", 4, event_button);
72
    ros::Publisher pub = n.advertise<buttons::button_event>("button_event",
73
                                                            QUEUE_SIZE);
109 74

  
110 75
    /* Initialize hardware for buttons */
111 76
    // Hardware init functions here
77
    
78
    // Publish a button event now and then
112 79

  
113
    ROS_INFO("Ready to query buttons.");
80
    ROS_INFO("Ready to handle buttons. [unimplemented]");
114 81
    ros::spin();
115 82

  
116 83
    return 0;

Also available in: Unified diff