|
29 | 29 | #include <sensor_msgs/JoyFeedbackArray.h>
|
30 | 30 | #include <std_msgs/Float64MultiArray.h>
|
31 | 31 | #include <std_msgs/ColorRGBA.h>
|
| 32 | +#include <std_msgs/Bool.h> |
32 | 33 | #include <std_srvs/Trigger.h>
|
33 | 34 | #include <XmlRpcValue.h>
|
34 | 35 |
|
@@ -70,6 +71,12 @@ class CobTeleop
|
70 | 71 | int right_left_button_;
|
71 | 72 | //mode 4: Twist controller
|
72 | 73 |
|
| 74 | + // free drive |
| 75 | + int free_drive_button_; |
| 76 | + ros::Publisher free_drive_publisher_; |
| 77 | + std::string free_drive_topic_name_; |
| 78 | + bool free_drive_active_; |
| 79 | + |
73 | 80 | //common
|
74 | 81 | int deadman_button_;
|
75 | 82 | int safety_button_;
|
@@ -123,6 +130,7 @@ class CobTeleop
|
123 | 130 | void getConfigurationFromParameters();
|
124 | 131 | void init();
|
125 | 132 | void updateBase();
|
| 133 | + void updateArm(); |
126 | 134 | void say(std::string text, bool blocking);
|
127 | 135 | void setLight(int mode);
|
128 | 136 | void joy_cb(const sensor_msgs::Joy::ConstPtr &joy_msg);
|
@@ -262,6 +270,11 @@ void CobTeleop::getConfigurationFromParameters()
|
262 | 270 | vel_old_[i]=0;
|
263 | 271 | vel_req_[i]=0;
|
264 | 272 | }
|
| 273 | + |
| 274 | + n_.param<int>("free_drive_button", free_drive_button_, 2); // x button |
| 275 | + n_.param<std::string>("free_drive_topic_name", free_drive_topic_name_, "/arm/driver/free_drive_mode"); |
| 276 | + free_drive_publisher_ = n_.advertise<std_msgs::Bool>(free_drive_topic_name_, 1); |
| 277 | + free_drive_active_ = false; |
265 | 278 | }
|
266 | 279 |
|
267 | 280 | sensor_msgs::JoyFeedbackArray CobTeleop::switch_mode()
|
@@ -369,6 +382,20 @@ void CobTeleop::updateBase()
|
369 | 382 | }
|
370 | 383 | }
|
371 | 384 |
|
| 385 | +void CobTeleop::updateArm() |
| 386 | +{ |
| 387 | + if (joy_active_) |
| 388 | + { |
| 389 | + if (free_drive_active_) |
| 390 | + { |
| 391 | + std_msgs::Bool free_drive_msg; |
| 392 | + free_drive_msg.data = true; |
| 393 | + free_drive_publisher_.publish(free_drive_msg); |
| 394 | + setLight(1); |
| 395 | + } |
| 396 | + } |
| 397 | +} |
| 398 | + |
372 | 399 | void CobTeleop::say(std::string text, bool blocking)
|
373 | 400 | {
|
374 | 401 | if(enable_sound_)
|
@@ -428,6 +455,20 @@ void CobTeleop::joy_cb(const sensor_msgs::Joy::ConstPtr &joy_msg)
|
428 | 455 | switch_mode();
|
429 | 456 | }
|
430 | 457 |
|
| 458 | + if (free_drive_button_ >= 0 && free_drive_button_ < (int)joy_msg->buttons.size() && joy_msg->buttons[free_drive_button_] == 1) |
| 459 | + { |
| 460 | + if (free_drive_active_ && joy_msg->buttons[free_drive_button_] == 0) |
| 461 | + { |
| 462 | + ROS_INFO("Free drive mode deactivated"); |
| 463 | + free_drive_active_ = false; |
| 464 | + } |
| 465 | + else if (!free_drive_active_ && joy_msg->buttons[free_drive_button_] == 1) |
| 466 | + { |
| 467 | + ROS_INFO("Free drive mode activated"); |
| 468 | + free_drive_active_ = true; |
| 469 | + } |
| 470 | + } |
| 471 | + |
431 | 472 | if(safety_button_>=0 && safety_button_<(int)joy_msg->buttons.size() && joy_msg->buttons[safety_button_]==1)
|
432 | 473 | {
|
433 | 474 | safe_mode_ = false;
|
@@ -826,6 +867,7 @@ int main(int argc, char** argv)
|
826 | 867 | while(cob_teleop.n_.ok())
|
827 | 868 | {
|
828 | 869 | cob_teleop.updateBase();
|
| 870 | + cob_teleop.updateArm(); |
829 | 871 | ros::spinOnce();
|
830 | 872 | loop_rate.sleep();
|
831 | 873 | }
|
|
0 commit comments