Welcome to Jetson Orin NX Developer Kit repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
20.ROS2 recording and playback tool
20. ROS2 recording and playback tool
1. Introduction to the recording and playback tool
Bag2 is a commonly used recording and playback tool in ROS2, and it is used to record topic data. We can use this command to store topic data as a file. Later on, we do not need to start any node, and we can directly publish the topic data in the bag file.
This tool is extremely useful when we are building a real robot. For example, we can record the topic data of a robot while it is having problems. After the recording is finished, we can publish it many times for testing and experimentation, or we can share the topic data with others to verify algorithms, etc.
We will try to use the bag tool to record topic data and play it back a second time.
2. Usage tutorial
2.1. Starting the topic node to be recorded
For example, the talker in the ros2 demo:
ros2 run demo_nodes_py talker
2.2. Recording
/topic-name is the topic name
xxxxxxxxxx# Record a single topicros2 bag record /topic-name# Record multiple topicsros2 bag record topic-name1 topic-name2# Record all topicsros2 bag record -aOther options
-o name Customize the output file name
xxxxxxxxxxros2 bag record -o file-name topic-name-s Storage format
ROS2 Jazzy uses the MCAP storage format by default, and you can also specify an installed storage plugin with -s, for example sqlite3:
xxxxxxxxxxros2 bag record -s sqlite3 /topic-name2.3. Viewing the information of the recorded topics
Before playing back a video, you can view the relevant information about the video through the file information, such as the time, size, type and number of the topic records
xxxxxxxxxx# Assume the recorded file is rosbag2_2023_10_31-07_58_23ros2 bag info rosbag2_2023_10_31-07_58_232.4. Playing back and viewing
2.4.1. Playback
Next we can play the data back again. The following command can be used to play back the data
xxxxxxxxxxros2 bag play rosbag2_2023_10_31-07_58_232.4.2. Viewing
Use the topic command of ros2 to view the data
xxxxxxxxxxros2 topic echo /chatter2.4.3. Playback options
Speed playback -r
The -r option can modify the playback rate. For example, the -r value, for example -r 10, means 10 times the speed, playing the topic ten times faster
xxxxxxxxxxros2 bag play rosbag2_2023_10_31-07_58_23 -r 10Loop playback -l
This is the one-song loop
xxxxxxxxxxros2 bag play rosbag2_2023_10_31-07_58_23 -lPlaying back a single topic
xxxxxxxxxxros2 bag play rosbag2_2023_10_31-07_58_23 --topics /chatter3. Example
3.1. Running the talker node
xxxxxxxxxxros2 run demo_nodes_py talker3.2. Recording
xxxxxxxxxx# Record all topicsros2 bag record -a
How do we stop the recording? We simply press Ctrl+C in the terminal to interrupt the recording.
Then you will find a folder in the terminal, named rosbag2_2023_10_31-08_21_21
Open the folder and you can see its contents
This completes the recording.
3.3. Playing back and viewing
Here we play it back in a loop
xxxxxxxxxxros2 bag play rosbag2_2023_10_31-07_58_23 -l Open another terminal to view the topic:
xxxxxxxxxxros2 topic echo /chatter
