[ROS2] rosbag 和 ros2 bag 转换

1. 需求

前期录制的rosbag用以在office中做各种实验和测试,如ndt, lidar fusion等.现在切换ros2 环境,又不想去重新费时费力去重新录制ros2 bag,那么就引申了转换格式的需求.

2. 方法

I)通过ros1 bridge 转换topic

 

2)现成的模块rosbag2 v2 plugin

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

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

安装rosbag2  rosbag2 plugin

sudo  apt install -y ros-dashing-rosbag2-bag-v2-plugins	ros-dashing-rosbag2-converter-default-plugins ros-dashing-rosbag2-storage ros-dashing-rosbag2-transport ros-dashing-rosbag2-storage-default-plugins ros-dashing-ros2bag

 查看ros2 bag  info

ros2 bag info -s rosbag_v2  2019-12-20-18-00-27.bag
Files:             2019-12-20-18-00-27.bag
Bag size:          792.8 MiB
Storage id:        rosbag_v2
Duration:          6.492s
Start:             Dec 20 2019 10:00:33.878 (1576836033.878)
End                Dec 20 2019 10:00:40.371 (1576836040.371)
Messages:          7513
Topic information: 
                   Topic: /ns2/rslidar2 | Type: sensor_msgs/msg/PointCloud2 | Count: 75 | Serialization Format: rosbag_v2
                   Topic: /ns1/rslidar1 | Type: sensor_msgs/msg/PointCloud2 | Count: 76 | Serialization Format: rosbag_v2
                   Topic: /points_raw | Type: sensor_msgs/msg/PointCloud2 | Count: 65 | Serialization Format: rosbag_v2

播放

ros2 bag play -s rosbag_v2 3lidars.bag

与此同时,可以新开终端录制ros2bag 格式的文件

-XPS-15-9560:~$ ros2 bag record /points_raw /ns1/rslidar1 /ns2/rslidar2  -o 3.bag2
[INFO] [rosbag2_storage]: Opened database '3.bag2'.
[INFO] [rosbag2_transport]: Listening for topics...
[INFO] [rosbag2_transport]: Subscribed to topic '/ns2/rslidar2'
[INFO] [rosbag2_transport]: Subscribed to topic '/points_raw'
[INFO] [rosbag2_transport]: Subscribed to topic '/ns1/rslidar1'
[INFO] [rosbag2_transport]: All requested topics are subscribed. Stopping discovery...
^C[INFO] [rclcpp]: signal_handler(signal_value=2)
-XPS-15-9560:~$ ros2 bag info 3.bag2/

Files:             3.bag2.db3
Bag size:          268.9 MiB
Storage id:        sqlite3
Duration:          6.427s
Start:             Apr 13 2020 08:08:39.422 (1586765319.422)
End                Apr 13 2020 08:08:45.850 (1586765325.850)
Messages:          209
Topic information: Topic: /ns1/rslidar1 | Type: sensor_msgs/msg/PointCloud2 | Count: 73 | Serialization Format: cdr
                   Topic: /ns2/rslidar2 | Type: sensor_msgs/msg/PointCloud2 | Count: 73 | Serialization Format: cdr
                   Topic: /points_raw | Type: sensor_msgs/msg/PointCloud2 | Count: 63 | Serialization Format: cdr

但是录制下来的帧数有所减少,时间也有差异

看看录制下来的帧率

-XPS-15-9560:~$ ros2 topic hz /points_raw

WARNING: topic [/ns2/rslidar2] does not appear to be published yet
average rate: 14.224
	min: 0.006s max: 0.141s std dev: 0.04155s window: 15
average rate: 9.122
	min: 0.006s max: 0.694s std dev: 0.12617s window: 25
average rate: 8.281
	min: 0.006s max: 0.742s std dev: 0.16182s window: 31
average rate: 9.239
	min: 0.006s max: 0.742s std dev: 0.13851s window: 44
average rate: 9.189
	min: 0.006s max: 0.742s std dev: 0.12708s window: 53

帧率也有所降低

而我们用ros1 play和record的结果,是不会有这个现象的

 rosbag record  /points_raw /ns1/rslidar1 /ns2/rslidar2  
[ INFO] [1586768938.763631804]: Subscribing to /ns1/rslidar1
[ INFO] [1586768938.766971727]: Subscribing to /ns2/rslidar2
[ INFO] [1586768938.769629437]: Subscribing to /points_raw
[ INFO] [1586768938.772643391]: Recording to rosbag_2020-04-13-17-08-58.bag.


-XPS-15-9560:/tmp$ rosbag info rosbag_2020-04-13-17-08-58.bag 
path:        rosbag_2020-04-13-17-08-58.bag
version:     2.0
duration:    6.4s
start:       Apr 13 2020 17:09:03.83 (1586768943.83)
end:         Apr 13 2020 17:09:10.27 (1586768950.27)
size:        277.5 MB
messages:    216
compression: none [216/216 chunks]
types:       sensor_msgs/PointCloud2 [1158d486dd51d683ce2f1be655c3c181]
topics:      /ns1/rslidar1   76 msgs    : sensor_msgs/PointCloud2
             /ns2/rslidar2   75 msgs    : sensor_msgs/PointCloud2
             /points_raw     65 msgs    : sensor_msgs/PointCloud2

 对比autoware sample ros2bag 

 wget https://autoware-ai.s3.us-east-2.amazonaws.com/sample_moriyama_150324.bag2.tar.gz

时间,总帧数和ros1 bag完全一致

但是播放的时候,帧率也会下降

-XPS-15-9560:~$ ros2 topic hz /points_raw
average rate: 10.111
	min: 0.088s max: 0.105s std dev: 0.00447s window: 11
average rate: 9.575
	min: 0.088s max: 0.197s std dev: 0.02143s window: 20
average rate: 9.380
	min: 0.088s max: 0.211s std dev: 0.02691s window: 29
average rate: 9.282
	min: 0.088s max: 0.211s std dev: 0.02877s window: 38
average rate: 9.247
	min: 0.088s max: 0.211s std dev: 0.02910s window: 48
average rate: 8.898
	min: 0.088s max: 0.212s std dev: 0.03451s window: 56
average rate: 8.774
	min: 0.088s max: 0.212s std dev: 0.03623s window: 64
average rate: 8.696
	min: 0.088s max: 0.212s std dev: 0.03719s window: 73
average rate: 8.832
	min: 0.088s max: 0.212s std dev: 0.03521s window: 83
average rate: 8.844
	min: 0.088s max: 0.212s std dev: 0.03468s window: 92
average rate: 8.678

播放的时候,也许会出现

-XPS-15-9560:~$ ros2 bag  play sample_moriyama_150324.bag2
[ERROR] [rosbag2_storage]: Could not open 'sample_moriyama_150324.bag2' with 'sqlite3'. Error: Failed to read from bag 'sample_moriyama_150324.bag2': File 'sample_moriyama_150324.bag2/sample_moriyama_150324.bag2_0.db3' does not exist.
[ERROR] [rosbag2_storage]: Could not load/open plugin with storage id 'sqlite3'.
[ERROR] [rosbag2_transport]: Failed to play: No storage could be initialized. Abort
autoware@weilin-XPS-15-9560:~$ vim sample_moriyama_150324.bag2/

原因是对应的path要修改一下,如

vim metadata.yaml
 relative_file_paths:
    - ../sample_moriyama_150324.bag2/sample_moriyama_150324.bag2_0.db3

 

你可能感兴趣的:(ros,自动驾驶)