Project

General

Profile

Revision 04f50f8a

ID04f50f8a7157f48a484b1e29be4f7b0427008ab1

Added by Priya over 12 years ago

Added buttons and cliffsensor ROS nodes. Everything except for src/<node>.cpp file functions have been changed.

View differences:

scout/buttons/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
# Set the build type.  Options are:
5
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
6
#  Debug          : w/ debug symbols, w/o optimization
7
#  Release        : w/o debug symbols, w/ optimization
8
#  RelWithDebInfo : w/ debug symbols, w/ optimization
9
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
10
#set(ROS_BUILD_TYPE RelWithDebInfo)
11

  
12
rosbuild_init()
13

  
14
#set the default path for built executables to the "bin" directory
15
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
16
#set the default path for built libraries to the "lib" directory
17
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
18

  
19
#uncomment if you have defined messages
20
rosbuild_genmsg()
21
#uncomment if you have defined services
22
rosbuild_gensrv()
23

  
24
#common commands for building c++ executables and libraries
25
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
26
#target_link_libraries(${PROJECT_NAME} another_library)
27
#rosbuild_add_boost_directories()
28
#rosbuild_link_boost(${PROJECT_NAME} thread)
29
#rosbuild_add_executable(example examples/example.cpp)
30
#target_link_libraries(example ${PROJECT_NAME})
31

  
32
rosbuild_add_executable(motors_node src/motors.cpp)
scout/buttons/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/buttons/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b buttons is the ros node that will respond to button events.
6

  
7
<!-- 
8
Buttons will contain the functions neceessary for setting and responding to button events.
9
-->
10

  
11

  
12
\section codeapi Code API
13

  
14
<!--
15
Provide links to specific auto-generated API documentation within your
16
package that is of particular interest to a reader. Doxygen will
17
document pretty much every part of your code, so do your best here to
18
point the reader to the actual API.
19

  
20
If your codebase is fairly large or has different sets of APIs, you
21
should use the doxygen 'group' tag to keep these APIs together. For
22
example, the roscpp documentation has 'libros' group.
23
-->
24

  
25

  
26
*/
scout/buttons/manifest.xml
1
<package>
2
  <description brief="buttons">
3
     buttons
4
     Module to respond to button events.
5
  </description>
6
  <author>Priya</author>
7
  <license>BSD</license>
8
  <review status="unreviewed" notes=""/>
9
  <url>https://www.roboticsclub.org/redmine/projects/colonyscout/wiki</url>
10
  <depend package="roscpp"/>
11
  <depend package="std_msgs"/>
12

  
13
</package>
14

  
15

  
scout/buttons/msg/button_event.msg
1
Header header
2
int8 button1_pressed
3
int8 button2_pressed
scout/buttons/src/buttons.cpp
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 Sets motor speed
54
 *
55
 * Sets the motor speeds based on subscription to the set_motors topic.
56
 *
57
 * @param msg The message from the set_motors topic, containing speeds and
58
 *  motor configuration settings.
59
 */
60
void motors_set(const motors::set_motors::ConstPtr& msg)
61
{
62
    /** @todo Edit to only set requested motors, not all */
63
    int which = msg->which;
64
    if(which & MOTOR_FL_REV)
65
    {
66
      motor_fl_speed = -1 * motors_rel_to_abs(msg->fl_speed, msg->units);
67
    }
68
    if(which & MOTOR_FR_REV)
69
    {
70
      motor_fr_speed = -1 * motors_rel_to_abs(msg->fr_speed, msg->units);
71
    }
72
    if(which & MOTOR_BL_REV)
73
    {
74
      motor_bl_speed = -1 * motors_rel_to_abs(msg->bl_speed, msg->units);
75
    }
76
    if(which & MOTOR_BR_REV)
77
    {
78
      motor_br_speed = -1 * motors_rel_to_abs(msg->br_speed, msg->units);
79
    }
80
    if(which & MOTOR_FL)
81
    {
82
      motor_fl_speed = motors_rel_to_abs(msg->fl_speed, msg->units);
83
    }
84
    if(which & MOTOR_FR)
85
    {
86
      motor_fr_speed = motors_rel_to_abs(msg->fr_speed, msg->units);
87
    }
88
    if(which & MOTOR_BL)
89
    {
90
      motor_bl_speed = motors_rel_to_abs(msg->bl_speed, msg->units);
91
    }
92
    if(which & MOTOR_BR)
93
    {
94
      motor_br_speed = motors_rel_to_abs(msg->br_speed, msg->units);
95
    }
96

  
97
    /* Write speeds to hardware */
98
    /** @todo Add code to write speeds to hardware */
99
}
100

  
101
/**
102
 * @brief Outputs current motor speeds
103
 *
104
 * Serves the service query_motors by responding to service requests with the
105
 * speeds of the motors.
106
 * @param req The request. The only field is the units requested.
107
 * @param res The response. The fields will be filled with values.
108
 */
