Subscribing to bluetooth_teleop/joy on the Clearpath jackal

asked 2015-07-02 15:49:07 -0500

Adi gravatar image

Hey,

So I am trying to use an arduino to implement a kill switch for the Clearpath jackal robot. The ROS version is indigo, and I chose to use the arduino, since that is how I have been doing my ROS programming so far. So, what I think I need to do is to make subscribe to the bluetooth_teleop/joy topic, and using the documentation here, use the values in the 'buttons' array to determine what has been pressed. Here is my simple code, that publishes a constant velocity to the cmd_vel node and stops doing so (by entering an infinite loop) when the X button on the PS3 joystick (buttons[14]) is pressed. This however, doesn't work. The velocity keeps being published no matter what button I press (except of course the regular velocity controls through the joystick itself). I have tried other buttons, as well as a case in which the simply executing the callback function, regardless of what button is pressed, should disable the velocity publication. No luck. It seems like the callback function is never being called. What am I doing wrong?

#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>
boolean pressed = false;
ros::NodeHandle nh;

void messageCb( const sensor_msgs::Joy& joy_msg){
     if (joy_msg.buttons[14]==1)
       pressed=true;
}

geometry_msgs::Twist msg;

ros::Publisher pub("/cmd_vel", &msg);
ros::Subscriber<sensor_msgs::Joy> sub("/bluetooth_teleop/joy", &messageCb );

void setup() {
  nh.initNode();
  nh.advertise(pub);
  nh.subscribe(sub);
}

void loop(){
  if (pressed)
    while(1){}
  msg.linear.x=0.1;
  pub.publish(&msg);
  nh.spinOnce();
}

Thanks!

edit retag flag offensive close merge delete