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

Using topic_tools transform to publish more complex types

asked 2017-05-17 04:43:27 -0600

9a3eedi gravatar image

updated 2017-05-17 04:44:25 -0600

I am attempting to use topic_tools/transform to publish messages that are slightly more complex than what the examples show in the wiki, in order to avoid having to write a node.

For example (this might be a bad example), I would like the transform node to subscribe to a TwistStamped message, then create a new TwistStamped message with twist.linear.x equal to the magnitude of the subscribed linear velocity (which only needs a simple math function).

I figured out how to have transform publish the Float on its own, and can also figure out how to publish a Vector, but I couldn't figure out how to get it to publish a Twist or a TwistStamped. I keep getting errors, probably due to my incorrect syntax. But I can't find any examples online. I'm also not sure how to put a header into the published message.

If transform isn't the right tool to use, is there something else I should be using? Or perhaps it's just better to write my own node after all?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-05-17 05:15:37 -0600

rbbg gravatar image

updated 2017-05-17 05:17:48 -0600

I always find topic_tools/transform very useful, but somewhat difficult to use. I always helps me to write the expressions in a text editor, so that you can experiment and jump around a little bit more. I think this is the transform you are after: I am not able to test it right now, but you'll get the idea.

rosrun topic_tools transform /ts /tsnew geometry_msgs/TwistStamped \
  'geometry_msgs.msg.TwistStamped( \
    header=m.header,  \
    twist=geometry_msgs.msg.Twist( \
      linear=geometry_msgs.msg.Vector3( \
        numpy.linalg.norm([m.twist.linear.x, m.twist.linear.y, m.twist.linear.z]),  \
        0.0,  \
        0.0)))'  \
   --import geometry_msgs

I have split it into several lines for clarity. Few notes, the imports can be a bit finicky and it's useful to test with the python interpreter.

edit flag offensive delete link more



I'm impressed that you can do this with topic_tools/transform, but it's probably more readable to write a small ROS node that does it.

ahendrix gravatar image ahendrix  ( 2017-05-17 17:25:57 -0600 )edit

I agree. It's usually not the easiest way, but once you get the hang of it you can jot them down quite quickly and it can be useful as a quick tool.

rbbg gravatar image rbbg  ( 2017-05-18 07:27:49 -0600 )edit

Amazing! Really useful and solved my problem, thanks!

NEET gravatar image NEET  ( 2019-05-28 15:33:49 -0600 )edit

Question Tools



Asked: 2017-05-17 04:43:27 -0600

Seen: 2,157 times

Last updated: May 17 '17