109
bool motors_query(motors::query_motors::Request &req,
110
                  motors::query_motors::Response &res)
111
{
112
    int units = req.units;
113
    res.fl_speed = motors_abs_to_rel(motor_fl_speed, units);
114
    res.fr_speed = motors_abs_to_rel(motor_fr_speed, units);
115
    res.bl_speed = motors_abs_to_rel(motor_bl_speed, units);
116
    res.br_speed = motors_abs_to_rel(motor_br_speed, units);
117

  
118
    ROS_DEBUG("Motor speeds queried");
119
    return true;
120
}
121

  
122
/**
123
 * @brief Converts set speeds (of various units) to absolute speeds.
124
 *
125
 * @param speed The speed expressed in the desired units
126
 * @param units The units the desired speed is measured in
127
 * @return The absolute speed of the motor
128
 **/
129
int motors_rel_to_abs(int rel_speed, int units)
130
{
131
    switch(units)
132
    {
133
      case MOTOR_ABSOLUTE:/* Speed given as absolute */
134
        return rel_speed;
135
      case MOTOR_PERCENT:/* Convert from percentage */
136
        return rel_speed * MAXSPEED / 100;
137
      case MOTOR_MMS:/* Convert from mm/s */
138
        /** @todo Make math to do this conversion **/
139
        return rel_speed;
140
      case MOTOR_CMS:/* Convert from cm/s */
141
        /** @todo Make math to do this conversion **/
142
        return rel_speed;
143
      default: /* The units aren't recognized */
144
        /** @todo Decide on default case. Either percent or absolute. **/
145
        return rel_speed;
146
    }
147
}
148

  
149
/**
150
 * @brief Convert absolute speeds to speeds of various units.
151
 *
152
 * @param speed The speed expressed in absolute units.
153
 * @param units The units the desired speed is measured in.
154
 * @return The relative speed of the motor in desired units.
155
 **/
156
int motors_abs_to_rel(int abs_speed, int units)
157
{
158
    switch(units)
159
    {
160
      case MOTOR_ABSOLUTE:/* Speed given as absolute */
161
        return abs_speed;
162
      case MOTOR_PERCENT:/* Convert from percentage */
163
        return abs_speed * 100 / MAXSPEED;
164
      case MOTOR_MMS:/* Convert from mm/s */
165
        /** @todo Make math to do this conversion **/
166
        return abs_speed;
167
      case MOTOR_CMS:/* Convert from cm/s */
168
        /** @todo Make math to do this conversion **/
169
        return abs_speed;
170
      default: /* The units aren't recognized */
171
        /** @todo Decide on default case. Either percent or absolute. **/
172
        return abs_speed;
173
    }
174
}
175

  
176
/**
177
 * @brief Motors driver. This is a ROS node that controls motor speeds.
178
 *
179
 * This is the main function for the motors node. It is run when the node
180
 * starts and initializes the motors. It then subscribes to the
181
 * set_motors, and set_motor_speeds topics, and advertises the
182
 * query_motors service.
183
 * 
184
 * @param argc The number of command line arguments (should be 1)
185
 * @param argv The array of command line arguments
186
 **/
