📜 ⬆️ ⬇️

ROS on Raspberry Pi: Using rosbag to save topic data

Good afternoon, dear readers!
This article is an extraordinary in the series . It can be considered as a useful addition to the article . Here I will talk about such a useful tool in ROS as rosbag. Anyone interested, please under the cat.

What is rosbag?


rosbag allows you to save data published in ROS topics to special files with the bag extension. These files can then be played through the same rosbag; the data will be published in the same topics in which they were originally published. This allows, for example, to simulate the acquisition of data from sensors in the absence of such.

Writing data from the topic to the bag file


For example, we will record data from the Raspberry Pi camera. If you recall the article where we received a video stream from the camera and published it in the topic image_raw. Now we just use the same ROS node to get data for recording. We will record the video stream from the image_raw top in the rosbag raspicam_image_raw.bag file, and then play it back, getting the original stream without using the camera.
')
So, run the raspi_cam_ros node:

rosrun raspi_can_ros capture 

Show the list of active topics:

 rostopic list 

Among the topics will be our topic image_raw. Now use rosbag to write the topic:

 rosbag record /image_raw -o raspicam_image_raw 

Let's record a few minutes of video stream. It is better not to record very long streams, because bag files occupy a decent place in memory. For example, I have a record in the length of a minute and a half took 90 MB.
First, let's see what our bag file contains:

 rosbag info < > 

 path: 2016-05-07-13-00-23.bag version: 2.0 duration: 55.1s start: May 07 2016 15:00:24.86 (1462626024.86) end: May 07 2016 15:01:19.96 (1462626079.96) size: 89.7 MB messages: 102 compression: none [102/102 chunks] types: sensor_msgs/Image [060021388200f6f0f447d0fcd9c64743] topics: /image_raw 102 msgs : sensor_msgs/Image 


Running through the bag file data


Now we stop our node and play the recording:

 rosbag play raspicam_image_raw.bag -r 1 --loop 

Let's show the data from the image_raw topic in the rqt_image_view window:

 rosrun rqt_image_view rqt_image_view 

Playback recording bag file on the Raspberry Pi 2 can be viewed on the video.



The rosbag play team also has several useful options:

There is a special tool rqt_bag for recording and working with bag files. On the official page, you can learn more about this utility.
So far this is all about rosbag. I think you will find many uses for the rosbag utility. This is quite a powerful utility and it is difficult to do without it when fully using ROS.
Good luck in projects using ROS!

Source: https://habr.com/ru/post/393811/


All Articles