# How to use the subscribed cmd_vel?

Hi, i calculate the geometry_msgs::Twist cmd_vel and can subscribe to this topic /myrobot/cmd_vel successfully. But i don't know how to use it, e.g. send it directly to my robot? I mean I can call back with velCallback, but how to use the velocity, in the main() function or in the velCallback() function if i want to send it to the robot? I hope i express my question clearly. Below is the simple subscriber node.

#include "ros/ros.h"

#include "std_msgs/String.h"

#include "geometry_msgs/Twist.h"

using namespace std;

void velCallback(const geometry_msgs::Twist& vel) {

cout<<"velocity\n"<<vel<<"\n";


}

int main(int argc, char **argv) {

ros::init(argc, argv, "myrobot_cmd_vel");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/myrobot/cmd_vel", 10, velCallback);

ros::spin();
return 0;


}

Originally posted by Qt_Yeung on ROS Answers with karma: 90 on 2014-08-15

Post score: 0

I assume you're writing a driver which receives Twist messages on the cmd_vel topic to control a custom mobile base.

In this case, you have to read the contents of the message and convert it into motor commands.

For a normal diff-drive robot, this means reading the linear.x (forward/backward) and angular.z (angular velocity) members of the Twist message and computing velocities for the left and right wheels.

For more complex robots, the other members of the Twist message represent sidways, up/down, and rotational motion around the other axes of the robot.

Note that, by convention, the units on the Twist message are in meters per second for linear velocities, and radians per second for angular velocities.

Originally posted by ahendrix with karma: 47576 on 2014-08-15

This answer was ACCEPTED on the original site

Post score: 2