ROS2 Bag Utility

Record and replay ROS2 topics programmatically using rosbag2 in Python and C++.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/three1324/yeonjinautomotive --skill ros2-bag-utility-three1324
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ROS2 Bag Utility
Source: https://github.com/three1324/yeonjinautomotive/tree/main/.claude/skills/ros2_bag
Command: npx skills add https://github.com/three1324/yeonjinautomotive --skill ros2-bag-utility-three1324

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires rosbag2_py, rosbag2_cpp, rclcpp.

What problem does it solve? Recording and replaying ROS2 topic data for debugging, testing, and analysis requires boilerplate code around rosbag2 APIs, and doing it inside a Clean Architecture codebase adds interface design overhead. This Skill provides ready-made patterns for programmatic bag recording and reading in both Python and C++. ## Core Features & Use Cases - Programmatic Recording: Start and stop rosbag2 recording from code using rosbag2_py or rosbag2_cpp with configurable topic lists and storage options. - Clean Architecture Structure: Defines a domain-layer IDataRecorder interface so recording logic stays decoupled from ROS2 infrastructure. - Bag Reading in C++: A BagReader helper built on rosbag2_cpp::Reader for iterating recorded messages offline. - Use Case: During an autonomous driving test run, record only the camera, lidar, and control topics to a sqlite3 bag, then replay it later to reproduce a perception failure without rerunning the vehicle. ## Quick Start Ask the AI to implement a ROS2 bag recorder node in C++ that records selected topics to a sqlite3 bag following the Clean Architecture interface pattern.

Frequently Asked Questions about ROS2 Bag Utility

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I record a ROS2 bag programmatically in Python?

Use the rosbag2_py library to open a writer with storage options, register topics, and write messages from your node. Wrap it behind a recorder interface with start_recording and stop_recording methods to keep the logic testable.

How to record ROS2 topics in C++ with rosbag2_cpp?

Create a rosbag2_cpp::Writer, configure StorageOptions with the bag URI and storage_id such as sqlite3, set CDR converter options, then call open and write messages with timestamps. Generic subscriptions let you record topics without knowing types at compile time in Humble and later.

Should I use sqlite3 or mcap storage for ROS2 bags?

sqlite3 is the default storage format and works for general use, while mcap is recommended when recording performance matters, such as high-bandwidth sensor topics. Both are configured through the storage_id field in StorageOptions.

How do I read messages from a ROS2 bag file in C++?

Use rosbag2_cpp::Reader, open the bag path, then loop with has_next and read_next to retrieve serialized messages. You must deserialize each message into its concrete type before using the data.

How can I reduce ROS2 bag file size during long recordings?

Record only the topics you actually need instead of all topics, and configure bag splitting so long recordings are divided into manageable chunks. Choosing mcap storage can also improve write efficiency for large data rates.