change message content in rosbag in place

asked 2019-09-20 07:36:52 -0600

Christian Rauch gravatar image

I want to directly change the value of messages in a rosbag, without manually extracting the timestamp, message and topic and inserting it again into another bag file.

A motivating example might be that you want to apply some scaling to float values in a message on a specific topic, but want to keep the other parts exactly the same.

The naive solution would be to iterate over the bag via for topic, msg, t in rosbag.Bag(input).read_messages(), change the msg and write it again with output.write(topic, msg, t). However, as far as I know, this will lose the connection information like latching etc.

How can I directly access the msg, without touching any other parts (like the topic,, timestamp, etc.)? In a standard text or binary file, you would simply get a pointer to the value you want to change, and manipulate it directly. How can I achieve this with the rosbag API (python or C++)?

edit retag flag offensive close merge delete