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

Is there a way to recompose messages from command line?

asked 2013-03-23 03:05:49 -0600

updated 2013-03-23 04:09:38 -0600

Is there a tool that can take a complex message from one topic, then compose a new message from some of its fields and publish it on another topic?

For instance, JTCartesianController exposes rather complex state, where I need only state/x field of type geometry_msgs::PoseStamped. So such magic tool should do something like:

$ rosmagic /jt_cart_controller/state/x /robot_pose

rostopic is able to echo 'subtopics', but there is no way to republish them.

topic_tools relay does not work with subtopics either.

Any ideas?

Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-03-23 07:35:46 -0600

I found the approach of writing echo "rostopic echo" output to yaml file, optionally changing it and republishing using "rostopic pub" to be fast and work very well. See the "YAML data file" section of the rostopic pub documentation. You can easily change data or also cut/paste submessages out of a composed message and republish them this way.

edit flag offensive delete link more

Comments

Thanks! It also works fine with the pipes, i.e. I can simply do rostopic echo /eef_pose/pose/position | rostopic pub /xyz_position geometry_msgs/Vector3. However I was unable to find any generic command-line tools for parsing YAML, so looks like the scripting is unavoidable...

Boris gravatar image Boris  ( 2013-03-23 19:09:38 -0600 )edit
3

answered 2013-04-04 06:33:23 -0600

updated 2013-04-04 06:38:16 -0600

Here is my first attempt on Python code.

The recompose.py script allows to take a message of any(?) complexity and generate another message based on given format. The format of new message is specified by YAML string, where the values of elements are the paths (delimited by /) to a data in input message.

The most valuable use case for myself is to take a complex message like gazebo_msgs/ContactsState and combine geometry_msgs/WrenchStamped. Main problem here is that we need both std_msgs/Header and geometry_msgs/Wrench to be combined in a new message. However these fields are spread across the ContactsState.

So, this issue can be solve with the provided script as follows:

rostopic echo /gazebo_bumper | recompose.py "{header: header, wrench: 'states[0]/total_wrench'}"

Maybe I'm reinventing the wheel, but I was unable to find a ready to use solution so far.

Hope it can be useful for others.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-23 03:05:49 -0600

Seen: 1,294 times

Last updated: Apr 04 '13