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

Understanding rosbag timestamps

asked 2019-03-14 09:58:40 -0500

Vicente Penades gravatar image

updated 2019-03-14 10:46:38 -0500

Looking at the ROSbag.v2 specification, every message stored in a bag file is comprised of a:

  1. Message Header
  2. Message Content

The header contains a connection ID and a TimeStamp. The content is the message serialized to bytes, which can include a std_msgs/Header.stamp.

So, I would like to understand which is the relationship between the bag header TimeStamp and the message's std_msgs/Header.stamp

I am also concerned about out of order messages, where messages have been acquired at different times, but they reach the bag file writing queue out of order.


  • It is mandatory that both the bag header stamp and std_msgs/Header.stamp to always match?

  • It is mandatory that the bag header TimeStamp to be in order?

  • Can the std_msgs/Header.stamp to be out of order and decoupled from bag header TimeStamp?

In general, who is usually responsible of handling out of order messages? the software writing the bag files, or the clients reading them?

My undestanding is that the bag header TimeStamp is the instanct in which the message is written to the file, so they're guaranteed to be in order. While the message's std_msg/Header.stamp is the acquisition time, which can be a out of order and a bit sooner than the time in the bag header. Is this correct?

so for example, I can have a bag file with two consecutive messages, where

  • The header timestamps are sequential and in order...
  • But the actual message Header.stamps can be sooner and out of order.

Is this right?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-03-14 13:56:57 -0500

ahendrix gravatar image

The bag header timestamp is populated by rosbag and is the time that a message was received by the rosbag recorder. I believe these will always be in order, but I am not certain.

If the serialized message contains a timestamp, it is populated by the publisher of that message. ROS and rosbag make no guarantees about the meaning, offset between these timestamps and rosbag timestamps, or even the timestamp validity. All of those things are the responsibility of the publisher.

Some publishers backdate or future-date timestamps, which can cause them to differ from the actual time by a significant amount. I've seen offsets up to 1/2 a second for properly functioning publishers, and I've seen other publishers that just set all timestamps to 0 because their clients don't need the timestamp at all.

The rosbag writers and readers do not look at the header timestamp within the messages, and does not guarantee that messages are ordered by those timestamps. Generally messages from a single publisher are written in the order that they are received, but if there are multiple publishers on a topic, you can easily get header timestamps slightly out order.

It is the client's responsibility to interpret the message header timestamps, and to handle out-of-order timestamps in a way that makes sense for the client.

edit flag offensive delete link more



The rosbag writers and readers do not look at the header timestamp within the messages, and does not guarantee that messages are ordered by those timestamps.

note that there are options for rosbag play that change this such that rosbagdoes look at message timestamps.

gvdhoorn gravatar image gvdhoorn  ( 2019-03-17 15:24:50 -0500 )edit

Oh wow thats exactly what I was looking for, could you please share what rosbag play argument you are talking about

marctison gravatar image marctison  ( 2021-07-13 16:39:00 -0500 )edit

Question Tools



Asked: 2019-03-14 09:58:40 -0500

Seen: 10,883 times

Last updated: Mar 14 '19