Skip to content

ROS2 and rosbags

Damien LaRocque edited this page Nov 8, 2023 · 6 revisions

Now that we installed ROS 2, it can be complicated to process ROS1 bags

Convert to ROS 2 bags

pip3.10 install rosbags

rosbags-convert foo.bag --dst /path/to/bar

rosbags-convert foo.bag --dst ./imudata-rosbag --include-topic /imu/data --include-topic /imu/data_raw

Use old melodic methods

If you need to use melodic to process old ROS1 data, you can use Docker :

$ docker run -v /path/to/data/directory:/mnt/mydata -it ros:melodic

Your data will be inside /mnt/mydata in the container

Malformed ROS 2 bags database files

You can have the following error message when using common commands with malformed ROS 2 rosbags

Error: database disk image is malformed

Follow these steps to recover them :

sudo apt install sqlite3
# Check for issues
sqlite3 /path/to/bag/bag.db3 "PRAGMA integrity_check;"

# Make a backup and open the database
 cp bag/bag.db3 bag/bag.db.bak
 sqlite3 bag/bag.db3

Commands in SQLITE3 :

.mode insert
.output bag/dump_all.sql
.dump
.exit

Use grep to extract the relevant transactions and load the content back into a new database:

cat bag/dump_all.sql | grep -v TRANSACTION | grep -v ROLLBACK | grep -v COMMIT > bag/dump_all_notrans.sql
sqlite3 bag/bag.db3 ".read bag/dump_all_notrans.sql"
# OR
cat dump_all_notrans.sql | sqlite3 database.db

You should now be able to reindex the bag

ros2 bag reindex bag/
Clone this wiki locally