Home » ROS2入门教程 » ROS2入门教程-rosbag简介

ROS2入门教程-rosbag简介

ROS2入门教程-rosbag简介

说明:

  • 介绍ros2 rosbag工具

概念:

  • ros2 bag是一个命令行工具,用于记录系统中有关主题的发布数据。
  • 它累积在任意数量的话题上传递的数据,并将其保存在数据库中。
  • 然后,您可以重播数据以重现测试和实验的结果。
  • 记录话题也是共享您的作品并允许其他人重新创建作品的一种好方法。

安装:

  • 安装命令:
sudo apt-get install ros-<distro>-ros2bag ros-<distro>-rosbag2*
  • 新开终端,运行turtlesim
ros2 run turtlesim turtlesim_node
  • 新开终端,运行键盘控制
ros2 run turtlesim turtle_teleop_key
  • 新建rosbag目录
mkdir ~/bag_files
cd bag_files
  • 查看话题列表
$ ros2 topic list
/parameter_events
/rosout
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
  • 记录单个话题
$ ros2 bag record /turtle1/cmd_vel

[INFO] [rosbag2_storage]: Opened database 'rosbag2_2019_10_11-05_18_45'.
[INFO] [rosbag2_transport]: Listening for topics...
[INFO] [rosbag2_transport]: Subscribed to topic '/turtle1/cmd_vel'
[INFO] [rosbag2_transport]: All requested topics are subscribed. Stopping discovery...
  • 中止记录,ctrl+c,默认保存格式为rosbag2_year_month_day-hour_minute_second的目录
  • 记录多个话题,并指定保存的目录名,例如:
$ ros2 bag record -o subset /turtle1/cmd_vel /turtle1/pose

[INFO] [rosbag2_storage]: Opened database 'subset'.
[INFO] [rosbag2_transport]: Listening for topics...
[INFO] [rosbag2_transport]: Subscribed to topic '/turtle1/cmd_vel'
[INFO] [rosbag2_transport]: Subscribed to topic '/turtle1/pose'
[INFO] [rosbag2_transport]: All requested topics are subscribed. Stopping discovery...
  • 查看bag信息
$ ros2 bag info subset 

Files:             subset.db3
Bag size:          228.5 KiB
Storage id:        sqlite3
Duration:          48.47s
Start:             Oct 11 2019 06:09:09.12 (1570799349.12)
End                Oct 11 2019 06:09:57.60 (1570799397.60)
Messages:          3013
Topic information: Topic: /turtle1/cmd_vel | Type: geometry_msgs/msg/Twist | Count: 9 | Serialization Format: cdr
                 Topic: /turtle1/pose | Type: turtlesim/msg/Pose | Count: 3004 | Serialization Format: cdr
  • 重发bag信息
$ ros2 bag play subset
[INFO] [1595321648.231311289] [rosbag2_storage]: Opened database 'subset/subset_0.db3' for READ_ONLY.

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros2入门教程