近期在重新开展工作,准备把自己的技术栈升级一下,从之前使用的ROS1 melodic转换为ROS2 jazzy,其中涉及到一些数据格式的转换。
因为,我们之前使用的数据都是ROS1录制的,但是在后续使用过程中我们使用ros2 bag play就不能识别.bag后缀格式的数据了。因此通过网上搜索和大模型来回问询,得到方法,使用下述命令进行转换:
bash
# 假设你当前还在 /media/xiaochen/xch_disk2/FAST-LIVO2_datasets 目录下
# 使用新的目标类型重新转换,并指定一个新的输出文件夹,避免和之前的结果混淆
rosbags-convert --src CBD_Building_01.bag --dst CBD_Building_02--dst-typestore ros2_jazzy
在转换结果中,我们查看数据信息可以看到:
bash
ros2 bag info CBD_Building_02
Files: CBD_Building_02.db3
Bag size: 4.9 GiB
Storage id: sqlite3
ROS Distro: rosbags
Duration: 118.610003187s
Start: Aug 25 2022 11:37:11.416023035 (1661398631.416023035)
End: Aug 25 2022 11:39:10.026026222 (1661398750.026026222)
Messages: 26362
Topic information: Topic: /left_camera/image | Type: sensor_msgs/msg/Image | Count: 1187 | Serialization Format: cdr
Topic: /livox/imu | Type: sensor_msgs/msg/Imu | Count: 23988 | Serialization Format: cdr
Topic: /livox/lidar | Type: livox_ros_driver/msg/CustomMsg | Count: 1187 | Serialization Format: cdr
Service: 0
Service information:
数据中存在/left_camera/image,/livox/imu,/livox/lidar三个topic,然后,我们播包
bash
ros2 bag play CBD_Building_02
出现了这个警告Publisher for topic '/livox/lidar' not found
开始大模型提示我没有激活livox_ros_driver2的功能包,所以我激活了一遍:
bash
source /home/xiaochen/Downloads/ws_livox/install/setup.bash
之后,执行
bash
ros2 bag info CBD_Building_02
还是提示同样的警告。
解决方案:
最后,只要通过人工编辑文件的方式把问题解决了:
bash
# 切换到转换到ros2的功能包中
cd /media/xiaochen/xch_disk2/FAST-LIVO2_datasets/CBD_Building_02
# 编辑元数据文件
gedit metadata.yaml
把其中的livox_ros_driver/msg/CustomMsg人工修改为livox_ros_driver2/msg/CustomMsg
随后,再下载一个sqlite3 的命令行工具
bash
sudo apt update
sudo apt install sqlite3
然后用它来修改数据库,执行这条命令:
bash
sqlite3 CBD_Building_01.db3 "UPDATE topics SET type = 'livox_ros_driver2/msg/CustomMsg' WHERE name = '/livox/lidar';"
验证一下,确保修改成功了
bash
sqlite3 CBD_Building_01.db3 "SELECT name, type FROM topics WHERE name = '/livox/lidar';"
现在两个文件都改好了,就可以重新播放了:
bash
# 先回到上级目录,再播放
cd ..
ros2 bag play CBD_Building_01
之后就没有警告Publisher for topic '/livox/lidar' not found提示了,而且代码可以正常运行。