1

Imagine I have a rosbag with some messages recorded on it.

I want to extract some messages, do some operations on it and then record another "results" bag.

Later I want to rosbag play both bag files and I want them to play at the same pace, ergo synchronized.

How can I do this?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150

2 Answers2

2

Rosbag synchronizes multiple bags when they are played back. According to the rosbag documentation:

If two separate bag files are used, they are treated as a single bag with interlaced times according to the timestamps. This means if you record one bag, wait an hour, and record a second bag, when you play them back together you will have an hour-long dead period in the middle of your playback.

If while playing back a rosbag you want to record a 2nd bag with timestamps that line up with 1st bag, make sure to set /use_sim_time to true. Otherwise the messages in the new bag will be stamped with the current system time, which is not what you want.

rosparam set use_sim_time true
supersolver
  • 426
  • 5
  • 14
0

You can use the rosbag api. If you're just editing the data elements all you have to do is make sure the std_msgs/Header fields are copied from the input to the output msg since this is where timestamps are stored. If you want to play two bag files you just pass them as normal args to rosbag play such as rosbag play *.bag to play all bag files in the current directory. You can also check out the rosbag cookbook if you were interested in doing something like combining them into a single bag file.

BTables
  • 4,413
  • 2
  • 11
  • 30
  • I have done all that. The result is that I have two bags, with the same Header fields (copied as you said) . The problem is that they have different lenght and duration since I published the second one at 10 Hz , not at the original frequency. – KansaiRobot Sep 07 '21 at 22:56
  • There’s not much else you can do differently other than record at a different rate. A node running at 10Hz will have more messages than one running at 5Hz – BTables Sep 07 '21 at 23:59