< >
Home » ROS2入门教程 » ros2入门教程-rosbag和ros2 bag 转换

ros2入门教程-rosbag和ros2 bag 转换

ros2入门教程-rosbag和ros2 bag 转换

说明:

  • 介绍如何实现旧的rosbag包转换位新格式的ros2 bag包
  • 通过ros2 bag的插件机制rosbag2插件来实现转换

步骤:

mkdir ~/dataset
cd ~/dataset
wget http://www.aisl.cs.tut.ac.jp/databases/hdl_graph_slam/hdl_400.bag.tar.gz
tar -zxvf hdl_400.bag.tar.gz
  • 安装依赖
sudo  apt install -y libroscpp-serialization0d ros-galactic-nmea-msgs ros-noetic-nmea-msgs
  • 安装插件
sudo  apt install -y ros-galactic-rosbag2-bag-v2-plugins  ros-galactic-rosbag2-storage ros-galactic-rosbag2-storage-default-plugins ros-galactic-ros2bag ros-galactic-rosbag2-transport 
  • 注意要先加载ros1的环境再加载ros2的环境,要不会提示错误
  • 新开终端,查看包信息
$ source /opt/ros/noetic/setup.bash
$ source /opt/ros/galactic/setup.bash
$ ros2 bag info -s rosbag_v2 dataset/hdl_400.bag
[INFO] [1664424696.629539261] [rosbag2_bag_v2_plugins]: ROS 1 to ROS 2 type mapping is not available for topic '/gpsimu_driver/nmea_sentence' which is of type 'nmea_msgs/Sentence'. Skipping messages of this topic when replaying.

Files:             hdl_400.bag
Bag size:          2.3 GiB
Storage id:        rosbag_v2
Duration:          126.320s
Start:             Oct 30 2017 15:33:17.69 (1509348797.69)
End:               Oct 30 2017 15:35:23.390 (1509348923.390)
Messages:          149206
Topic information: Topic: /gpsimu_driver/imu_data | Type: sensor_msgs/msg/Imu | Count: 24658 | Serialization Format: rosbag_v2
                   Topic: /gpsimu_driver/temperature | Type: sensor_msgs/msg/Temperature | Count: 73971 | Serialization Format: rosbag_v2
                   Topic: /gpsimu_driver/gpstime | Type: sensor_msgs/msg/TimeReference | Count: 24657 | Serialization Format: rosbag_v2
                   Topic: /velodyne_points | Type: sensor_msgs/msg/PointCloud2 | Count: 1263 | Serialization Format: rosbag_v2
  • 新开终端,播放包
~$ source /opt/ros/noetic/setup.bash
~$ source /opt/ros/galactic/setup.bash
~$ ros2 bag play -s rosbag_v2 dataset/hdl_400.bag
[INFO] [1664425395.413896497] [rosbag2_bag_v2_plugins]: ROS 1 to ROS 2 type mapping is not available for topic '/gpsimu_driver/nmea_sentence' which is of type 'nmea_msgs/Sentence'. Skipping messages of this topic when replaying.
[INFO] [1664425395.429094949] [rosbag2_cpp]: No plugin found providing serialization format. Falling back to checking RMW implementations.
[INFO] [1664425395.543486166] [rosbag2_bag_v2_plugins]: ROS 1 to ROS 2 type mapping is not available for topic '/gpsimu_driver/nmea_sentence' which is of type 'nmea_msgs/Sentence'. Skipping messages of this topic when replaying.
[INFO] [1664425395.556567667] [rosbag2_cpp]: No plugin found providing serialization format. Falling back to checking RMW implementations.
  • 新开终端,查看话题列表
~$ source /opt/ros/galactic/setup.bash
~$ ros2 topic list
/gpsimu_driver/gpstime
/gpsimu_driver/imu_data
/gpsimu_driver/temperature
/parameter_events
/rosout
/velodyne_points
  • 新开终端,可以再重新录制
source /opt/ros/galactic/setup.bash
ros2 bag record /velodyne_points  -o dataset/velodyne.bag2

参考:

  • https://github.com/ros2/rosbag2/
  • https://github.com/ros2/rosbag2_bag_v2/

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

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


标签: ros2入门教程