このブログは、株式会社フィックスターズのエンジニアが、あらゆるテーマについて自由に書いているブログです。
https://github.com/ros2/rosbag2/pull/1163でrosbag2_storage_mcap
パッケージが追加され、rosbag2のストレージとしてMCAPが選択できるようになりました。この記事ではrosbag2_storage_mcapの使い方を紹介します。
動作確認に用いた環境は以下の通りです。
MCAP(https://mcap.dev/index.html)はタイムスタンプ付きの異なる種類データを記録するためのデータフォーマットで、構造化データ、非構造化データ(ROS2、Protobuf、JSON Schemaなど)の複数ストリームを1つのファイルに記録できます。MCAPのファイルフォーマット詳細はhttps://mcap.dev/specification/index.htmlを参照ください。また、ROS 2 Iron Irwiniからrosbag2のデフォルトストレージがMCAPとなる予定である旨がhttps://foxglove.dev/blog/mcap-as-the-ros2-default-bag-formatでアナウンスされています。
https://mcap.dev/index.htmlの「Benefits」に書かれているものから抜粋したMCAPのメリットを以下に示します。
以下のコマンドを実行してrosbag2_storage_mcap
パッケージをインストールします。
$ sudo apt install ros-humble-rosbag2-storage-mcap
以下のコマンドを実行して全てのトピックをMCAPで保存します。-s
オプションはストレージタイプの指定です。詳細なオプションはros2 bag -h
で確認ください。
$ ros2 bag record -s mcap --all
rosbag2_storage_mcapの場合、https://github.com/ros2/rosbag2/blob/humble/rosbag2_storage_mcap/README.md#writer-configurationにある通り、圧縮に関して以下の指定ができます。
ここでは以下の条件でrosbag2ファイルサイズを確認しました。
各条件で生成されたrosbag2のファイルサイズを下表に示します。ただし、MCAP+Lz4(default)
とMCAP+Lz4(slow)
のケースはrosbag2ファイル保存時にエラーとなったため計測対象から除外しました。
RGB-Dデータ(詳細はAppendix参照)を使った場合の結果を下表に示します。MCAP+Zstd(slow)ではSQLite3+Zstdと同等のファイルサイズになっていることがわかります。
storage type | compression | size(MB) |
---|---|---|
SQLite3 | 無圧縮 | 1359 |
SQLite3 | Zstd | 408 |
MCAP | Zstd(fast) | 500 |
MCAP | Zstd(default) | 472 |
MCAP | Zstd(slow) | 393 |
MCAP | Lz4(fast) | 633 |
Autoware sample rosbag2(詳細はAppendix参照)を使った場合の結果を下表に示します。MCAP+Zstd(slow)ではSQLite3+Zstdと同等のファイルサイズになっていることがわかります。
storage type | compression | size(GB) |
---|---|---|
SQLite3 | 無圧縮 | 7.9 |
SQLite3 | Zstd | 2.8 |
MCAP | Zstd(fast) | 3.1 |
MCAP | Zstd(default) | 2.7 |
MCAP | Zstd(slow) | 2.8 |
MCAP | Lz4(fast) | 3.6 |
MCAPを扱うためのCLIツールを紹介します。https://github.com/foxglove/mcap/blob/releases/cpp/v0.6.0/go/cli/mcap/README.mdからダウンロードします。実行オプションは以下の通りです。
Usage:
mcap [command]
Available Commands:
add Add records to an existing MCAP file
cat Cat the messages in an MCAP file to stdout
completion Generate the autocompletion script for the specified shell
compress Compress data in an MCAP file
convert Convert a bag file to an MCAP file
doctor Check an MCAP file structure
filter Copy some filtered MCAP data to a new file
get Get a record from an MCAP file
help Help about any command
info Report statistics about an MCAP file
list List records of an MCAP file
merge Merge a selection of MCAP files by record timestamp
recover Recover data from a potentially corrupt MCAP file
version Output version information
Flags:
--config string Config file (default is $HOME/.mcap.yaml)
-h, --help help for mcap
Use "mcap [command] --help" for more information about a command.
ここでは以下のコマンドを紹介します。
rosbag2に記録されている情報のサマリーを表示します。実行例は以下の通りです。
$ mcap info zstd_default_0.mcap
library: libmcap 0.7.0
profile: ros2
messages: 5326
duration: 47.452457991s
start: 2023-01-05T16:28:57.516754852+09:00 (1672903737.516754852)
end: 2023-01-05T16:29:44.969212843+09:00 (1672903784.969212843)
compression:
zstd: [1194/1194 chunks] [1356 MB/470 MB (65.29%)] [9.90 MB/sec]
channels:
(1) /rosout 35 msgs (0.74 Hz) : rcl_interfaces/msg/Log [ros2msg]
(2) /events/write_split 0 msgs (0.00 Hz) : rosbag2_interfaces/msg/WriteSplitEvent [ros2msg]
(3) /events/read_split 0 msgs (0.00 Hz) : rosbag2_interfaces/msg/ReadSplitEvent [ros2msg]
(4) /parameter_events 0 msgs (0.00 Hz) : rcl_interfaces/msg/ParameterEvent [ros2msg]
(5) /camera/depth/image_rect_raw 661 msgs (13.93 Hz) : sensor_msgs/msg/Image [ros2msg]
(6) /camera/aligned_depth_to_color/camera_info 661 msgs (13.93 Hz) : sensor_msgs/msg/CameraInfo [ros2msg]
(7) /camera/depth/metadata 661 msgs (13.93 Hz) : realsense2_camera_msgs/msg/Metadata [ros2msg]
(8) /camera/extrinsics/depth_to_depth 1 msgs (0.02 Hz) : realsense2_camera_msgs/msg/Extrinsics [ros2msg]
(9) /camera/aligned_depth_to_color/image_raw 661 msgs (13.93 Hz) : sensor_msgs/msg/Image [ros2msg]
(10) /camera/color/camera_info 661 msgs (13.93 Hz) : sensor_msgs/msg/CameraInfo [ros2msg]
(11) /camera/color/image_raw 661 msgs (13.93 Hz) : sensor_msgs/msg/Image [ros2msg]
(12) /camera/color/metadata 661 msgs (13.93 Hz) : realsense2_camera_msgs/msg/Metadata [ros2msg]
(13) /camera/depth/camera_info 661 msgs (13.93 Hz) : sensor_msgs/msg/CameraInfo [ros2msg]
(14) /tf_static 1 msgs (0.02 Hz) : tf2_msgs/msg/TFMessage [ros2msg]
(15) /camera/extrinsics/depth_to_color 1 msgs (0.02 Hz) : realsense2_camera_msgs/msg/Extrinsics [ros2msg]
(16) /camera/imu 0 msgs (0.00 Hz) : sensor_msgs/msg/Imu [ros2msg]
attachments: 0
metadata: 0
記録されているトピック内容のサマリーを標準出力に表示します。実行例は以下の通りです。
$ mcap cat zstd_default_0.mcap
1672903737516754852 /rosout [rcl_interfaces/msg/Log] [0 1 0 0 57 124 182 99 88 237]...
1672903737516870652 /rosout [rcl_interfaces/msg/Log] [0 1 0 0 57 124 182 99 108 241]...
≪中略≫
1672903741204468335 /camera/aligned_depth_to_color/camera_info [sensor_msgs/msg/CameraInfo] [0 1 0 0 61 109 182 99 0 8]...
1672903741204537835 /camera/depth/metadata [realsense2_camera_msgs/msg/Metadata] [0 1 0 0 61 109 182 99 0 8]...
1672903741204545735 /tf_static [tf2_msgs/msg/TFMessage] [0 1 0 0 4 0 0 0 28 109]...
1672903741204576835 /camera/extrinsics/depth_to_color [realsense2_camera_msgs/msg/Extrinsics] [0 1 0 0 0 0 0 192 247 255]...
≪中略≫
rosbag2ファイルが破損していないかをチェックします。実行例は以下の通りです。今回用いたデータは破損していないためエラーメッセージは出ていません。
$ mcap doctor zstd_default_0.mcap
Examining zstd_default_0.mcap
執筆時点ではrqt_bagがMCAPをサポートしていないようで、rqt_bagでrosbag2(MCAP)を開こうとすると以下のエラーメッセージが出ます。
sqlite3.DatabaseError: file is not a database
Rolling向けの対策は行われているため、今後、Humble向けにバックポートされる可能性があります。
https://github.com/ros2/rosbag2/issues/1195にて報告されています。Rolling向けだとこのメッセージは消されていますが、Humbleでどう対応するか検討中となっているようです。
ファイルサイズ確認に用いた入力のrosbag2ファイル(SQLite3、無圧縮)は以下の通りです。
$ ros2 bag info rosbag2_2023_01_05-15_25_01/
Files: rosbag2_2023_01_05-15_25_01_0.db3
Bag size: 1.3 GiB
Storage id: sqlite3
Duration: 44.66s
Start: Jan 5 2023 15:25:01.719 (1672899901.719)
End: Jan 5 2023 15:25:45.786 (1672899945.786)
Messages: 5301
Topic information: Topic: /events/write_split | Type: rosbag2_interfaces/msg/WriteSplitEvent | Count: 0 | Serialization Format: cdr
Topic: /camera/imu | Type: sensor_msgs/msg/Imu | Count: 0 | Serialization Format: cdr
Topic: /camera/aligned_depth_to_color/camera_info | Type: sensor_msgs/msg/CameraInfo | Count: 661 | Serialization Format: cdr
Topic: /camera/depth/metadata | Type: realsense2_camera_msgs/msg/Metadata | Count: 661 | Serialization Format: cdr
Topic: /camera/extrinsics/depth_to_depth | Type: realsense2_camera_msgs/msg/Extrinsics | Count: 1 | Serialization Format: cdr
Topic: /camera/aligned_depth_to_color/image_raw | Type: sensor_msgs/msg/Image | Count: 661 | Serialization Format: cdr
Topic: /camera/color/camera_info | Type: sensor_msgs/msg/CameraInfo | Count: 661 | Serialization Format: cdr
Topic: /camera/color/image_raw | Type: sensor_msgs/msg/Image | Count: 661 | Serialization Format: cdr
Topic: /rosout | Type: rcl_interfaces/msg/Log | Count: 10 | Serialization Format: cdr
Topic: /camera/color/metadata | Type: realsense2_camera_msgs/msg/Metadata | Count: 661 | Serialization Format: cdr
Topic: /camera/depth/camera_info | Type: sensor_msgs/msg/CameraInfo | Count: 661 | Serialization Format: cdr
Topic: /camera/depth/image_rect_raw | Type: sensor_msgs/msg/Image | Count: 661 | Serialization Format: cdr
Topic: /parameter_events | Type: rcl_interfaces/msg/ParameterEvent | Count: 0 | Serialization Format: cdr
Topic: /tf_static | Type: tf2_msgs/msg/TFMessage | Count: 1 | Serialization Format: cdr
https://gitlab.com/autowarefoundation/autoware.ai/autoware/-/wikis/ROSBAG-Demoにあるsample_moriyama_150324.bag2を使用。
$ ros2 bag info sample_moriyama_150324.bag2/
Files: sample_moriyama_150324.bag2/sample_moriyama_150324.bag2_0.db3
Bag size: 7.9 GiB
Storage id: sqlite3
Duration: 479.172s
Start: Feb 21 2020 02:04:31.772 (1582218271.772)
End: Feb 21 2020 02:12:30.944 (1582218750.944)
Messages: 16768
Topic information: Topic: /clock | Type: rosgraph_msgs/msg/Clock | Count: 0 | Serialization Format: cdr
Topic: /nmea_sentence | Type: nmea_msgs/msg/Sentence | Count: 11980 | Serialization Format: cdr
Topic: /points_raw | Type: sensor_msgs/msg/PointCloud2 | Count: 4788 | Serialization Format: cdr
keisuke.kimura in Livox Mid-360をROS1/ROS2で動かしてみた
Sorry for the delay in replying. I have done SLAM (FAST_LIO) with Livox MID360, but for various reasons I have not be...
Miya in ウエハースケールエンジン向けSimulated Annealingを複数タイルによる並列化で実装しました
作成されたプロファイラがとても良さそうです :) ぜひ詳細を書いていただきたいです!...
Deivaprakash in Livox Mid-360をROS1/ROS2で動かしてみた
Hey guys myself deiva from India currently i am working in this Livox MID360 and eager to knwo whether you have done the...
岩崎システム設計 岩崎 満 in Alveo U50で10G Ethernetを試してみる
仕事の都合で、検索を行い、御社サイトにたどりつきました。 内容は大変参考になりま...
Prabuddhi Wariyapperuma in Livox Mid-360をROS1/ROS2で動かしてみた
This issue was sorted....