ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

geometry_msgs/TwistStamped to geometry_msgs/Twist

asked 2020-04-10 07:59:04 -0600

louis960126 gravatar image

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

Please help me,Thank you!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-04-10 08:32:48 -0600

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 ;
edit flag offensive delete link more

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-10 08:36:46 -0600 )edit

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

louis960126 gravatar image louis960126  ( 2020-04-10 08:42:13 -0600 )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.

Fetullah Atas gravatar image Fetullah Atas  ( 2020-04-10 08:44:39 -0600 )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

Fetullah Atas gravatar image Fetullah Atas  ( 2020-04-10 08:47:02 -0600 )edit

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

gvdhoorn gravatar image gvdhoorn  ( 2020-04-10 08:54:00 -0600 )edit

link text

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

louis960126 gravatar image louis960126  ( 2020-04-10 09:20:37 -0600 )edit

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

louis960126 gravatar image louis960126  ( 2020-04-10 09:31:08 -0600 )edit

link text

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

louis960126 gravatar image louis960126  ( 2020-04-13 01:29:47 -0600 )edit
0

answered 2020-04-13 03:49:25 -0600

gvdhoorn gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-04-10 07:59:04 -0600

Seen: 12,110 times

Last updated: Apr 13 '20