Ask Your Question
0

How to use the subscribed cmd_vel?

asked 2014-08-15 16:32:21 -0500

Qt_Yeung gravatar image

updated 2014-08-15 16:36:31 -0500

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;

}

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-08-15 16:38:41 -0500

ahendrix gravatar image

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.

edit flag offensive delete link more

Comments

Hi, thanks for your response. Actually I am writing a driver for a robot arm, the linear and angular velocities are for the arm's 6 degree of freedom. Can you explain how to read the Twist message to send it directly to the arm?

Qt_Yeung gravatar image Qt_Yeung  ( 2014-08-15 17:07:10 -0500 )edit

Twist messages represent a free motion in space, and don't accurately capture the kinematics of an arm. You should probably look into the JointTrajectoryAction interface instead. Unfortunately, I don't have much experience with arms, so I don't have any good references on the subject.

ahendrix gravatar image ahendrix  ( 2014-08-15 17:18:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-08-15 16:32:21 -0500

Seen: 1,581 times

Last updated: Aug 15 '14