一、ROS2和ROS1录制的文件格式的区别
ros2录制的bag包文件,录制完后会生成一个目录,在目录下会生成多个文件,如下:
编辑
ros1 录制的bag文件,只有一个文件:例如 2021-05-19-19-10-18.bag
二、在ros2的环境中播放ros1录制的bag包
2.1
安装ros2和ros1环境
参考的链接为:
Ubuntu20.04 ROS1和ROS2同时安装及使用 - 古月居
2.1
安装rosbag_v2相关依赖和插件
1)安装ros1转换bridge
sudo apt update
sudo apt install ros-foxy-ros1-bridge
sudo apt install ros-foxy-ros1-rosbag-storage-vendor
2)# 安装catkin_tools(https://catkin-tools.readthedocs.io/en/latest/installing.html)
$ sudo sh \
-c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" \
> /etc/apt/sources.list.d/ros-latest.list'
$ wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install python3-catkin-tools
3)# 安装依赖与插件(https://www.ncnynl.com/archives/202209/5469.html)
$ sudo apt update
$ sudo apt install -y libroscpp-serialization0d \
ros-foxy-nmea-msgs \
ros-noetic-nmea-msgs
$ sudo apt install -y ros-foxy-rosbag2-bag-v2-plugins \
ros-foxy-rosbag2-storage \
ros-foxy-rosbag2-storage-default-plugins \
ros-foxy-ros2bag ros-galactic-rosbag2-transport
4)补全rosbag_v2相关依赖和插件
sudo apt install ros-foxy-rosbag2-bag-v2-plugins ros-foxy-rosbag2*
2.2 验证
安装完后直接到bag目录下去使用是错误的
光导入ROS2的环境执行也是错误的
按照参考博文的方法,先导入ROS1,再导入ROS2的环境,会出现下面的错误:
ImportError: /opt/ros/foxy/lib/librosbag2_storage.so: undefined symbol: _ZNK12class_loader11ClassLoader15isLibraryLoadedEv
正确的方法是打开终端,输入以下的命令
source /opt/ros/foxy/setup.bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/noetic/lib
可以得到该bag包的详细信息
2.3 执行
source /opt/ros/galactic/setup.bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/noetic/lib
# 查看.bag信息,如上图,包含topic等信息
$ ros2 bag info -s rosbag_v2 your_bag_file.bag
# 回放.bag
$ ros2 bag play -s rosbag_v2 your_bag_file.bag
三、ros2环境中将ros1的bag包,转换成ros2的bag包
3.1 要直接把ros1的包转换成ros2的方法
参考链接:
安装:
pip install rosbags
将 rosbag1 转换为 rosbag2:
# Convert "foo.bag", result will be "foo/"
rosbags-convert foo.bag
# Convert "foo.bag", save the result as "bar"
rosbags-convert foo.bag --dst /path/to/bar
将 rosbag2 转换为 rosbag1(仅克隆存储库):
# Convert "foo", save the result as "foo.bag"
rosbags-convert-2to1 /path/to/foo
转换一些连续的 rosbag2 文件(仅克隆存储库):
# Convert "foo0" and "foo1", save the result as "foo0.bag" and "foo1.bag"
# The sequence number in std_msgs/Header is continued from foo0.bag to foo1.bag
rosbags-convert-2to1 /path/to/foo0 /path/to/foo1
3.2 ros包更改话题名字
GitHub - facontidavide/rosbag_editor: Create a rosbag from a given one, using a simple GUI
使用方法,下载源码后,在ROS1中进行编译,然后执行。
rosrun rosbag_editor rosbag_editor
参考博文:
ROS2 回放 ros1.bag 文件?血泪总结_.bag文件_kinderkindme的博客-CSDN博客
ROS1与ROS2的bag包互换(包含自定义消息) - 古月居