24
24
#include < map>
25
25
#include < string>
26
26
#include < vector>
27
+ #include < std_msgs/Float64.h>
27
28
28
29
// / \brief. Tele-operation node to control a team of robots by joysticks.
29
30
class SubtTeleop
@@ -91,6 +92,33 @@ class SubtTeleop
91
92
// / \brief Index for vertial axis of arrow keys.
92
93
private: int axisArrowVertical;
93
94
95
+ // / \brief Whether flipper controls are expected to be axes or buttons.
96
+ private: bool flippersUseAxes;
97
+
98
+ // / \brief Index for front flippers axis.
99
+ private: int axisFrontFlippers;
100
+
101
+ // / \brief Index for rear flippers axis.
102
+ private: int axisRearFlippers;
103
+
104
+ // / \brief Index of the button that lifts front flippers up.
105
+ private: int frontFlippersUpButton;
106
+
107
+ // / \brief Index of the button that lifts front flippers down.
108
+ private: int frontFlippersDownButton;
109
+
110
+ // / \brief Index of the button that lifts rear flippers up.
111
+ private: int rearFlippersUpButton;
112
+
113
+ // / \brief Index of the button that lifts rear flippers down.
114
+ private: int rearFlippersDownButton;
115
+
116
+ // / \brief Scale value for front flipper velocity.
117
+ private: double scaleFrontFlippers;
118
+
119
+ // / \brief Scale value for rear flipper velocity.
120
+ private: double scaleRearFlippers;
121
+
94
122
// / \brief Index for the left dead man's switch.
95
123
private: int leftDeadMan;
96
124
@@ -126,6 +154,18 @@ class SubtTeleop
126
154
// / \brief Map from a robot name to a ROS publisher to control flashlights.
127
155
private: std::map<std::string, ros::Publisher> lightPubMap;
128
156
157
+ // / \brief Map from a robot name to a ROS publisher to control front left flipper velocity.
158
+ private: std::map<std::string, ros::Publisher> flipperFrontLeftPubMap;
159
+
160
+ // / \brief Map from a robot name to a ROS publisher to control front right flipper velocity.
161
+ private: std::map<std::string, ros::Publisher> flipperFrontRightPubMap;
162
+
163
+ // / \brief Map from a robot name to a ROS publisher to control rear left flipper velocity.
164
+ private: std::map<std::string, ros::Publisher> flipperRearLeftPubMap;
165
+
166
+ // / \brief Map from a robot name to a ROS publisher to control rear right flipper velocity.
167
+ private: std::map<std::string, ros::Publisher> flipperRearRightPubMap;
168
+
129
169
// / \brief the name of the robot currently under control.
130
170
private: std::string currentRobot;
131
171
};
@@ -136,7 +176,10 @@ SubtTeleop::SubtTeleop():
136
176
angularScaleTurbo(0 ), vertical(3 ), horizontal(2 ), verticalScale(0 ),
137
177
verticalScaleTurbo(0 ), horizontalScale(0 ), horizontalScaleTurbo(0 ),
138
178
enableButton(4 ), enableTurboButton(5 ), lightOnTrigger(6 ), lightOffTrigger(7 ),
139
- axisArrowHorizontal(4 ), axisArrowVertical(5 )
179
+ axisArrowHorizontal(4 ), axisArrowVertical(5 ), flippersUseAxes(true ),
180
+ axisFrontFlippers(5 ), axisRearFlippers(4 ), frontFlippersUpButton(6 ),
181
+ frontFlippersDownButton(4 ), rearFlippersUpButton(7 ),
182
+ rearFlippersDownButton(5 ), scaleFrontFlippers(0 ), scaleRearFlippers(0 )
140
183
{
141
184
// Load joy control settings. Setting values must be loaded by rosparam.
142
185
this ->nh .param (" axis_linear" , this ->linear , this ->linear );
@@ -179,6 +222,32 @@ SubtTeleop::SubtTeleop():
179
222
this ->nh .param (
180
223
" axis_arrow_vertical" , this ->axisArrowVertical , this ->axisArrowVertical );
181
224
225
+ this ->nh .param (
226
+ " flippers_use_axes" , this ->flippersUseAxes , this ->flippersUseAxes );
227
+ this ->nh .param (
228
+ " scale_front_flippers" ,
229
+ this ->scaleFrontFlippers , this ->scaleFrontFlippers );
230
+ this ->nh .param (
231
+ " scale_rear_flippers" , this ->scaleRearFlippers , this ->scaleRearFlippers );
232
+
233
+ this ->nh .param (
234
+ " axis_front_flippers" , this ->axisFrontFlippers , this ->axisFrontFlippers );
235
+ this ->nh .param (
236
+ " axis_rear_flippers" , this ->axisRearFlippers , this ->axisRearFlippers );
237
+
238
+ this ->nh .param (
239
+ " front_flippers_up_button" ,
240
+ this ->frontFlippersUpButton , this ->frontFlippersUpButton );
241
+ this ->nh .param (
242
+ " front_flippers_down_button" ,
243
+ this ->frontFlippersDownButton , this ->frontFlippersDownButton );
244
+ this ->nh .param (
245
+ " rear_flippers_up_button" ,
246
+ this ->rearFlippersUpButton , this ->rearFlippersUpButton );
247
+ this ->nh .param (
248
+ " rear_flippers_down_button" ,
249
+ this ->rearFlippersDownButton , this ->rearFlippersDownButton );
250
+
182
251
this ->nh .getParam (" button_map" , this ->joyButtonIndexMap );
183
252
184
253
// Load robot config information. Setting values must be loaded by rosparam.
@@ -211,6 +280,22 @@ SubtTeleop::SubtTeleop():
211
280
this ->lightPubMap [robotName]
212
281
= this ->nh .advertise <std_msgs::Bool>(
213
282
robotName + " /light" , 1 , true );
283
+
284
+ this ->flipperFrontLeftPubMap [robotName]
285
+ = this ->nh .advertise <std_msgs::Float64 >(
286
+ robotName + " /flippers_cmd_vel/front_left" , 1 , true );
287
+
288
+ this ->flipperFrontRightPubMap [robotName]
289
+ = this ->nh .advertise <std_msgs::Float64 >(
290
+ robotName + " /flippers_cmd_vel/front_right" , 1 , true );
291
+
292
+ this ->flipperRearLeftPubMap [robotName]
293
+ = this ->nh .advertise <std_msgs::Float64 >(
294
+ robotName + " /flippers_cmd_vel/rear_left" , 1 , true );
295
+
296
+ this ->flipperRearRightPubMap [robotName]
297
+ = this ->nh .advertise <std_msgs::Float64 >(
298
+ robotName + " /flippers_cmd_vel/rear_right" , 1 , true );
214
299
}
215
300
216
301
// Select the first robot in default
@@ -316,6 +401,30 @@ void SubtTeleop::JoyCallback(const sensor_msgs::Joy::ConstPtr &_joy)
316
401
// Publish the control values.
317
402
this ->velPubMap [this ->currentRobot ].publish (twist);
318
403
}
404
+
405
+ if (_joy->buttons [this ->enableButton ] ||
406
+ _joy->buttons [this ->rightDeadMan ] ||
407
+ _joy->buttons [this ->leftDeadMan ] ||
408
+ _joy->buttons [this ->enableTurboButton ])
409
+ {
410
+ std_msgs::Float64 flipperVel;
411
+ double axisValue;
412
+ const auto & b = _joy->buttons ;
413
+
414
+ axisValue = this ->flippersUseAxes ? _joy->axes [this ->axisFrontFlippers ] :
415
+ (b[this ->frontFlippersUpButton ] - b[this ->frontFlippersDownButton ]);
416
+ flipperVel.data = -axisValue * this ->scaleFrontFlippers ;
417
+ this ->flipperFrontLeftPubMap [this ->currentRobot ].publish (flipperVel);
418
+ this ->flipperFrontRightPubMap [this ->currentRobot ].publish (flipperVel);
419
+
420
+ axisValue = this ->flippersUseAxes ? _joy->axes [this ->axisRearFlippers ] :
421
+ (b[this ->rearFlippersUpButton ] - b[this ->rearFlippersDownButton ]);
422
+ // rear flippers are oriented the other way than front flippers, so their
423
+ // sign has to be opposite to go in the same direction
424
+ flipperVel.data = axisValue * this ->scaleRearFlippers ;
425
+ this ->flipperRearLeftPubMap [this ->currentRobot ].publish (flipperVel);
426
+ this ->flipperRearRightPubMap [this ->currentRobot ].publish (flipperVel);
427
+ }
319
428
}
320
429
321
430
// ///////////////////////////////////////////////
0 commit comments