ros1 bag to ros2 bag play

有个问题是,ros1格式的bag需要转到ros2格式的bag,怎么弄?
需要注意的是,这里只能提供标准信息的rosbag转换,如果带有自定义msg的rosbag,应该是不可以的,请注意一下。

解决办法:

  1. 安装依赖
sudo apt install ros-foxy-rosbag2-bag-v2-plugins ros-foxy-ros1-bridge ros-foxy-ros1-rosbag-storage-vendor ros-foxy-rosbag2*
  1. 设置环境变量

这里一定要注意顺序。因为我们原有的rosbag是ros1格式,用的是ros2里面的bag工具,所以要先source ros1,再source ros2,否则可能出现问题。特别提示一下,在安装完依赖之后,请打开一个新的终端窗口进行操作,保证环境变量的干净。

. /opt/ros/noetic/setup.bash && . devel/setup.bash && . /opt/ros/foxy/setup.bash

中途可能会提示:

ROS_DISTRO was set to 'noetic' before. Please make sure that the environment does not mix paths from different distributions.

不用管。

  1. 查看rosbag信息
ros2 bag info -s rosbag_v2 src/localization/localization/bag/data_example.bag

如果带有自定义msg的话,这里就会提示你转换可能有问题:

[INFO] [1621995510.997956249] [rosbag2_bag_v2_plugins]: ROS 1 to ROS 2 type mapping is not available for topic '/vicon_xb/viconPoseTopic' which is of type 'vicon_xb/viconPoseMsg'. Skipping messages of this topic when replaying.
[INFO] [1621995510.997974022] [rosbag2_bag_v2_plugins]: ROS 1 to ROS 2 type mapping is not available for topic '/uwb_endorange_info' which is of type 'uwb_driver/UwbRange'. Skipping messages of this topic when replaying.

ros1 bag to ros2 bag play_第1张图片

  1. play rosbag
ros2 bag play -s rosbag_v2 src/localization/localization/bag/data_example.bag

在这里插入图片描述

因为这里带了自定义msg,所以不成功,不过标准msg的rosbag还是可以使用的。

  1. 搞定

你可能感兴趣的:(ros2,ros2,rosbag)