使用ros_readbagfile脚本提取感兴趣的话题

使用ros_readbagfile脚本轻松地提取感兴趣的话题

来源:这部分教程是根据本文件中首次发表的指引改编的,Python脚本来自:ros_readbag.py

注意:您可以杀死任何正在运行的进程。比如说连roscore都不需要运行。

  1. 下载并安装`ros_readbag.py`

    bash 复制代码
    # Download the file
    wget https://raw.githubusercontent.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/master/useful_scripts/ros_readbagfile.py
    # Make it executable
    chmod +x ros_readbagfile.py
    # Ensure you have the ~/bin directory for personal binaries
    mkdir -p ~/bin
    # Move this executable script into that directory as `ros_readbagfile`, so that it will
    # be available as that command
    mv ros_readbagfile.py ~/bin/ros_readbagfile
    # Re-source your ~/.bashrc file to ensure ~/bin is in your PATH, so you can use this
    # new `ros_readbagfile` command you just installed
    . ~/.bashrc
  2. 通过rosbag info命令确定要从bag文件中读取的准确话题名,如上一篇文章的第一步所示。

  3. 然后使用ros_readbagfile,大体格式如下:

    bash 复制代码
    ros_readbagfile <mybagfile.bag> [topic1] [topic2] [topic3] [...]

    要阅读上一篇文章中显示的相同消息,请使用:

    bash 复制代码
    time ros_readbagfile demo.bag /obs1/gps/fix /diagnostics_agg | tee topics.yaml

    就是这样!你会看到它快速打印出所有70条信息。以下是终端输出的最后部分:

    bash 复制代码
            key: "Early diagnostic update count:"
            value: "0"
          - 
            key: "Zero seen diagnostic update count:"
            value: "0"
    =======================================
    topic:           /obs1/gps/fix
    msg #:           30
    timestamp (sec): 1490150297.770734310
    - - -
    header: 
      seq: 4028
      stamp: 
        secs: 1490150297
        nsecs: 744347249
      frame_id: "gps"
    status: 
      status: 0
      service: 1
    latitude: 37.4007565466
    longitude: -122.108159482
    altitude: -6.35130467023
    position_covariance: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
    position_covariance_type: 0
    =======================================
    Total messages found = 70.
    DONE.
    
    real  0m2.897s
    user  0m2.457s
    sys 0m0.355s

    现在用你喜欢的文本编辑器打开topics.yaml,看看它从bag文件中提取的所有消息。

    请注意,尽管我给了这个文件一个".yaml"扩展名,但并不代表所有部分都是正确的YAML格式。相反,尽管文件中存储的每条消息都是有效的YAML语法,但是消息之间的标题和行分隔符(例如=====)不是有效的。请记住这一点,避免试图将输出解析为YAML。如果你愿意,也可以很容易地修改ros_readbagfile这个Python脚本来删除这些非YAML特性。

为什么用ros_readbagfile而不是rostopic echo -b呢?

  1. 因为rostopic极其地 慢! 举个例子,就算在高配计算机(4核8线程的奔腾i7和m.2固态硬盘)上运行这个命令,也需要11.5分钟才能读取一个18GB的bag文件!

    bash 复制代码
    time rostopic echo -b large_bag_file.bag /topic1

    而用ros_readbagfile脚本,在相同计算机上只要花费1分钟37秒 就能读取同样的话题和18GB的bag文件!因此ros_readbagfile比rostopic快了11.5/(1+37/60) = 大约7倍

    bash 复制代码
    time ros_readbagfile large_bag_file.bag /topic1
  2. 因为rostopic一次只能读取单个话题 ,而ros_readbagfile可以同时读取任意多的话题

    bash 复制代码
    ros_readbagfile <mybagfile.bag> [topic1] [topic2] [topic3] [...] [topic1000]

就酱。

相关推荐
锋行天下4 小时前
公司内网部署大模型的探索之路
前端·人工智能·后端
背心2块钱包邮6 小时前
第7节——积分技巧(Integration Techniques)-代换积分法
人工智能·python·深度学习·matplotlib
无心水6 小时前
【分布式利器:大厂技术】4、字节跳动高性能架构:Kitex+Hertz+BytePS,实时流与AI的极致优化
人工智能·分布式·架构·kitex·分布式利器·字节跳动分布式·byteps
阿正的梦工坊6 小时前
DreamGym:通过经验合成实现代理学习的可扩展化
人工智能·算法·大模型·llm
湘-枫叶情缘6 小时前
人脑生物芯片作为“数字修炼世界”终极载体的技术前景、伦理挑战与实现路径
人工智能
Aaron15886 小时前
侦察、测向、识别、干扰一体化平台系统技术实现
人工智能·fpga开发·硬件架构·边缘计算·信息与通信·射频工程·基带工程
维维180-3121-14557 小时前
作物模型的未来:DSSAT与机器学习、遥感及多尺度模拟的融合
人工智能·生态学·农业遥感·作物模型·地理学·农学
阿杰学AI7 小时前
AI核心知识38——大语言模型之Alignment(简洁且通俗易懂版)
人工智能·安全·ai·语言模型·aigc·ai对齐·alignment
xier_ran7 小时前
关键词解释:对比学习(Contrastive Learning)
人工智能·深度学习·学习·机器学习·对比学习
Jay20021117 小时前
【机器学习】27 异常检测(密度估计)
人工智能·机器学习