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

Change message type

asked 2018-09-18 08:56:57 -0500

antoineniotna gravatar image

When i run the following command line: rostopic info /vehicle/odometry I get this response. I would like to change the type of the msg, from motion_common_msg/Odometry to interval_map/odometry, which I know both to be exactly the same.

Type: motion_common_msg/Odometry

Publishers: * /rqt_gui_cpp_node_26530

Subscribers: None

How can I do that ?

edit retag flag offensive close merge delete

Comments

The relevant context is in: #q303668

Next time, please don't post a question twice, and add the important context. Thank you.

mgruhler gravatar image mgruhler  ( 2018-09-18 09:17:02 -0500 )edit

Sorry, I just wanted to make it a bit more clear.

antoineniotna gravatar image antoineniotna  ( 2018-09-18 09:29:59 -0500 )edit
1

no worries, but keep in mind that the context is always relevant, as the answers might be different depending on the context. see also xy-problem

mgruhler gravatar image mgruhler  ( 2018-09-18 10:05:59 -0500 )edit

Indeed my problem was way bigger than the one I explained, I tried to explain the whole thing in my answer and how I solved it.

antoineniotna gravatar image antoineniotna  ( 2018-10-01 08:51:30 -0500 )edit

@antoineiotna happy to hear you solved it. If this is solved, please mark any of the answers as correct (by clicking the check mark next to it), best the one that describes the solution best. This will help future users who are looking for the same thing...

mgruhler gravatar image mgruhler  ( 2018-10-01 09:41:24 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-09-18 10:05:07 -0500

mgruhler gravatar image

The messages are not exactly the same, as they are from different packages. They may contain the same fields, but you cannot simply plug them together. This is not how ROS messages work. Consider you have to messages, containing just one integer, say, one is a temperature, and the other height above ground. Being able to use one as the other is probably not a good idea...

As both messages cannot be found on the ROS wiki, I assume they are custom messages from your project. Thus, you have everything on your control. I'd suggest to resort to only use one single message, if they are actually the same. Maybe consider using nav_msgs/Odometry... This would solve all further problems.

If this is not doable, for whatever reasons, there are several other things you could do:

  1. rewrite the bag file using the rosbag API.
  2. Or use rosbag fix as described in this answer and here, but you need to create conversion rules. Also note, that you don't have the same problem, as this is actually meant to update outdated bag files. But you should be able to work around that.
  3. write a "converter node" that subscribes to one and publishes the other. This introduces some latency, though.
  4. use topic_tools/transform as described here. This is basically 2, but you just have to care about the conversion logic.

But note that all those are not actually "changing the message type", but rather converting it. In 1. and 2. offline by rewriting the bagfile, online in 3. and 4.

So I strongly encourage you to figure out why you have multiple odometry topics that deviate :-)

edit flag offensive delete link more
0

answered 2018-10-01 08:48:36 -0500

antoineniotna gravatar image

Thanks for your help mgruhler! So, I made it work and I am gonna try to explain how I did, as clear as I can.

I my case the odometry data are coming from a rosbag, which I didn't made and I don't have access to the msg. I should have started with this information!

Inside the rosbag I have the odometry but also a lot of other msg types. So first of all, I had to split the rosbag thanks to a small script to have a rosbag with only the topic I wanted : /vehicle/odometry. I was then able print the msg thanks to a script, still.
http://wiki.ros.org/rosbag/Cookbook

I wanted to create my own message type to receive the informations of /vehicle/odometry. And that is when I put my question.

Regarding the solution, in the end the two msg types where not exactly the same in the msg file and I had to create the motion_common_msg/Odometry package instead of interval_map/odometry just to have the same path.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-09-18 08:56:57 -0500

Seen: 3,444 times

Last updated: Oct 01 '18