Skip to content

Commit b9aa2c4

Browse files
schmid-jnschmid-jn
authored andcommitted
add free drive mode
1 parent 4196a8d commit b9aa2c4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

cob_teleop/ros/src/cob_teleop.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sensor_msgs/JoyFeedbackArray.h>
3030
#include <std_msgs/Float64MultiArray.h>
3131
#include <std_msgs/ColorRGBA.h>
32+
#include <std_msgs/Bool.h>
3233
#include <std_srvs/Trigger.h>
3334
#include <XmlRpcValue.h>
3435

@@ -70,6 +71,12 @@ class CobTeleop
7071
int right_left_button_;
7172
//mode 4: Twist controller
7273

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+
7380
//common
7481
int deadman_button_;
7582
int safety_button_;
@@ -123,6 +130,7 @@ class CobTeleop
123130
void getConfigurationFromParameters();
124131
void init();
125132
void updateBase();
133+
void updateArm();
126134
void say(std::string text, bool blocking);
127135
void setLight(int mode);
128136
void joy_cb(const sensor_msgs::Joy::ConstPtr &joy_msg);
@@ -262,6 +270,11 @@ void CobTeleop::getConfigurationFromParameters()
262270
vel_old_[i]=0;
263271
vel_req_[i]=0;
264272
}
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;
265278
}
266279

267280
sensor_msgs::JoyFeedbackArray CobTeleop::switch_mode()
@@ -369,6 +382,20 @@ void CobTeleop::updateBase()
369382
}
370383
}
371384

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+
372399
void CobTeleop::say(std::string text, bool blocking)
373400
{
374401
if(enable_sound_)
@@ -428,6 +455,20 @@ void CobTeleop::joy_cb(const sensor_msgs::Joy::ConstPtr &joy_msg)
428455
switch_mode();
429456
}
430457

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+
431472
if(safety_button_>=0 && safety_button_<(int)joy_msg->buttons.size() && joy_msg->buttons[safety_button_]==1)
432473
{
433474
safe_mode_ = false;
@@ -826,6 +867,7 @@ int main(int argc, char** argv)
826867
while(cob_teleop.n_.ok())
827868
{
828869
cob_teleop.updateBase();
870+
cob_teleop.updateArm();
829871
ros::spinOnce();
830872
loop_rate.sleep();
831873
}

0 commit comments

Comments
 (0)