ROS2 Bags (rosbag2)
287 words · 2 min read · 1 source
rosbag2 records and replays ROS2 topics for offline analysis and regression testing. The black-box recorder of every modern robot.
rosbag2 is the ROS2 tool to record any set of topics into a single time-stamped file (a 'bag') and later replay them as if the live robot were running. It is the standard way to capture data for offline analysis, regression tests, and CI pipelines.
What is ROS2 Bags (rosbag2)?
rosbag2 is the ROS2 tool to record any set of topics into a single time-stamped file (a 'bag') and later replay them as if the live robot were running. It is the standard way to capture data for offline analysis, regression tests, and CI pipelines.
How It Works
From the command line, ros2 bag record /scan /cmd_vel /tf writes all messages on the listed topics into a MCAP or SQLite-backed bag with nanosecond timestamps. ros2 bag play reads the bag and republishes the messages with the original timing — your subscribers cannot tell whether they are reading from a live robot or a replayed bag. Bags can be sliced, filtered, and converted with ros2 bag subcommands.
Real-World Example
Every Nav2 release runs regression tests on stored bag files. Boston Dynamics customers record bag files when robots misbehave and ship them to support. Indian autonomous-vehicle teams (Swaayatt, Flux Auto) record terabytes of bag data daily for training and replay.
Why It Matters for Robotics
Without bag recordings, robotics debugging is nearly impossible. Capturing what the robot saw at the moment of failure — and replaying it offline — is the foundation of modern robotics engineering practice.
Try It Yourself
Record a bag while you drive a TurtleBot3 in Gazebo. Stop the simulator. Run ros2 bag play <bag> while RViz2 is open. The robot appears to move in RViz exactly as it did before — pure replay magic.
Quick Quiz
Quick Quiz
3 questions
1.A rosbag2 file captures:
2.The default modern storage format for rosbag2 is:
3.Bag files are essential for:
Further Reading
Ask R2 About This
Open the R2 Co-pilot (press ⌘K anywhere on R2BOT) and ask: "Explain ROS2 Bags (rosbag2) for a Class 9 student in India, with one real-world Indian example." You'll get a tailored, sourced answer in seconds.
🐍 Python Playground · runs in your browser
Editor · 15 lines
Output
Press ▶ Run to execute. First run downloads Python (~6MB) — only happens once per page.
Powered by Pyodide · Python in WebAssembly · no server required.
Next: the course path
Five free courses, from zero to your own robot design
Short videos with a quiz after each one, a final activity and a certificate per course.
See the course path →Plain English. Free. Unsubscribe in one click.
Keep going
ROS2
Robot Operating System 2 — the DDS-based middleware that runs nearly every modern research and commercial robo…
ConceptROS2 Topics
ROS2 topics are typed, asynchronous message buses that let robot nodes publish and subscribe data — like senso…
ConceptROS2 Nodes
A ROS2 node is a single-process unit of computation that publishes and subscribes to topics, services, and act…
Last updated · 2026-05-21
Spotted something off? Report an error →