ROS1录制的bag包转换为ROS2格式

近期在重新开展工作,准备把自己的技术栈升级一下,从之前使用的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提示了,而且代码可以正常运行。

相关推荐
陈随易1 小时前
编程语言级别的Skill市场,AI Agent 的未来形态
前端·后端·程序员
SoaringHeart2 小时前
Flutter进阶:基于 EasyRefresh 的下拉刷新封装 n_easy_refresh_mixin.dart
前端·flutter
IT_陈寒4 小时前
Vite的热更新突然不香了,排查三小时差点砸键盘
前端·人工智能·后端
子兮曰5 小时前
Agency-Agents 深度解析:400+ AI 专家的"梦之队"如何重塑开发工作流
前端·后端·vibecoding
竹林8185 小时前
用 The Graph 查询链上数据实战:从手搓 RPC 到 Subgraph,我的 NFT 项目数据加载快了 10 倍
前端·javascript
妙码生花6 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十九):点选验证码代码逐行目检
前端·后端·go
Awu12276 小时前
⚡从零开发 Agent CLI(五)实现一个可治理、可扩展的工具系统
前端·人工智能·claude
咪库咪库咪7 小时前
Vue3-生命周期
前端
莪_幻尘7 小时前
你的 AI Skill 越多越蠢?Token 上下文爆炸的求生指南
前端·ai编程
lichenyang4538 小时前
从 has.echo 到异步 API 注册表:一次 ASCF API 回调不触发的排查复盘
前端