0
$\begingroup$

Rosanswers logo

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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Original comments

Comment by Qt_Yeung on 2014-08-15:
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?

Comment by ahendrix on 2014-08-15:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.