ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The main concern is the button/axis mapping in the subscriber. Each robot interprets joy messages differently. You need to know what fields you have to emulate. For example, the Xbox 360 controller works as such:
#define XBOX_AXIS_LHORZ 0
#define XBOX_AXIS_LVERT 1
#define XBOX_AXIS_LTRIG 2
#define XBOX_AXIS_RHORZ 3
#define XBOX_AXIS_RVERT 4
#define XBOX_AXIS_RTRIG 5
If you wanted to publish to the left stick vertical axis (up/down) to tell the robot to go forward, you could do the following:
sensor_msgs::Joy joy_msg;
joy_msg.axes.push_back(0.0); // Left Horizontal
joy_msg.axes.push_back(1.0); // Left Vertical (-1.0 through 1.0)
joy_msg.axes.push_back(0.0); // Left Trigger
joy_msg.axes.push_back(0.0); // Right Horizontal
joy_msg.axes.push_back(0.0); // Right Vertical
joy_msg.axes.push_back(0.0); // Right Trigger
2 | No.2 Revision |
The main concern is the button/axis mapping in the subscriber. Each robot interprets joy messages differently. You need to know what fields you have to emulate. For example, the Xbox 360 controller works as such:
#define XBOX_AXIS_LHORZ 0
#define XBOX_AXIS_LVERT 1
#define XBOX_AXIS_LTRIG 2
#define XBOX_AXIS_RHORZ 3
#define XBOX_AXIS_RVERT 4
#define XBOX_AXIS_RTRIG 5
If you wanted to publish to the left stick vertical axis (up/down) to tell the robot to go forward, you could do the following:following in the publisher:
sensor_msgs::Joy joy_msg;
joy_msg.axes.push_back(0.0); // Left Horizontal
joy_msg.axes.push_back(1.0); // Left Vertical (-1.0 through 1.0)
joy_msg.axes.push_back(0.0); // Left Trigger
joy_msg.axes.push_back(0.0); // Right Horizontal
joy_msg.axes.push_back(0.0); // Right Vertical
joy_msg.axes.push_back(0.0); // Right Trigger
publisher.publish(joy_msg);
The .push_back()
method appends a new value to the "axes" vector. If you don't add to the vector, it will be empty. If it's empty when you try to access it with axes[i]
, you'll get a segmentation fault. The above code will generate a new message for you to publish to your robot.