0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ROS 2のMCAPファイルをCLIとLichtblickで可視化してみた

Posted at

背景・目的

前回、ROS2コマンドとMCAPファイルへ出力しました。今回はMCAPコマンドやツールを使用して確認してみます。

実践

前提

下記でインストールしたとおり、UTMでUbuntu環境を構築しています。

MCAPコマンド

インストール

  1. Python3.11をインストールします

    $ sudo add-apt-repository ppa:deadsnakes/ppa -y
    $ sudo apt update
    $ sudo apt install python3.11 python3.11-venv python3.11-dev -y
    
  2. python3-venvをインストールします

    $ sudo apt install python3-venv -y
    
  3. 仮想環境を作成します

    $ python3.11 -m venv ~/mcap-venv-py311
    
  4. 仮想環境を有効化します

    $ source ~/mcap-venv-py311/bin/activate
    (mcap-venv-py311) $ 
    
  5. pipをインストールします

    (mcap-venv-py311) $ pip install --upgrade pip
    Requirement already satisfied: pip in ./mcap-venv-py311/lib/python3.11/site-packages (24.0)
    Collecting pip
      Using cached pip-25.1.1-py3-none-any.whl.metadata (3.6 kB)
    Using cached pip-25.1.1-py3-none-any.whl (1.8 MB)
    Installing collected packages: pip
      Attempting uninstall: pip
        Found existing installation: pip 24.0
        Uninstalling pip-24.0:
          Successfully uninstalled pip-24.0
    Successfully installed pip-25.1.1
    (mcap-venv-py311) $ 
    
  6. mcapをインストールします

    (mcap-venv-py311) $ pip install mcap
    Collecting mcap
      Using cached mcap-1.2.2-py3-none-any.whl.metadata (381 bytes)
    Collecting lz4 (from mcap)
      Downloading lz4-4.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.8 kB)
    Collecting zstandard (from mcap)
      Downloading zstandard-0.23.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.0 kB)
    Downloading mcap-1.2.2-py3-none-any.whl (20 kB)
    Downloading lz4-4.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 10.0 MB/s eta 0:00:00
    Downloading zstandard-0.23.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.4/5.4 MB 8.7 MB/s eta 0:00:00
    Installing collected packages: zstandard, lz4, mcap
    Successfully installed lz4-4.4.4 mcap-1.2.2 zstandard-0.23.0
    (mcap-venv-py311) $ 
    
  7. バイナリを取得します

    $ wget https://github.com/foxglove/mcap/releases/download/releases%2Fmcap-cli%2Fv0.0.53/mcap-linux-amd64
    
  8. パーミッションを変更します

    chmod +x mcap-linux-amd64
    
  9. 任意のディレクトリに移動します

    sudo mv mcap-linux-amd64 /usr/local/bin/mcap
    
  10. 使えるようになりました

    (mcap-venv-py311) ubuntu@ubuntu:~$ which mcap
    /usr/local/bin/mcap
    (mcap-venv-py311) ubuntu@ubuntu:~$ mcap --help
    🔪 Officially the top-rated CLI tool for slicing and dicing MCAP files.
    
    Usage:
      mcap [command]
    
    Available Commands:
      add         Add records to an existing MCAP file
      cat         Concatenate the messages in one or more MCAP files to stdout
      completion  Generate the autocompletion script for the specified shell
      compress    Create a compressed copy of an MCAP file
      convert     Convert a bag file to an MCAP file
      decompress  Create an uncompressed copy of an MCAP file
      doctor      Check an MCAP file structure
      du          Report space usage within an MCAP file
      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
      sort        Read an MCAP file and write the messages out physically sorted on log time
      version     Output version information
    
    Flags:
          --config string          Config file (default is $HOME/.mcap.yaml)
      -h, --help                   help for mcap
          --pprof-profile          Record pprof profiles of command execution. Profiles will be written to files: mcap-mem.prof, mcap-cpu.prof, and mcap-block.pprof. Defaults to false.
          --strict-message-order   Require that messages have a monotonic log time
      -v, --verbose                Verbose output
    
    Use "mcap [command] --help" for more information about a command.
    (mcap-venv-py311) ubuntu@ubuntu:~$ 
    

ファイル

  1. こちらで、作成済みのmcapファイルを使用します
    $ tree my_bag
    my_bag
    ├── metadata.yaml
    └── my_bag_0.mcap
    
    1 directory, 2 files
    $ 
    