187
int main(int argc, char **argv)
188
{
189
    /* Initialize in ROS the motors driver node */
190
    ros::init(argc, argv, "motors_driver");
191

  
192
    /* Advertise that this serves the query_motors service */
193
    ros::NodeHandle n;
194
    ros::ServiceServer service = n.advertiseService("query_motors",
195
                                                    motors_query);
196

  
197
    /* Subscribe to the set_motors topic */
198
    ros::Subscriber sub0 = n.subscribe("set_motors", 4, motors_set);
199

  
200
    /* Initialize hardware for motors */
201
    // Hardware init functions here
202

  
203
    ROS_INFO("Ready to set motors.");
204
    ros::spin();
205

  
206
    return 0;
207
}
208

  
209
/** @} **/
scout/buttons/src/buttons.h
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.h
28
 * @brief Contains buttons declarations and functions.
29
 * 
30
 * Contains functions and definitions for the use of
31
 * buttons.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Priyanka Deo
35
 **/
36

  
37
#ifndef _BUTTONS_H_
38
#define _BUTTONS_H_
39

  
40
#include "buttons/query_buttons.h"
41
#include "buttons/button_event.h"
42

  
43
#define BUTTON_PRESSED 0x1
44

  
45
/** @brief Initialize the buttons module and driver. **/
46
int main(int argc, char **argv);
47

  
48
/** @brief Responds to topic to notify of button events. **/
49
void event_button(const buttons::button_event::ConstPtr& msg);
50

  
51
/** @brief Responds to service to query buttons. **/
52
bool buttons_query(buttons::query_buttons::Request &req,
53
                  buttons::query_buttons::Response &res);
54

  
55
#endif
scout/buttons/srv/query_buttons.srv
1
int8 units
2
---
3
int8 button1_pressed
4
int8 button2_pressed
scout/buttons/srv/query_motors.srv
1
int8 units
2
---
3
int8 fl_speed
4
int8 fr_speed
5
int8 bl_speed
6
int8 br_speed
scout/cliffsensor/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
# Set the build type.  Options are:
5
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
6
#  Debug          : w/ debug symbols, w/o optimization
7
#  Release        : w/o debug symbols, w/ optimization
8
#  RelWithDebInfo : w/ debug symbols, w/ optimization
9
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
10
#set(ROS_BUILD_TYPE RelWithDebInfo)
11

  
12
rosbuild_init()
13

  
14
#set the default path for built executables to the "bin" directory
15
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
16
#set the default path for built libraries to the "lib" directory
17
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
18

  
19
#uncomment if you have defined messages
20
rosbuild_genmsg()
21
#uncomment if you have defined services
22
rosbuild_gensrv()
23

  
24
#common commands for building c++ executables and libraries
25
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
26
#target_link_libraries(${PROJECT_NAME} another_library)
27
#rosbuild_add_boost_directories()
28
#rosbuild_link_boost(${PROJECT_NAME} thread)
29
#rosbuild_add_executable(example examples/example.cpp)
30
#target_link_libraries(example ${PROJECT_NAME})
31

  
32
rosbuild_add_executable(motors_node src/motors.cpp)
scout/cliffsensor/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/cliffsensor/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b cliffsensor is the ros node that will read from the cliffsensors and detect cliffs and tell the motors to stop driving.
6

  
7
<!-- 
8
Cliffsensor will contain the functions necessary for reading from the cliffsensors and detecting cliffs (and behaviors associated with the cliffsensor).
9
-->
10

  
11

  
12
\section codeapi Code API
13

  
14
<!--
15
Provide links to specific auto-generated API documentation within your
16
package that is of particular interest to a reader. Doxygen will
17
document pretty much every part of your code, so do your best here to
18
point the reader to the actual API.
19

  
20
If your codebase is fairly large or has different sets of APIs, you
21
should use the doxygen 'group' tag to keep these APIs together. For
22
example, the roscpp documentation has 'libros' group.
23
-->
24

  
25

  
26
*/
scout/cliffsensor/manifest.xml
1
<package>
2
  <description brief="cliffsensor">
