rosbag
1. 录制包
//录制所有的topic
rosbag record -a
2. 查看包的信息
rosbag info your.bag
会显示如下内容:
path: 2014-12-10-20-08-34.bag
version: 2.0
duration: 1:38s (98s)
start: Dec 10 2014 20:08:35.83 (1418270915.83)
end: Dec 10 2014 20:10:14.38 (1418271014.38)
size: 865.0 KB
messages: 12471
compression: none [1/1 chunks]
types: geometry_msgs/Twist [9f195f881246fdfa2798d1d3eebca84a]
rosgraph_msgs/Log [acffd30cd6b6de30f120938c17c593fb]
turtlesim/Color [353891e354491c51aabe32df673fb446]
turtlesim/Pose [863b248d5016ca62ea2e895ae5265cf9]
topics: /rosout 4 msgs : rosgraph_msgs/Log (2 connections)
/turtle1/cmd_vel 169 msgs : geometry_msgs/Twist
/turtle1/color_sensor 6149 msgs : turtlesim/Color
/turtle1/pose 6149 msgs : turtlesim/Pose
这个命令主要是拿来看一个包里的topic,时长,信息类型等。对于比较小的包,直接rosbag play xx.bag
再rostopic list
即可。但像KITTI转出来的,20多G的,打开实在太慢了,相比起来,info足够。
3. 播放包 rosbag play
rosbag play xx.bag
-d 参数可以用来指定延迟播放的时间(Sec)
-s 参数用于指定从几秒开始:
//从十秒开始播放xx.bag
rosbag play -s 10 xx.bag
-u 参数表示仅播放包的前几秒信息:
//仅播放前十秒
rosbag play -u 10 xx.bag
-r 参数用来指定播放速度:
//2倍速播放
rosbag play -r 2 xx.bag
4. 包过滤 rosbag filter
rosbag filter命令可以用python指令来过滤包,能够使用的内置变量为topic, m , t.secs和t.nsecs。
按时间过滤的时候,需要注意的是应该用UNIX时间,这个时间可以用rosbag info来确定。
rosbag filter input.bag output.bag "t.to_sec() <= 1284703931.86"
而如果需要截取一段时间,可以用and来连接。
rosbag filter input.bag output.bag "t.to_sec() <= 1284703931.86 and t.to_sec()>=1284703935.86"
按话题过滤的话,可以这样写:
//过滤单个topic
rosbag filter my.bag only-tf.bag "topic == '/tf'"
//过滤多个topic
rosbag filter input.bag output.bag "topic == '/velodyne_point_cloud' or topic =='/visensor/imu' or topic == '/visensor/left/image_raw'"
参考链接:
https://blog.csdn.net/a850565178/article/details/105820624