24.ROS2 recording and playback tool

 

1. Introduction to recording and playback tools

The commonly used recording and playback tool in ROS2 - rosbag2, is used to record topic data. We can use this command to store the topic data as a file. Later, we can directly publish the topic data in the bag file without starting the node.

This tool is very useful when we are making a real robot. For example, we can record a piece of topic data when the robot has problems. After the recording is completed, it can be released multiple times for testing and experimentation.You can also share topic data with others for verification of algorithms, etc.

We try to use the bag tool to record topic data and replay it twice.

 

2. Usage tutorial

2.1. Start the topic node to be recorded

Such as the talker in ros2 demo:

2.2. Record

/topic-name is the topic name

Other options

-o name Customize the name of the output file

-s storage format

Currently only supports sqllite3, others also have extensions

2.3. View the recorded topic information

Before we play a video, we can check the relevant information of the video through the file information, such as the time, size, type, and quantity of the topic record.

2.4. Play and view

2.4.1. Play

Then we can replay the data and use the following command to play the data

2.4.2. View

Use the ros2 topic command to view data

2.4.3. Play options

  1. Play at double speed -r

The -r option can modify the playback rate, such as -r value, such as -r 10, which means playing the topic at 10 times speed.

  1. Loop play -l

This is the single cycle

  1. Play a single topic

 

3. Example

3.1. Run talker node

3.2. Recording

image-20231031162153843

How to stop recording? We can directly use the Ctrl+C command in the terminal to interrupt the recording.

Then you will find multiple folders in the terminal named rosbag2_2023_10_31-08_21_21

Open the folder and you can see the contents

image-20231031162443246

This completes the recording.

3.3. Play and view

Here we play it in a loop

Open another terminal to view the topic:

image-20231031162719003