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

rosbag topics out of order

asked 2014-11-07 12:44:35 -0500

csherstan gravatar image

updated 2014-11-07 13:51:35 -0500

Indigo, Linux Mint 17

I'm using the commandline rosbag utility to record various topics.

I have two topics /topic1 and /topic2. Topic1 is published before Topic2, like so:

if state==new_state:


So topic1 publishes when we are in the new_state and topic2 just publishes the state, whatever it happens to be. After recording I inspect the bag with rqt_bag. I expect to see topic1 always preceding topic2 switching from another state to "new_state". However, this is not what I see. I often will see topic2 transition to "new_state" before topic1 appears. If I explicitly add a sleep statement after publishing topic1 then they appear in the order I expect.


  • What should I expect for timing topics? Should I expect them to be received and recorded in order? My understanding was that rosbag would handle synchronization of all my data streams.
  • Does adding a Header to each msg type help?
  • Is everything fine and rqt_bag is just broken?

Does it all come to the limitations of record/playback as described here?

If so, does anyone have a solution for ensuring accurate timing in a rosbag? Writing it directly myself rather than publishing and letting rosrecord pick it up?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-11-07 14:10:31 -0500

ahendrix gravatar image

rosbag timestamps and records messages in the order that they're received. If the messages on topic1 are much larger and take longer to serialize and transmit, they may arrive later even if they're queued for transmission first.

Adding a header won't help rosbag order messages properly; it will still use the receive timestamp. That said, having a header with a timestamp is useful for lots of other things. You can also reorder the messages in a bag file based on their header timestamps:

edit flag offensive delete link more


Well I've confirmed what you've said with tests. However, it would be really nice if messages were timestamped according to when they were published rather than received. So the callback for a subscriber would now have an extra parameter:

def callback(msg, timestamp):
csherstan gravatar image csherstan  ( 2014-11-07 14:44:12 -0500 )edit

If you want timestamps, it's much better to include a Header in your messages, and set it appropriately. This also allows nodes that process and reinterpret data to propagate that timestamp from one message to the next.

ahendrix gravatar image ahendrix  ( 2014-11-07 18:21:16 -0500 )edit

Question Tools

1 follower


Asked: 2014-11-07 12:44:35 -0500

Seen: 4,605 times

Last updated: Nov 07 '14