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?

rosbag(mcap)に記録された"/diagnostics"の内容を抽出する

Posted at

コード

from mcap.reader import make_reader
from mcap_ros2.decoder import DecoderFactory
from tqdm import tqdm
import pandas as pd

mcap_file = "hoge.mcap"
target_status_name = "hoge_monitor: hoge_monitor"

statuses = []

with open(mcap_file, "rb") as f:
    reader = make_reader(f, decoder_factories=[DecoderFactory()])
    for schema, channel, message, ros_msg in tqdm(reader.iter_decoded_messages(), dynamic_ncols=True):
        if channel.topic != "/diagnostics":
            continue

        for status in ros_msg.status:
            if status.name == target_status_name:
                dic = {
                    "sec": ros_msg.header.stamp.sec,
                    "nanosec": ros_msg.header.stamp.nanosec,
                    "level": status.level,
                    "message": status.message,
                    "hardware_id": status.hardware_id
                }

                for value in status.values:
                    dic[value.key] = value.value
                
                statuses.append(dic)

df = pd.DataFrame(statuses)

実行結果

image.png

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?