# geometry_msgs/TwistStamped to geometry_msgs/Twist

Hi everyone, I have a topic name called /twist_cmd from autoware twist_filter. But the mavros needs the topic /cmd_vel.

/cmd_vel is geometry_msgs/Twist.msg but /twist_cmd is geometry_msgs/TwistStamped.msg

how to change geometry_msgs/TwistStamped.msg to /cmd_vel is geometry_msgs/Twist.msg

edit retag close merge delete

Sort by » oldest newest most voted

If you don't care about transforming the velocities to the correct frame (see my comment under @atas' answer), then the following should do what you want:

rosrun topic_tools transform /twist_cmd /cmd_vel geometry_msgs/Twist 'm.twist'


This takes the twist field from the messages which come in on the input topic, and publishes just that field as a new message on the output topic. Adjust as necessary of course.

No need to write your own node, as I mentioned earlier.

Refer to wiki/topic_tools - transform for more information about transform.

more

Most of the time when you see the ros message types with additional stamped extension , that means in i addition to original message type there is also std_msgs::Header included together as one comapct message. In your case , the geometry_msgs::TwistStaped have original original geometry_msgs::Twist and std_msgs::Header. If you you can extract the only twist with for example something like this ; in your callback ;

 geometry_msgs::Twist your_extarcted_twist = Msg->twist ;

more

While this does get you the data, it's important to recognise the different semantics between Twist and TwistStamped. The former is a bare twist (ie: set of linear and angular velocities), while the latter is a twist, but in a certain coordinate system.

Whether that could cause problems for the OP we can't say, but if mavros assumes Twists to be relative to a certain "default" coordinate system, while the TwistStamped is in another, taking just the Twist and disregarding the frame_id could lead to undesirable (and unexpected) results.

( 2020-04-10 08:36:46 -0500 )edit

Do i need to write another subscriber or publisher ? or just add
;geometry_msgs::Twist your_extarcted_twist = Msg->twist in my node?

( 2020-04-10 08:42:13 -0500 )edit

Thanks for the completion, I think since he just needs bare twist , I would interpret this as the coordinate system that this twist should be at is predetermined. One thing may Be noted further is that , the op should make sure that the source twiststamped message is streamed from this very same coordinate system.

( 2020-04-10 08:44:39 -0500 )edit

@louis960126, depends on what you want to do with this new acquired twist message, probably you will need to write a publisher and publish it with appropriate topic name

( 2020-04-10 08:47:02 -0500 )edit

You don't need to write a node. Look into topic_tools, either transform or relay_field.

( 2020-04-10 08:54:00 -0500 )edit

I found this in topic_tools , I will try it tomorrow. just subscribe and pub right? Thank you sir!

( 2020-04-10 09:20:37 -0500 )edit

rosrun topic_tools transform /twist_cmd /cmd_vel geometry_msgs/Twist something error too few arguments

( 2020-04-10 09:31:08 -0500 )edit

I finished this node, thx for your help. have a nice day!

( 2020-04-13 01:29:47 -0500 )edit