ROBOTICS 101Concept explainer

Logging, Bags, and Replay

When a robot misbehaves in the field, you need to see exactly what it saw. A bag file, made with ros2 bag record, saves every message on chosen topics with its timestamp. Replaying the bag later feeds the same data back into your software, so a bug that happened once can be reproduced, studied, and fixed at a desk.

Recording and replay

ros2 bag record /scan /odom /cmd_vel writes each message with its timestamp. ros2 bag play publishes them again at the original timing, or faster or slower with --rate. The bag's size grows with each topic's rate and message size:

$$\text{size} \approx \sum_{\text{topics}} \text{rate} \times \text{message size} \times \text{duration}$$

What to notice

Camera images dominate the size, so many teams record them only around interesting moments, or compress them. Move the playhead to about 41 seconds, where the robot stopped suddenly in this recording: the scan shows an obstacle that appeared briefly, the cause of the stop. Because replay is exact, you can run a fixed version of the planner on the same bag and confirm the bug is gone. Bags are also how many robot learning datasets are first captured.