確認

  1. ファイルの基本情報を確認します

    (mcap-venv-py311) :~/ros2_ws/my_bag$ mcap info my_bag_0.mcap 
    library:   libmcap 1.3.0                                          
    profile:   ros2                                                   
    messages:  430                                                    
    duration:  3m34.495901362s                                        
    start:     2025-05-05T14:50:24.818789035Z (1746456624.818789035)  
    end:       2025-05-05T14:53:59.314690397Z (1746456839.314690397)  
    compression:
    	: [1/1 chunks] [25.15 KiB/25.15 KiB (0.00%)] [120.00 B/sec] 
    channels:
    	(1) /hello  430 msgs (2.00 Hz)   : std_msgs/msg/String [ros2msg]  
    channels: 1
    attachments: 0
    metadata: 2
    (mcap-venv-py311) :
    
    
    • libmcap: 1.3.0: MCAPを作成・更新したライブラリのバージョン
    • profile: ros2: MCAPファイルがROS2のメッセージトピック構造に準拠している
    • messeages: 430:ファイルに含まれるメッセージの総数。430個のメッセージが記録されている
    • duration: 3m34.495901362s:記録されたデータの全体の期間。最初のメッセージから最後のメッセージまでの時間を示している
    • startとend:記録の開始〜終了時刻(UTC)、括弧内の数値は、Unixエポックタイム
    • compression:
      • [1/1 chunks] [25.15 KiB/25.15 KiB (0.00%)] [120.00 B/sec]
        • このファイルには1つのチャンクが含まれている
      • [25.15 KiB/25.15 KiB (0.00%)]
        • 圧縮前後のサイズ。圧縮率は0.00%
      • [120.00 B/sec]
        • データの平均記録速度
        • 1秒あたり120バイトのデータが記録されている
    • channels:
      • (1)
        • チャネル番号
      • /hello
        • トピック名
      • 430 msgs (2.00 Hz)
        • 430個のメッセージ
        • 平均 2.00Hz(1秒間に2回)の頻度でメッセージが記録されている
      • : std_msgs/msg/String [ros2msg]
        • ROS2標準メッセージのstd_msgs/msg/Stringを使用して記録されている
    • channels: 1
      • このファイルには、1つのチャネル(トピック)が含まれる
    • attachments: 0
      • 添付ファイルは含まれていない
    • metadata: 2
      • 2つのメタデータエントリが含まれている
  2. 特定のトピックのメッセージを表示します

    (mcap-venv-py311) $ mcap cat my_bag_0.mcap --topics /hello
    1746456624818789035 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456625318991337 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456625817153713 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456626315038953 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456626816190243 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456627316889793 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456627817237061 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456628315399412 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456628813197746 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456629311262029 /hello [std_msgs/msg/String] [0 1 0 0 15 0 0 0 72 101]...
    1746456629810155184 /hello [std_msgs/msg/String] [0 1 0 0 16 0 0 0 72 101]...
    1746456630312970613 /hello [std_msgs/msg/String] [0 1 0 0 16 0 0 0 72 101]...
    1746456630818005871 /hello [std_msgs/msg/String] [0 1 0 0 16 0 0 0 72 101]...
    
    • 1746456624818789035
      • タイムスタンプ
    • /hello
      • トピック名
      • メッセージが送信されたROS2トピック名
    • [std_msgs/msg/String]
      • メッセージの型
    • [0 1 0 0 15 0 0 0 72 101]...
      • ペイロード(バイナリ)
      • メッセージの内容をバイナリ形式で表したもの

Lichtblick

下記を基にインストールします

事前準備

Node.jsとCorepackの確認・有効化

  1. Node.jsとバージョンを確認します
    % node -v                
    v20.19.0
    
  2. corepackを有効化します
    % corepack prepare yarn@stable --activate
    % 
    
  3. yarnのバージョンを確認します
    % yarn --version
    3.6.3
    % 
    

Lichtblickのセットアップ

  1. Lichtblickのリポジトリをダウンロードします

    % git clone https://github.com/lichtblick-suite/lichtblick.git
    
    Cloning into 'lichtblick'...
    remote: Enumerating objects: 80130, done.
    remote: Counting objects: 100% (17089/17089), done.
    remote: Compressing objects: 100% (1888/1888), done.
    remote: Total 80130 (delta 15852), reused 15201 (delta 15201), pack-reused 63041 (from 3)
    Receiving objects: 100% (80130/80130), 47.82 MiB | 9.69 MiB/s, done.
    Resolving deltas: 100% (63903/63903), done.
    
    
  2. パッケージをインストールします

    % cd lichtblick
    % 
    
  3. 起動します

    $ yarn desktop:serve
    
  4. 別ターミナルで起動します

    yarn desktop:start
    
  5. 起動しました
    image.png

mcapの読み込み

  1. 「File」>「Open local File(s)」から、mcapファイルを開きます

  2. 表示されました
    image.png

  3. 画面下の再生ボタンを押します
    image.png

  4. メッセージの内容とタイムスタンプが進んでいることがわかりました
    image.png

考察

今回は、ROS 2で出力したMCAPファイルを mcap CLI と GUIツール「Lichtblick」で確認する手順を試しました。

  • mcap CLI を使い、メッセージ件数や内容、圧縮状況などをテキストベースで柔軟に確認できました
  • GUIツール「Lichtblick」を使えば、タイムラインに沿って直感的に可視化できました

今後は、複数トピックの可視化や画像・点群データを含んだMCAPファイルを読み込んで確認したいと思います。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?