Working with ROS 1/2 Bags
This page serves as a guide to work with ROS Bags on ROS2 Humble.
There are some differences between ROS1 and ROS2 messages:
Understanding Bag Formats
ROS1:
Extension:
.bagStorage: Custom binary format
Tools:
rosbag,rqt_bagCompression: Supported (e.g., BZ2)
Metadata: Topic names, types, timestamps
ROS2:
Extension:
.db3Storage: SQLite3 database
Tools:
ros2 bagCompression: Supported
Metadata: More flexible and complex metadata
MCAP
MCAP (Message Capture)
A proposed standard for a unified file format to store serialized messages for robotic systems.
Designed to be flexible, efficient, and language-agnostic.
Aims to standardize message storage across different middleware systems, improving interoperability and performance.
How to play ROS2 Bags (.db3)?
What should a rosbag file contain?
<bagfolder_name>
|_ metadata.yaml
|_ <bagfolder_name>.db3Playing rosbags that are .db3 files
Install plugins
sudo apt install ros-humble-rqt*
sudo apt install \ ros-humble-image-transport-pluginsPlay Bag using any of the two commands:
ros2 bag play /path/to/bagfolder/bag.db3ros2 bag play /path/to/bagfolderUse rqt to view topics,
rqtHow to use ROS1 Bags in ROS2?
You can use rosbags-convert tool to unpack ROS1 .bag file to .db3 files that can be played using
ros2 bag play </path/to/bag.db3>
If you want to obtain a .mcap file, we can use rosbag2 to convert .db3 to .mcap.
Extracting .db3 and metadata.yaml from .bag files
1.1) Install rosbags library
pip install rosbags1.2) Navigate to directory containing .bag and extract .db3 and metadata
cd /path/to/bags
rosbags-convert --src /path/to/filename.bag --dst /path/to/outputIf your terminal says "rosbags-convert command not found". It could be that your rosbags library is installed in a directory that is not included in PATH variable.
Go to your home directory and add the following line into ~/.bashrc. (Replace {user} with your device username)
export PATH=$PATH:/home/{user}/.local/binConvert .db3 to .mcap
2.1) Ensure that you have rosbag2 installed
sudo apt-get install ros-humble-rosbag22.2) Write config file for conversion (name of file can differ)
vim convert.yamlIf you want your mcap file to contain all topics and services, write convert.yaml as such:
output_bags:
- uri: <NAME_OF_OUTPUT_DIR>
storage_id: mcap
all: true2.3) Run command to convert
ros2 bag convert --input /path/to/bag --output-options /path/to/convert.yamlLast updated