3
     cliffsensor
4
     Module to read from the cliffsensor, detect cliffs, and behaviors for cliffsensor.
5
  </description>
6
  <author>Priya</author>
7
  <license>BSD</license>
8
  <review status="unreviewed" notes=""/>
9
  <url>https://www.roboticsclub.org/redmine/projects/colonyscout/wiki</url>
10
  <depend package="roscpp"/>
11
  <depend package="std_msgs"/>
12

  
13
</package>
14

  
15

  
scout/cliffsensor/msg/cliff_status_changed.msg
1
Header header
2
int8 front_raw
3
int8 left_raw
4
int8 right_raw
5
int8 cliff_status
scout/cliffsensor/src/cliffsensor.cpp
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 Sets motor speed
56
 *
57
 * Sets the motor speeds based on subscription to the set_motors topic.
58
 *
59
 * @param msg The message from the set_motors topic, containing speeds and
60
 *  motor configuration settings.
61
 */
62
void motors_set(const motors::set_motors::ConstPtr& msg)
63
{
64
    /** @todo Edit to only set requested motors, not all */
65
    int which = msg->which;
66
    if(which & MOTOR_FL_REV)
67
    {
68
      motor_fl_speed = -1 * motors_rel_to_abs(msg->fl_speed, msg->units);
69
    }
70
    if(which & MOTOR_FR_REV)
71
    {
72
      motor_fr_speed = -1 * motors_rel_to_abs(msg->fr_speed, msg->units);
73
    }
74
    if(which & MOTOR_BL_REV)
75
    {
76
      motor_bl_speed = -1 * motors_rel_to_abs(msg->bl_speed, msg->units);
77
    }
78
    if(which & MOTOR_BR_REV)
79
    {
80
      motor_br_speed = -1 * motors_rel_to_abs(msg->br_speed, msg->units);
81
    }
82
    if(which & MOTOR_FL)
83
    {
84
      motor_fl_speed = motors_rel_to_abs(msg->fl_speed, msg->units);
85
    }
86
    if(which & MOTOR_FR)
87
    {
88
      motor_fr_speed = motors_rel_to_abs(msg->fr_speed, msg->units);
89
    }
90
    if(which & MOTOR_BL)
91
    {
92
      motor_bl_speed = motors_rel_to_abs(msg->bl_speed, msg->units);
93
    }
94
    if(which & MOTOR_BR)
95
    {
96
      motor_br_speed = motors_rel_to_abs(msg->br_speed, msg->units);
97
    }
98

  
99
    /* Write speeds to hardware */
100
    /** @todo Add code to write speeds to hardware */
101
}
102

  
103
/**
104
 * @brief Outputs current motor speeds
105
 *
106
 * Serves the service query_motors by responding to service requests with the
107
 * speeds of the motors.
108
 * @param req The request. The only field is the units requested.
109
 * @param res The response. The fields will be filled with values.
110
 */
111
bool motors_query(motors::query_motors::Request &req,
112
                  motors::query_motors::Response &res)
113
{
114
    int units = req.units;
115
    res.fl_speed = motors_abs_to_rel(motor_fl_speed, units);
116
    res.fr_speed = motors_abs_to_rel(motor_fr_speed, units);
117
    res.bl_speed = motors_abs_to_rel(motor_bl_speed, units);
118
    res.br_speed = motors_abs_to_rel(motor_br_speed, units);
119

  
120
    ROS_DEBUG("Motor speeds queried");
121
    return true;
122
}
123

  
124
/**
125
 * @brief Converts set speeds (of various units) to absolute speeds.
126
 *
127
 * @param speed The speed expressed in the desired units
128
 * @param units The units the desired speed is measured in
129
 * @return The absolute speed of the motor
130
 **/
