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:
- rewrite the bag file using the rosbag API.
- 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. - write a "converter node" that subscribes to one and publishes the other. This introduces some latency, though.
- 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 :-)
The relevant context is in: #q303668
Next time, please don't post a question twice, and add the important context. Thank you.
Sorry, I just wanted to make it a bit more clear.
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
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.
@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...