Common components in ROS (6)-rosbag data recording and playback

Common components in ROS (6)-rosbag data recording and playback

Overview

In order to facilitate debugging and testing, ROS provides a data recording and playback function package-rosbag, which can help developers collect the message data of the ROS system at runtime, and then replay it in an offline state.
Introduce the realization method of rosbag data recording and playback through the tortoise routine.

One, record data

First start all the nodes required by the keyboard to control the turtle routine:

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

After the startup is successful, you can see the little turtle in the interface, and you can control the movement of the turtle through the keyboard in the terminal.
View topics in the current ROS system:

rostopic list -v

Next, use rosbag to grab the messages of these topics, and pack them into a file and place them in the specified folder:

mkdir ~/bagfiles
cd ~/bagfiles
rosbag record -a

rosbag record is a command for data recording, and the -a (all) parameter means to record all published messages. Now that the message recording has started, we can control the turtle to move for a period of time in the terminal, and then press "Ctrl+C" in the terminal where the data recording is running to terminate the data recording. The newly generated data log file is saved in the newly created ~/bagfiles folder.

Two, playback data

After the data recording is completed, the data recording file can be used for data playback. The rosbag function package provides the info command to view the detailed information of the data record file. The format of the command is as follows:

rosbag info <your bagfile>

Use the info command to view the previously generated data log file.
It can be seen from the information that all topics, message types, number of messages and other information contained in the data logging package. Terminate the previously opened turtle_teleop_key control node and restart turtlesim_node, use the following command to replay the recorded topic data:

rosbag play <your bagfile>

After a short waiting time, the data starts to play back, and the turtle's motion rules should be exactly the same as the state of the previous data record.

Guess you like

Origin blog.csdn.net/weixin_45661757/article/details/112794669