131
int motors_rel_to_abs(int rel_speed, int units)
132
{
133
    switch(units)
134
    {
135
      case MOTOR_ABSOLUTE:/* Speed given as absolute */
136
        return rel_speed;
137
      case MOTOR_PERCENT:/* Convert from percentage */
138
        return rel_speed * MAXSPEED / 100;
139
      case MOTOR_MMS:/* Convert from mm/s */
140
        /** @todo Make math to do this conversion **/
141
        return rel_speed;
142
      case MOTOR_CMS:/* Convert from cm/s */
143
        /** @todo Make math to do this conversion **/
144
        return rel_speed;
145
      default: /* The units aren't recognized */
146
        /** @todo Decide on default case. Either percent or absolute. **/
147
        return rel_speed;
148
    }
149
}
150

  
151
/**
152
 * @brief Convert absolute speeds to speeds of various units.
153
 *
154
 * @param speed The speed expressed in absolute units.
155
 * @param units The units the desired speed is measured in.
156
 * @return The relative speed of the motor in desired units.
157
 **/
158
int motors_abs_to_rel(int abs_speed, int units)
159
{
160
    switch(units)
161
    {
162
      case MOTOR_ABSOLUTE:/* Speed given as absolute */
163
        return abs_speed;
164
      case MOTOR_PERCENT:/* Convert from percentage */
165
        return abs_speed * 100 / MAXSPEED;
166
      case MOTOR_MMS:/* Convert from mm/s */
167
        /** @todo Make math to do this conversion **/
168
        return abs_speed;
169
      case MOTOR_CMS:/* Convert from cm/s */
170
        /** @todo Make math to do this conversion **/
171
        return abs_speed;
172
      default: /* The units aren't recognized */
173
        /** @todo Decide on default case. Either percent or absolute. **/
174
        return abs_speed;
175
    }
176
}
177

  
178
/**
179
 * @brief Motors driver. This is a ROS node that controls motor speeds.
180
 *
181
 * This is the main function for the motors node. It is run when the node
182
 * starts and initializes the motors. It then subscribes to the
183
 * set_motors, and set_motor_speeds topics, and advertises the
184
 * query_motors service.
185
 * 
186
 * @param argc The number of command line arguments (should be 1)
187
 * @param argv The array of command line arguments
188
 **/
189
int main(int argc, char **argv)
190
{
191
    /* Initialize in ROS the motors driver node */
192
    ros::init(argc, argv, "motors_driver");
193

  
194
    /* Advertise that this serves the query_motors service */
195
    ros::NodeHandle n;
196
    ros::ServiceServer service = n.advertiseService("query_motors",
197
                                                    motors_query);
198

  
199
    /* Subscribe to the set_motors topic */
200
    ros::Subscriber sub0 = n.subscribe("set_motors", 4, motors_set);
201

  
202
    /* Initialize hardware for motors */
203
    // Hardware init functions here
204

  
205
    ROS_INFO("Ready to set motors.");
206
    ros::spin();
207

  
208
    return 0;
209
}
210

  
211
/** @} **/
scout/cliffsensor/src/cliffsensor.h
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.h
28
 * @brief Contains cliffsensor declarations and functions.
29
 * 
30
 * Contains functions and definitions for the use of
31
 * cliffsensors.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Priyanka Deo
35
 **/
36

  
37
#ifndef _CLIFFSENSOR_H_
38
#define _CLIFFSENSOR_H_
39

  
40
#include "cliffsensor/query_cliff.h"
41
#include "cliffsensor/cliff_status_changed.h"
42

  
43
#define CLIFF_DETECTED 0x0
44
#define NO_CLIFF 0x1
45

  
46
/** @brief Initialize the cliffsensor module and driver. **/
47
int main(int argc, char **argv);
48

  
49
/** @brief Responds to topic to change cliff sensor status. **/
50
void changed_cliff_status(const cliffsensor::cliff_status_changed::ConstPtr& msg);
51

  
52
/** @brief Responds to service to query cliffsensor data. **/
53
bool cliff_query(cliffsensor::query_cliff::Request &req,
54
                  cliffsensor::query_cliff::Response &res);
55

  
56
#endif
scout/cliffsensor/srv/query_cliff.srv
1
int8 units
2
---
3
int8 front_raw
4
int8 left_raw
5
int8 right_raw
6
int8 cliff_status

Also available in: Unified diff