walking机器人仿真教程-rosbag录制和播放
walking机器人仿真教程-rosbag录制和回放
说明:
- 介绍rosbag包的录制和回放
- 参考教程: ROS2入门教程-rosbag简介
相关设备:
- walking机器人套件:采购地址
步骤:
- 新建包保存目录
mkdir ~/bag_files
- 新终端, 启动仿真
ros2 launch walking_gazebo world.launch.py
- 新终端, 查看话题
$ ros2 topic list
/active
/clock
/cmd_vel
/cmd_vel_mux/input/default
/cmd_vel_mux/input/joystick
/cmd_vel_mux/input/keyop
/cmd_vel_mux/input/navigation
/cmd_vel_mux/input/remote
/cmd_vel_mux/input/webapp
/depth_camera/camera_info
/depth_camera/depth/camera_info
/depth_camera/depth/image_raw
/depth_camera/depth/image_raw/compressed
/depth_camera/depth/image_raw/compressedDepth
/depth_camera/depth/image_raw/theora
/depth_camera/image_raw
/depth_camera/image_raw/compressed
/depth_camera/image_raw/compressedDepth
/depth_camera/image_raw/theora
/depth_camera/points
/imu
/joint_states
/odom
/parameter_events
/performance_metrics
/rgb_camera/camera_info
/rgb_camera/image_raw
/rgb_camera/image_raw/compressed
/rgb_camera/image_raw/compressedDepth
/rgb_camera/image_raw/theora
/robot_description
/rosout
/scan
/tf
/tf_static
- 录制全部包
cd ~/bag_files
ros2 bag record -a
- 录制指定包
$ cd ~/bag_files
$ ros2 bag record /odom
[INFO] [1649295753.205135530] [rosbag2_storage]: Opened database 'rosbag2_2022_04_07-09_42_33/rosbag2_2022_04_07-09_42_33_0.db3' for READ_WRITE.
[INFO] [1649295753.205372136] [rosbag2_recorder]: Listening for topics...
[INFO] [1649295753.211060000] [rosbag2_recorder]: Subscribed to topic '/odom'
[INFO] [1649295753.211652769] [rosbag2_recorder]: All requested topics are subscribed. Stopping discovery...
- 按ctrl + C 中止
- 会自动建立一个类似rosbag2_2022_04_07-09_42_33目录,并包含metadata.yaml和rosbag2_2022_04_07-09_42_33_0.db3
- 录制指定包,并制定保存目录名
$ cd ~/bag_files
$ ros2 bag record -o subset /odom /imu
[INFO] [1649293844.111371681] [rosbag2_storage]: Opened database 'subset/subset_0.db3' for READ_WRITE.
[INFO] [1649293844.111521646] [rosbag2_recorder]: Listening for topics...
[INFO] [1649293844.117199109] [rosbag2_recorder]: Subscribed to topic '/odom'
[INFO] [1649293844.121867832] [rosbag2_recorder]: Subscribed to topic '/imu'
[INFO] [1649293844.122657320] [rosbag2_recorder]: All requested topics are subscribed. Stopping discovery...
^C[INFO] [1649294458.114834481] [rclcpp]: signal_handler(signal_value=2)
[INFO] [1649294458.118055898] [rosbag2_cpp]: Writing remaining messages from cache to the bag. It may take a while
- 会自动建立一个类似subset目录,并包含metadata.yaml subset_0.db3
- 查看rosbag信息
$ ros2 bag info subset
Files: subset_0.db3
Bag size: 35.1 MiB
Storage id: sqlite3
Duration: 613.990s
Start: Apr 7 2022 09:10:44.122 (1649293844.122)
End: Apr 7 2022 09:20:58.113 (1649294458.113)
Messages: 75864
Topic information: Topic: /imu | Type: sensor_msgs/msg/Imu | Count: 58622 | Serialization Format: cdr
Topic: /odom | Type: nav_msgs/msg/Odometry | Count: 17242 | Serialization Format: cdr
- 回放rosbag包
$ ros2 bag play subset
[INFO] [1649295908.026950105] [rosbag2_storage]: Opened database 'subset/subset_0.db3' for READ_ONLY.
[INFO] [1649295908.036916415] [rosbag2_storage]: Opened database 'subset/subset_0.db3' for READ_ONLY.
- 查看话题
$ ros2 topic list
/imu
/odom
/parameter_events
/rosout
演示视频
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号