Best and Most Common Tools to Process and Query rosbag2 Data
rosbag2 is the standard tool in ROS 2 for recording, playing back, and managing bag files, which are used to store message data from ROS topics. The default storage format for rosbag2 is SQLite3, resulting in .db3 files, though MCAP is also increasingly used[1][4][5][8].
Core Tools
- ros2 bag CLI: The primary command-line interface for recording (
record), playing (play), inspecting (info), converting (convert), and manipulating bag files. It supports splitting, compression, and conversion between storage formats[1][5][8].
- ros2bag_tools: A community extension that adds advanced verbs like
cut, extract, export, plot, sync, and process for more granular manipulation and analysis of bag data. It also supports exporting to other formats and reading topics as pandas DataFrames for data science workflows[2].
- Foxglove: A visualization tool that can load and play back ROS 2 bag files for data inspection and debugging, though it currently has limitations with custom message definitions[6].
- ros2_utils_tool: A GUI/CLI toolkit for editing, cropping, renaming, and extracting data (including video/image sequences) from ROS 2 bags, suitable for users preferring graphical interfaces or batch processing[7].
Use Cases
| Tool/Method | Use Cases |
|---|
| ros2 bag CLI | - Recording and replaying topic data- Quick inspection (info)- Format conversion |
| ros2bag_tools | - Data cleaning (cut, drop, prune)- Topic extraction- Data export (CSV, images)- Synchronization and advanced filtering |
| Foxglove | - Visualization and playback for debugging and analysis |
| ros2_utils_tool | - GUI-based editing, cropping, and extraction- Video/image sequence handling |
When to Use Each Tool
- ros2 bag CLI: Use for standard recording, playback, and format conversion. Ideal for most workflows and scripting[1][5][8].
- ros2bag_tools: Use when you need to filter, synchronize, or export data, or when you want to analyze data in Python or with pandas[2].
- Foxglove: Use for visual inspection, timeline analysis, and debugging, especially when working with standard message types[6].
- ros2_utils_tool: Use for interactive or batch editing, cropping, or extracting media from bags, especially if you prefer a GUI[7].
Limitations
| Tool/Method | Limitations |
|---|
| ros2 bag CLI | - Limited to basic operations- No built-in advanced filtering or data export to CSV/images |
| ros2bag_tools | - Requires Python environment- May not support all custom message types |
| Foxglove | - Cannot load custom message definitions (yet)- No preloading for large datasets |
| ros2_utils_tool | - Still in alpha, may lack stability- Requires additional dependencies (Qt, OpenCV, etc.) |
- General Limitation: ROS 2 bags do not store message definitions, which can hinder interoperability and decoding with third-party tools unless standard message types are used[6].
Querying the .db3 (SQLite3) File
The .db3 file in a ROS 2 bag is a standard SQLite3 database. You can query it using any SQLite client or library. The main tables of interest are:
- messages: Contains the actual serialized message data, timestamps, and topic references.
- topics: Maps topic names to their types and serialization formats.
Basic Query Example:
SELECT t.name, m.timestamp, m.data
FROM messages m
JOIN topics t ON m.topic_id = t.id
WHERE t.name = '/desired_topic'
ORDER BY m.timestamp;
- The
data field contains the serialized message (usually in CDR format), which must be deserialized using the appropriate ROS 2 message definition and serialization tools[1][5][8].
Python Example (using sqlite3):
import sqlite3
conn = sqlite3.connect('your_bag_file.db3')
cursor = conn.cursor()
cursor.execute("""
SELECT t.name, m.timestamp, m.data
FROM messages m
JOIN topics t ON m.topic_id = t.id
WHERE t.name = '/your_topic'
ORDER BY m.timestamp
""")
for row in cursor.fetchall():
print(row)
- For full message decoding, use ROS 2 Python libraries (e.g.,
rosbag2_py) to deserialize the binary data[8].
Summary Table: Tools, Use Cases, and Limitations
| Tool | Use Cases | Limitations |
|---|
| ros2 bag CLI | Record, play, convert, inspect | Basic filtering only, no direct CSV export |
| ros2bag_tools | Filter, extract, export, plot, sync | Python required, custom types may be limited |
| Foxglove | Visualization, playback | No custom msg support, no preloading |
| ros2_utils_tool | GUI/CLI editing, cropping, extraction | Alpha stage, extra dependencies |
| SQLite3 client | Direct database queries, custom analysis | Data is serialized, needs deserialization |
Conclusion
- ros2 bag CLI is best for standard workflows.
- ros2bag_tools and ros2_utils_tool add advanced processing and export capabilities.
- Foxglove is ideal for visualization and debugging.
- The
.db3 file can be queried directly with SQLite tools, but message data must be deserialized for full use[1][2][5][6][7][8].