rosbag 的常用命令

1、录制数据包

// cd到目标文件夹下
rosbag record –a					// 录制所有topic的数据包,不光包括正在播的bag里有的
rosbag record /topic_a /topic_2			// 录制topic_1/topic_2的数据包
rosbag record -O bag_name.bag /topic1	// 录制topic_1,指定生成数据包的名字,否则都是 日期.bag
rosbag record -o bag_name.bag /topic1	// 录制topic_1,指定生成数据包的名字,格式会自动变成 bag_name_时间.bag
rosbag record -a -o bag_name.bag		// 录制所有topic

// 录包时间没对齐的话,需要设置rosparam set /use_sim_time true
// 然后播包时加 --clock

rosbag record --duration=30	/topic	// 录制topic,录制时长30s;还可设置为--duration=5m 或 --duration=2h
rosbag record --split --duration=30	/topic_1 /topic_2	// 录制topic_1和2,录制持续30s后分文件存储
rosbag record --split --duration=5m	/topic_1 /topic_2	// 录制topic_1和2,录制持续5m后分文件存储
rosbag record --split --duration=2h	/topic_1 /topic_2	// 录制topic_1和2,录制持续2h后分文件存储
rosbag record --split --size=1024	/topic	// 录制topic,录制大小1024M后分文件存储
rosbag record -l 1000	/topic				// 录制topic满1000个消息

2、查看数据包信息

rosbag info xx.bag 	 // 查看数据包信息

3、数据包播放

rosbag play xx.bag  					// 播放xx数据包
rosbag play *.bag	 					// 播放目录下所有数据包
rosbag play bag1 bag2					// 播放多个bag包
rosbag play --bags=bag1 bag2			// 同上,播放多个bag包

rosbag play –s 10 –r 0.7 –l *.bag		// -s指定从几秒开始,-r指定播放速度,-l循环播放
rosbag play –s 10 –r 0.7 -u 60 *.bag	// 从10s开始0.7倍速播包,持续播60s

rosbag play --pause *.bag				// 以暂停方式启动
// 等播放到topic_1、topic_2相关话题的时候暂停播放,等待命令行输入空格时继续播放
rosbag play xxx.bag --pause-topics /topic_1 /topic_2

rosparam set /use_sim_time time			// 设置使用仿真时间,播包或者录包时间戳对不上时
rosbag play xx.bag --clock				// 系统以msg对应的仿真时间运行,而不是wall clock time(UTC);避免在做msg的tf转换时把更早时间的msg丢掉

rosbag play xxx.bag --topic /topic_name1 /topic_name2	// 只播放特定topic1/2
rosbag play xxx.bag --topics /topic_1 /topic_2			// 同上

4、数据包过滤

  • 根据时间过滤
    rosbag filter命令可以用python指令来过滤包,能够使用的内置变量为topic, m , t.secs和t.nsecs。按时间过滤的时候,需要注意的是应该用UNIX时间,这个时间可以用rosbag info来确定。
rosbag filter input.bag output.bag "t.to_sec() <= 1284703931.86"

rosbag filter input.bag output.bag "t.to_sec() <= 1284703931.86 and t.to_sec()>=1284703935.86"	// 如果需要截取一段时间,可以用and来连接:

  • 按话题过滤
rosbag filter input.bag output.bag "topic == '/tf'"		// 过滤单个topic

// 只保留/velodyne_point_cloud和/visensor/imu,使用or和==:
rosbag filter input.bag output.bag "topic == '/velodyne_point_cloud' or topic =='/visensor/imu' "

// 过滤两个topic:/velodyne_point_cloud和/visensor/imu,使用and和!=:
rosbag filter input.bag output.bag "topic != '/velodyne_point_cloud' and topic !='/visensor/imu' "

5、切割数据包

  • 根据topic进行切割/过滤
// 根据topic过滤/切割
rosbag filter my.bag only-tf.bag "topic == '\tf'"

// 根据多个topics进行过滤/切割
rosbag filter my.bag output.bag "topic == '/velodyne_point_cloud' or topic =='/visensor/imu'"

  • 根据时间段进行切割/过滤
// 根据时间过滤/切割
rosbag filter my.bag output.bag "t.to_sec() <= 1659100376.473893"

// 根据某个时间段过滤/切割
rosbag filter my.bag output.bag "t.to_sec() >= 1659100335.039506 and t.to_sec() <= 1659100376.473893"

  • 切割/过滤某个时间段内的多个topics
// 根据topic和时间过滤/切割
rosbag filter my.bag output.bag "topic == '/odometry/gps' and t.to_sec() <= 1659100376.473893"

// 过滤/切割某个时间段内的多个topics
rosbag filter my.bag output.bag "(topic == '/velodyne_point_cloud' or topic =='/visensor/imu')
		and (t.to_sec() >= 1659100335.039506 and t.to_sec() <= 1659100376.473893)"

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玳宸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值