rosbag
record
- 录制指定的topic:
rosbag record topic1 topic2
- 录制所有的topic:
rosbag record -a
- 录制完保存 bag 包名称为 “session1 + 时间戳.bag” 格式:
rosbag record -o session1 /chatter
- 录制完保存为指定文件名 “session2-090210.bag” 格式:
rosbag record -O session2-090210.bag /chatter
- 录制该主题1000个消息限制:
rosbag record -l 1000 /chatter
- 持续30s录制持续30s录制:
rosbag record --duration=30 /chatter
play
rosbag play 0027.bag --pause -r 0.8 --clock --topic /velodyne_points /imu/data -s 10 -u 5 -l
--pause
: 文件读取完成后不播放,按空格键开始播放-r 0.8
: in specified speed;--clock
: use timestamp in bag file;--topic
: /velodyne_points /imu/data, play these two topics;-s 10
: from the first message that after this time interval from the beginning-u 5
: 表示仅播放包的5秒-l
: 循环播放
把包中的话题original_topic
映射为/points_raw
。
rosbag play bagName.bag /original_topic:=/points_raw
filter
# 截取一段时间
rosbag filter input.bag output.bag "t.to_sec() <= 1284703931 and t.to_sec()>=1284703935"
# or
rosbag filter input.bag output.bag "t.secs <= 1284703931"
# remain specific topic(s)
rosbag filter input.bag output.bag "topic == '/tf'"
# 只保留`/velodyne_point_cloud`和`/visensor/imu`,使用or和==
rosbag filter input.bag output.bag "topic == '/velodyne_point_cloud' or topic =='/visensor/imu'"
# filter out topic(s)`/velodyne_point_cloud`和`/visensor/imu`,使用and和!=
rosbag filter input.bag output.bag "topic != '/velodyne_point_cloud' and topic !='/visensor/imu'"
extract images
将图片从bag文件中提取出来并放在该命令所在目录
rosrun image_view extract_images _sec_per_frame:=0.01 image:=/camera
rosbag play 20250613_084432.bag
extract cloud
解析bag
文件得到带时间戳的pcd
点云数据文件
# rosrun pcl_ros bag_to_pcd <*.bag> <topic> <output_directory>
rosrun pcl_ros bag_to_pcd 20250613_084432.bag /cloud .
bag info
# all info
rosbag info 20250613_084432.bag
# frequency of topic
rosbag info 20250613_084432.bag --freq
# uotput in yaml format
rosbag info 20250613_084432.bag -y
rosbag info 20250613_084432.bag --yaml
compression
Metric | Uncompressed | BZ2 | LZ4 |
---|---|---|---|
File Size | Largest | Smallest (best ratio) | Slightly larger than BZ2 |
Write Time | Fastest | Very slow | Fast |
Read Time | Fastest | Slow | Fast |
Compression Ratio | 1× | ~2.5–4× | ~1.5–2.5× |
Tool Compatibility | Full support | Full support | Limited (Noetic only) |
# default compression mode is bz2
rosbag compress test.bag
rosbag compress --bz2 test.bag
rosbag compress --lz4 test.bag
ros information
query ros topics
topic_name[0]="/image"
topic_name[1]="/lidar"
topic_name[2]="/rtk"
for topic in ${topic_name[@]};
do
echo $topic
timeout 3 rostopic hz $topic
echo "----------------------"
done