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:
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:
-r FACTOR determines the speed factor (frame rate is multiplied by this value)
-hz = HZ defines the frame rate in Hz (default is 100)
--loop loops playback ("rewinds" to the beginning when the end of the recording is reached)
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!