ros rosbag命令相关使用

rosbag

rosbag是ros提供的一个ros数据记录工具,用起来十分方便,可以跨越语言作为一种信息传输队列使用.而且其也提供相关的录制和回放功能.

rosbag录制数据

录制的所有数据如果没有使用-o指定文件名,则会自动以录制结束时的ros时间作为文件名记录,无需担心文件覆盖

  • 录制某一个或几个topic的信息
rosbag record /topic_name_1 /topic_name_2
  • 录制所有rostopic信息
rosbag record -a
  • 指定录制后的文件名
rosbag record -a -o filename.bag
  • 文件分割类命令
rosbag record --duration=30 /topic_name #持续30s录制,还可以指定m,h,和--split类似
rosbag record --split --size=1024 /topic_name #空间达到1024M后分文件存储
rosbag record --split --duration=30 /topic_name #持续时间到30s后分文件存储
rosbag record --split --duration=5m /topic_name #持续时间到5m后分文件存储
rosbag record --split --duration=2h /topic_name #持续时间到2h后分文件存储
rosbag record -l 1000 /topic_name # 录制该主题1000个消息限制

查看rosbag文件信息

  • 查看录制的.bag文件中的topic相关信息
rosbag info filename.bag
rosbag info filename.bag --yaml # 以yaml格式输出信息

示例:

path:        filename.bag
version:     2.0
duration:    32:31s (1951s)
start:       Jan 01 1970 09:17:09.10 (4629.10)
end:         Jan 01 1970 09:49:40.82 (6580.82)
size:        7.9 GB
messages:    20536
compression: none [9759/9759 chunks]
types:       sensor_msgs/PointCloud2 [1158d486****************55c3c181]
             std_msgs/String         [992ce8a1****************73ca41d1]
topics:      /livox/lidar    19518 msgs    : sensor_msgs/PointCloud2
             /pub_data    1018 msgs    : std_msgs/String

回放数据

  • 直接回放数据
rosbag play --clock fiename.bag 
# --clock参数为回放的数据添加一个起始时钟,用于给某些功能使用
# 播放过程中可随时在terminal中按空格暂停,再次按空格可继续
  • 回放数据,但是从一开始直接暂停
rosbag play --clock --pause filename.bag
  • 回放数据,但是仅回放其中一部分话题
rosbag play --clock filename.bag --topic /topic_name_1 /topic_name_2
  • 回放数据,改变播放速度
rosbag play --clock filename.bag -r 0.5 # 半倍速播放
rosbag play --clock filename.bag -r 2 # 2倍速播放
# 为避免程序出现冲突,尽量使用2的阶乘数来作为value
  • 指定播放起始位置
rosbag play --clock filename.bag -s 30 # 从30s的地方开始播放
  • 指定播放时长
rosbag play --clock filename.bag -u 250 # 播放300s信息
  • 循环播放
rosbag play --clock filename.bag -l
rosbag play --clock filename1.bag filename2.bag -l
# 注意:如果要使用第二条来循环播放两个文件的话,无法使用--clock参数

压缩与解压缩数据

  • 压缩数据文件
    使用压缩命令,会将原来的bag备份并重命名为.orig.bag。
#默认bz2格式压缩,特点:压缩数据小,但是慢
rosbag compress filename.bag
rosbag compress -j filename.bag

#lz4格式压缩,特点:压缩快,但是被压缩后的文件稍大
rosbag compress --lz4 bag_name.bag
  • 解压缩
rosbag decompress filename.bag

重新录制rosbag文件

  • 录制一份.bag,按照topic数据过滤
rosbag filter originfilename.bag outfilename.bag "topic == '/topic_name_1' or topic == '/topic_name_2'" # 复制一个bag,且仅复制其中两个topic的话题信息
  • 录制一份.bag,按照时间过滤
rosbag filter my.bag out.bag "t.to_sec() >= 123456.77 and t.to_sec() <= 234545.66"

rosbag可视化工具

rqt_bag filename.bag

参考

rosbag数据记录工具命令详解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值