Revision cc558a8d
ID | cc558a8d1299b6a5034be4ea7035b58fe09581b8 |
Modified the Behaviors to take a scoutname.
Scoutname now specifies which scout the behavior will affect. Scoutname must be passed to the constructors of each control module (some of which are now in need of modification), so that they can publish to the correct topic.
I also modified the constants file so that it is no longer exported. We should consider making this a full class with static exported functions (or a namespace).
scout/libscout/include/libscout/constants.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 |
/** |
|
28 |
* @file constants.h |
|
29 |
* @brief Contains top level scout library constants |
|
30 |
* |
|
31 |
* Contains constants for use in libscout |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
* @author Ben Wasserman |
|
35 |
**/ |
|
36 |
|
|
37 |
#ifndef _CONSTANTS_H_ |
|
38 |
#define _CONSTANTS_H_ |
|
39 |
|
|
40 |
#include "ros/ros.h" |
|
41 |
|
|
42 |
/* ROS defines */ |
|
43 |
#define QUEUE_SIZE 10 |
|
44 |
|
|
45 |
/* Libscout Defines */ |
|
46 |
|
|
47 |
/* Init defines */ |
|
48 |
#define LIB_ALL -1 |
|
49 |
#define LIB_MOTORS 0x1 |
|
50 |
#define LIB_SONAR 0x2 |
|
51 |
#define LIB_CLIFFSENSORS 0x4 |
|
52 |
#define LIB_HEADLIGHTS 0x8 |
|
53 |
#define LIB_BUTTONS 0x10 |
|
54 |
|
|
55 |
/* Status defines */ |
|
56 |
//TODO MAKE ENUMS |
|
57 |
#define LIB_ERROR -1 |
|
58 |
#define LIB_OK 0 |
|
59 |
|
|
60 |
|
|
61 |
#endif |
scout/libscout/src/Behavior.h | ||
---|---|---|
38 | 38 |
#define _BEHAVIOR_H_ |
39 | 39 |
|
40 | 40 |
#include <ros/ros.h> |
41 |
#include <libscout/constants.h> |
|
42 | 41 |
|
43 | 42 |
#include "MotorControl.h" |
44 | 43 |
#include "HeadlightControl.h" |
45 | 44 |
#include "SonarControl.h" |
45 |
#include "constants.h" |
|
46 | 46 |
|
47 | 47 |
class Behavior |
48 | 48 |
{ |
scout/libscout/src/ButtonControl.h | ||
---|---|---|
35 | 35 |
* @author Priyanka Deo |
36 | 36 |
* @author Leon Zhang |
37 | 37 |
**/ |
38 |
#include "libscout/constants.h" |
|
39 | 38 |
#include "buttons/button_event.h" |
39 |
#include "constants.h" |
|
40 | 40 |
|
41 | 41 |
#ifndef _LIBBUTTONS_H_ |
42 | 42 |
#define _LIBBUTTONS_H_ |
scout/libscout/src/HeadlightControl.cpp | ||
---|---|---|
37 | 37 |
|
38 | 38 |
#include "HeadlightControl.h" |
39 | 39 |
|
40 |
using namespace std; |
|
41 |
|
|
40 | 42 |
/** ROS publisher and client declaration */ |
41 | 43 |
|
42 | 44 |
/** |
... | ... | |
44 | 46 |
* |
45 | 47 |
* Initialize the libscout node as a publisher of set_headlights. |
46 | 48 |
*/ |
47 |
HeadlightControl::HeadlightControl(const ros::NodeHandle& libscout_node) |
|
49 |
HeadlightControl::HeadlightControl(const ros::NodeHandle& libscout_node, |
|
50 |
string scoutname) |
|
48 | 51 |
: node(libscout_node) |
49 | 52 |
{ |
50 | 53 |
set_headlights_pub = node.advertise<headlights::set_headlights> |
51 |
("set_headlights", QUEUE_SIZE);
|
|
54 |
(scoutname + "/set_headlights", QUEUE_SIZE);
|
|
52 | 55 |
} |
53 | 56 |
|
54 | 57 |
/** |
scout/libscout/src/HeadlightControl.h | ||
---|---|---|
39 | 39 |
#define _HEADLIGHT_CONTROL_H_ |
40 | 40 |
|
41 | 41 |
#include <ros/ros.h> |
42 |
#include <libscout/constants.h> |
|
43 | 42 |
#include <headlights/set_headlights.h> |
44 | 43 |
|
44 |
#include "constants.h" |
|
45 |
|
|
45 | 46 |
/* Defines */ |
46 | 47 |
#define WHITE 0xFFFFFF |
47 | 48 |
#define OFF 0x000000 |
... | ... | |
65 | 66 |
class HeadlightControl |
66 | 67 |
{ |
67 | 68 |
public: |
68 |
HeadlightControl(const ros::NodeHandle& libscout_node); |
|
69 |
HeadlightControl(const ros::NodeHandle& libscout_node, |
|
70 |
std::string scoutname); |
|
69 | 71 |
|
70 | 72 |
void set(int color, int which); |
71 | 73 |
void set_rgb(int red, int green, int blue, int which); |
scout/libscout/src/MotorControl.cpp | ||
---|---|---|
186 | 186 |
* |
187 | 187 |
* @param which A bitmask that will specify which motor speed should be |
188 | 188 |
* returned |
189 |
* @return The speed of the selected motor, or LIB_ERR if no motor selected
|
|
189 |
* @return The speed of the selected motor |
|
190 | 190 |
*/ |
191 | 191 |
float MotorControl::query(int which) |
192 | 192 |
{ |
... | ... | |
204 | 204 |
case MOTOR_BR: |
205 | 205 |
return srv.response.br_speed; |
206 | 206 |
default: |
207 |
ROS_WARN("Bad WHICH in motors_query.");
|
|
208 |
return LIB_ERROR;
|
|
207 |
/// @todo: I hate this. Let's fix it soon.
|
|
208 |
ROS_FATAL("Bad WHICH in motors_query.");
|
|
209 | 209 |
} |
210 | 210 |
} |
211 | 211 |
else |
212 | 212 |
{ |
213 |
ROS_ERROR("Failed to call service query_motors"); |
|
214 |
return LIB_ERROR; |
|
213 |
ROS_FATAL("Failed to call service query_motors"); |
|
215 | 214 |
} |
216 | 215 |
|
217 | 216 |
return 0; |
scout/libscout/src/MotorControl.h | ||
---|---|---|
39 | 39 |
#define _MOTOR_CONTROL_H_ |
40 | 40 |
|
41 | 41 |
#include <ros/ros.h> |
42 |
/// @TODO maybe not so good! Then packages have to depend on libscout. |
|
43 |
#include <libscout/constants.h> |
|
44 | 42 |
#include <motors/query_motors.h> |
45 | 43 |
#include <motors/set_motors.h> |
46 | 44 |
|
45 |
#include "constants.h" |
|
46 |
|
|
47 | 47 |
/* Motor-specific defines */ |
48 | 48 |
#define MOTOR_ALL 0xF |
49 | 49 |
#define MOTOR_ALL_REV 0xF0 |
scout/libscout/src/SonarControl.cpp | ||
---|---|---|
110 | 110 |
* |
111 | 111 |
* @TODO Change so we can get multiple sonar readings with one call |
112 | 112 |
* |
113 |
* @return The reading of the front sonar or LIB_ERR.
|
|
113 |
* @return The reading of the front sonar |
|
114 | 114 |
*/ |
115 | 115 |
float SonarControl::query_front() |
116 | 116 |
{ |
... | ... | |
121 | 121 |
} |
122 | 122 |
else |
123 | 123 |
{ |
124 |
ROS_ERROR("Failed to call service query_motors"); |
|
125 |
return LIB_ERROR; |
|
124 |
ROS_FATAL("Failed to call service query_motors"); |
|
126 | 125 |
} |
127 | 126 |
|
128 | 127 |
return 0; |
... | ... | |
136 | 135 |
* |
137 | 136 |
* @TODO Change so we can get multiple sonar readings with one call |
138 | 137 |
* |
139 |
* @return The reading of the back sonar or LIB_ERR.
|
|
138 |
* @return The reading of the back sonar |
|
140 | 139 |
*/ |
141 | 140 |
float SonarControl::query_back() |
142 | 141 |
{ |
... | ... | |
147 | 146 |
} |
148 | 147 |
else |
149 | 148 |
{ |
150 |
ROS_ERROR("Failed to call service query_motors"); |
|
151 |
return LIB_ERROR; |
|
149 |
ROS_FATAL("Failed to call service query_motors"); |
|
152 | 150 |
} |
153 | 151 |
|
154 | 152 |
return 0; |
scout/libscout/src/constants.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 constants.h |
|
28 |
* @brief A file containing top level scout library constants |
|
29 |
* |
|
30 |
* Contains constants for use in libscout |
|
31 |
* |
|
32 |
* @author Colony Project, CMU Robotics Club |
|
33 |
* @author Ben Wasserman |
|
34 |
* @author Alex Zirbel |
|
35 |
**/ |
|
36 |
|
|
37 |
#ifndef _CONSTANTS_H_ |
|
38 |
#define _CONSTANTS_H_ |
|
39 |
|
|
40 |
#include "ros/ros.h" |
|
41 |
|
|
42 |
/* ROS defines */ |
|
43 |
#define QUEUE_SIZE 10 |
|
44 |
|
|
45 |
#endif |
scout/libscout/src/priya_behavior_process.cpp | ||
---|---|---|
33 | 33 |
* @author Alex Zirbel |
34 | 34 |
**/ |
35 | 35 |
|
36 |
|
|
37 | 36 |
#include <ros/ros.h> |
38 | 37 |
#include "PriyaBehavior.h" |
39 | 38 |
|
... | ... | |
41 | 40 |
|
42 | 41 |
int main (int argc, char **argv) |
43 | 42 |
{ |
43 |
string scoutname = ""; |
|
44 |
|
|
44 | 45 |
if (argc != 2) |
45 | 46 |
{ |
46 |
cout << "Usage: " << argv[0] << " <scoutname>" << endl; |
|
47 |
exit(1); |
|
47 |
cout << "You have started this behavior in hardware mode." << endl |
|
48 |
<< "To start in software mode, use: " << argv[0] |
|
49 |
<< " <scoutname>" << endl; |
|
50 |
} |
|
51 |
else |
|
52 |
{ |
|
53 |
// Use the provided scoutname for simulator messages |
|
54 |
scoutname = argv[1]; |
|
48 | 55 |
} |
49 | 56 |
|
50 | 57 |
ros::init(argc, argv, "libscout"); |
51 | 58 |
|
52 |
PriyaBehavior *behavior = new PriyaBehavior(argv[1]);
|
|
59 |
PriyaBehavior *behavior = new PriyaBehavior(scoutname);
|
|
53 | 60 |
behavior->run(); |
54 | 61 |
} |
Also available in: Unified diff