ros2
recording
ai_generated
true
ROS2 bag recording timestamps don't match message timestamps when using sim_time
ID: ros2/bag-recording-sim-time-clock-skew
82%Fix Rate
85%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
ros2 bag record uses wall clock for recording timestamps by default, even when nodes use sim_time. Messages are recorded with wall-clock receive time, not the sim_time publish time. This causes misalignment on playback.
genericWorkarounds
-
88% success Use --use-sim-time with a reliable clock source (e.g., Gazebo clock)
ros2 bag record --use-sim-time /topic1 /topic2 /clock # always record /clock topic
-
92% success Always record the /clock topic alongside other topics
ros2 bag record -a --include-hidden-topics # or explicitly: ros2 bag record /clock /cmd_vel /scan
-
85% success Use message header timestamps (not bag timestamps) for time-critical analysis
When processing bag data, use msg.header.stamp not the bag receive timestamp for accurate timing
Dead Ends
Common approaches that don't work:
-
Record bag and assume timestamps match simulation time
85% fail
ros2 bag record uses wall clock for the bag metadata timestamps. Sim_time message headers have correct sim_time but the bag index uses wall clock.
-
Use --use-sim-time flag on ros2 bag record
78% fail
This changes the bag recorder's clock to sim_time but can cause recording gaps if clock publishes are delayed or irregular.