Ros包修复
.active的ros包修复
录制ros包,不是用ctrl+c关闭终端节点,会导致生成.active结尾的包。
运行下面的命令即可
rosbag reindex xxx.bag.active
rosbag fix xxx.bag.active result.bag
查看数据包信息
rosbag info xx.bag // 查看数据包信息
rosbag play
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 // 同上
录包
// 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个消息
剪切bag
- 根据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)"
参考链接
https://blog.csdn.net/baidu_35692628/article/details/120242574