rosbag使用方法汇总

rosbag的命令

rosbag简介

rosbag 既可以指命令行中数据包相关命令,也可以指 c++/python 的 rosbag 库。这里的 rosbag 是指前者。
rosbag 主要用于记录、回放、分析 rostopic 中的数据。它可以将指定 rostopic 中的数据记录到 .bag 后缀的数据包中,便于对其中的数据进行离线分析和处理。
对于 subscribe 某个 topic 的节点来说,它无法区分这个 topic 中的数据到底是实时获取的数据还是从 rosbag 中回放的数据。这就有助于我们基于离线数据快速重现曾经的实际场景,进行可重复、低成本的分析和调试。
rosbag record

  • 启动与 turtlesim 相关的两个 ros node
roscore
rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key
cd ~/bagfiles
rosbag record -a
  • a 选项表示将当前发布的所有 topic 数据都录制保存到一个 rosbag 文件中,录制的数据包名字为日期加时间。也可以只记录某些感兴趣的 topic
rosbag record /topic_name1 /topic_name2 /topic_name3
  • 如果要指定生成数据包的名字,则用-O /-o 参数,如下:
rosbag record -O filename.bag /topic_name1
  • 如果在 launch 文件中使用 rosbag record 命令,如下:
<node pkg="rosbag" type="record" name="bag_record" args="/topic1 /topic2"/> 

rosbag info

  • rosbag info指令可以显示数据包中的信息:
rosbag info filename.bag

显示类似下边的信息:

xiao@xiao:~/bagfiles$ rosbag info 1.bag 
path:        1.bag
version:     2.0
duration:    3.3s
start:       Aug 24 2019 21:37:53.35 (1566653873.35)
end:         Aug 24 2019 21:37:56.65 (1566653876.65)
size:        7.9 KB
messages:    20
compression: none [1/1 chunks]
types:       geometry_msgs/Twist [9f195f881246fdfa2798d1d3eebca84a]
topics:      /turtle1/cmd_vel   20 msgs    : geometry_msgs/Twist

Print information in YAML format.

rosbag info -y filename.bag

 

xiao@xiao:~/bagfiles$  rosbag info -y 1.bag
path: 1.bag
version: 2.0
duration: 3.295966
start: 1566653873.351150
end: 1566653876.647117
size: 8103
messages: 20
indexed: True
compression: none
types:
    - type: geometry_msgs/Twist
      md5: 9f195f881246fdfa2798d1d3eebca84a
topics:
    - topic: /turtle1/cmd_vel
      type: geometry_msgs/Twist
      messages: 20

rosbag play

接下来回放数据包中的 topic。

保留turtlesim节点继续运行。

rosbag play <bagfile>
  • 如果想改变消息的发布速率,可以用下面的命令,-r 后面的数字对应播放速率。
rosbag play -r 2 <bagfile>
  • 如果希望 rosbag 循环播放,可以用命令
rosbag play -l  <bagfile>  # -l== --loop
  • 如果只播放感兴趣的 topic ,则用命令
rosbag play <bagfile> --topic /topic1

在上述播放命令执行期间,空格键可以暂停播放。
————————————————
转载只为方便查阅,如侵告知立删。
原文链接:https://blog.csdn.net/weixin_43022784/article/details/116782961?spm=1001.2014.3001.5501

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值