Skip to content

Commit 57bab49

Browse files
authored
Added joy teleop support for flipper control (using deadman + D-pad). (#541)
1 parent 9492097 commit 57bab49

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

subt_example/config/logitech_config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ axis_horizontal: 2 # Right thumb stick horizontal
1515
scale_horizontal: 0.7
1616
scale_horizontal_turbo: 1.5
1717

18+
flippers_use_axes: True
19+
axis_front_flippers: 5
20+
scale_front_flippers: 0.5
21+
axis_rear_flippers: 4
22+
scale_rear_flippers: 0.5
23+
1824
enable_button: 4 # Left button (LB)
1925
enable_turbo_button: 5 # Right button (RB)
2026

subt_example/config/ps3_config.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ axis_horizontal: 3 # Right thumb stick horizontal
1515
scale_horizontal: 0.4
1616
scale_horizontal_turbo: 1.5
1717

18+
flippers_use_axes: False
19+
front_flippers_up_button: 6
20+
front_flippers_down_button: 4
21+
scale_front_flippers: 0.5
22+
rear_flippers_up_button: 7
23+
rear_flippers_down_button: 5
24+
scale_rear_flippers: 0.5
25+
1826
enable_button: 4 # Left button (LB)
1927
enable_turbo_button: 5 # Right button (RB)
2028

subt_example/src/teleop_node.cc

+110-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <map>
2525
#include <string>
2626
#include <vector>
27+
#include <std_msgs/Float64.h>
2728

2829
/// \brief. Tele-operation node to control a team of robots by joysticks.
2930
class SubtTeleop
@@ -91,6 +92,33 @@ class SubtTeleop
9192
/// \brief Index for vertial axis of arrow keys.
9293
private: int axisArrowVertical;
9394

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+
94122
/// \brief Index for the left dead man's switch.
95123
private: int leftDeadMan;
96124

@@ -126,6 +154,18 @@ class SubtTeleop
126154
/// \brief Map from a robot name to a ROS publisher to control flashlights.
127155
private: std::map<std::string, ros::Publisher> lightPubMap;
128156

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+
129169
/// \brief the name of the robot currently under control.
130170
private: std::string currentRobot;
131171
};
@@ -136,7 +176,10 @@ SubtTeleop::SubtTeleop():
136176
angularScaleTurbo(0), vertical(3), horizontal(2), verticalScale(0),
137177
verticalScaleTurbo(0), horizontalScale(0), horizontalScaleTurbo(0),
138178
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)
140183
{
141184
// Load joy control settings. Setting values must be loaded by rosparam.
142185
this->nh.param("axis_linear", this->linear, this->linear);
@@ -179,6 +222,32 @@ SubtTeleop::SubtTeleop():
179222
this->nh.param(
180223
"axis_arrow_vertical", this->axisArrowVertical, this->axisArrowVertical);
181224

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+
182251
this->nh.getParam("button_map", this->joyButtonIndexMap);
183252

184253
// Load robot config information. Setting values must be loaded by rosparam.
@@ -211,6 +280,22 @@ SubtTeleop::SubtTeleop():
211280
this->lightPubMap[robotName]
212281
= this->nh.advertise<std_msgs::Bool>(
213282
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);
214299
}
215300

216301
// Select the first robot in default
@@ -316,6 +401,30 @@ void SubtTeleop::JoyCallback(const sensor_msgs::Joy::ConstPtr &_joy)
316401
// Publish the control values.
317402
this->velPubMap[this->currentRobot].publish(twist);
318403
}
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+
}
319428
}
320429

321430
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)