ROS entry (xv) recording and playback data

Record data (by creating a bag file)

This section will teach you how to record the data subject ROS system is running, the topic of data records will be saved to the bag cumulative file.

First, execute the following command:

roscore
rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key

The above operation will start two nodes - a node and a visual turtlesim turtlesim keyboard control node. In the terminal window run turtlesim keyboard control node and you should see the following information:

Reading from keyboard
---------------------------
Use arrow keys to move the turtle.

Then press the arrow keys on the keyboard should make turtle in motion. Note that in order to control the movement of turtle you must first select the Terminal window where the keyboard when turtlesim control node starts instead of displaying a virtual window where the turtle.

All topics posted record

First, let's check to see that all topics are published in the current system. To do this, open a new terminal and execute:

rostopic list -v

This should produce the following output:

Published topics:
 * /turtle1/color_sensor [turtlesim/Color] 1 publisher
 * /turtle1/command_velocity [turtlesim/Velocity] 1 publisher
 * /rosout [roslib/Log] 2 publishers
 * /rosout_agg [roslib/Log] 1 publisher
 * /turtle1/pose [turtlesim/Pose] 1 publisher

Subscribed topics:
 * /turtle1/command_velocity [turtlesim/Velocity] 1 subscriber
 * /rosout [roslib/Log] 1 subscriber

Posted above topic section lists the topic of messages can be recorded only saved to the topic of the message file, because only the news has been released before they can be recorded. / Turtle1 / command_velocity topic command message is issued and teleop_turtle node as an input node of turtlesim. And / turtle1 / color_sensor and / turtle1 / pose is released out of the turtlesim node topic messages.

Now we start recording. Open a new terminal window, execute the following command in the terminal:

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

Here we first create a temporary directory for recording, and then run rosbag record command in the directory, and additional -a option, which said it would publish all the data in the current topic are saved to a record file bag.

Then back to the terminal window and the control node is located turtle_teleop turtle move anywhere about 10 seconds.

Press Ctrl-C in the command window to run rosbag record exit the command. Now check to see the contents of ~ / bagfiles directory, you should see a named year, date and time and to .bag as a file with the extension. This bag is the file that contains the topic during rosbag record run all nodes released.

Check the file and play back bag

Now that we have used rosbag record commands to record a document bag, then we can use rosbag info check to see its contents, use the command playback rosbag play out. Next we will see the first file in the bag in which things are recorded. We can use the info command, which you can check to see the contents of the bag without having to file played back. Execute the following command in the directory where the file bag:

rosbag info <your bagfile>

You should see the following information:

bag: 2009-12-04-15-02-56.bag
version: 1.2
start_time: 1259967777871383000
end_time: 1259967797238692999
length: 19367309999
topics:
  - name: /rosout
    count: 2
    datatype: roslib/Log
    md5sum: acffd30cd6b6de30f120938c17c593fb
  - name: /turtle1/color_sensor
    count: 1122
    datatype: turtlesim/Color
    md5sum: 353891e354491c51aabe32df673fb446
  - name: /turtle1/command_velocity
    count: 23
    datatype: turtlesim/Velocity
    md5sum: 9d5c2dcd348ac8f76ce2a4307bd63a13
  - name: /turtle1/pose
    count: 1121
    datatype: turtlesim/Pose
    md5sum: 863b248d5016ca62ea2e895ae5265cf9

This information tells you the name of the topic contained in the document bag, the type and number of messages. We can see, before using rostopic command to view the topic in five has been announced, in fact, only four of which released the news in our recording. Because we all messages with the -a parameter option when running under rosbag record command system will record release all nodes.

The next step is a process to reproduce playback file bag system operation. Terminal window where the first node is running in turtle_teleop_key press Ctrl + C to exit the node. Let turtlesim node continues to run. In the directory where the file bag terminal run the following command:

rosbag play <your bagfile>

In this window you should immediately see a message similar to the following:

Hit space to pause.
[ INFO] 1260210510.566003000: Sleeping 0.200 seconds after advertising /rosout...
[ INFO] 1260210510.766582000: Done sleeping.

[ INFO] 1260210510.872197000: Sleeping 0.200 seconds after advertising /turtle1/pose...
[ INFO] 1260210511.072384000: Done sleeping.

[ INFO] 1260210511.277391000: Sleeping 0.200 seconds after advertising /turtle1/color_sensor...
[ INFO] 1260210511.477525000: Done sleeping.

By default mode, rosbag play command after each message announcement will wait for a short time (0.2 seconds) after the bag really began to publish the contents of the file. The process can wait for some time notification message subscriber data message has announced the news might be coming soon. If rosbag play immediately after the announcement news release, subscriber might receive several messages less than the first release. The waiting time can be specified by the -d option.

Final / turtle1 / command_velocity topic will be released, while the turtle should be like before you control it through turtle_teleop_key node begins to move in the same turtuelsim virtual screen. Rosbag play turtle run from the time elapsed since the start should be approximately equal to press a key before issuing a control command experiences time after the start of this tutorial running rosbag record moved. You can make rosbag play command to wait for some time after the initial portion of the bag to skip the file really start playback by -s parameter options. The last parameter may be more interesting option is the -r option, which allows you to change the news release rate by setting a parameter. If you perform:

rosbag play -r 2 <your bagfile>

You should see the trajectory turtle little different, then the track should be equivalent to the track when you issue control commands through the key generated twice as fast.

Recording data subsets

When running a complex system, such as PR2 software system, there will be hundreds of topics is published, some topics will release large amounts of data (for example, contains topic camera image stream). In such a system, in order to put all topics are recording a single bag to save a file on the hard disk is unrealistic. rosbag record recording command supports only certain specified topic to bag a single file, which allows users to record only the topics that interest them.

If there is turtlesim node running before they quit, then start (relaunch) Keyboard control node associated with the startup file (launch file) again:

rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key

Execute the following command in the directory where the file bag:

rosbag record -O subset /turtle1/command_velocity /turtle1/pose

-O parameter of the command tells rosbag record will save the data to a file named subset.bag, the topic of parameters while back told rosbag record can only record two designated topic. Then move anywhere for a few seconds using the keyboard turtle, and finally press Ctrl + C to exit rosbag record command.

Now check to see content (rosbag info subset.bag) bag file. You should see the following information, which contains only the specified topic when recording:

bag: subset.bag
version: 1.2
start_time: 3196900000000
end_time: 3215400000000
length: 18500000000
topics:
  - name: /turtle1/command_velocity
    count: 8
    datatype: turtlesim/Velocity
    md5sum: 9d5c2dcd348ac8f76ce2a4307bd63a13
  - name: /turtle1/pose
    count: 1068
    datatype: turtlesim/Pose
    md5sum: 863b248d5016ca62ea2e895ae5265cf9

Limitations rosbag record / play command

In the previous section you may have noticed the turtle's path may not be completely mapped onto the path originally generated when the keyboard control - the overall shape should be similar, but not exactly the same. Cause of the problem is very sensitive to changes in the movement path turtlesim system timing accuracy. rosbag subject to the performance of their own can not fully replicate the behavior of the system when run record, rosplay too. For turtlesim such as a node, when very small changes in the system during the processing of the message timing generator also make subtle changes behavior, the user should be able to perfectly imitate undesirable system behavior.

Now that you have learned how to record and playback data, then we started to learn how to use roswtf to check system failure

Published 34 original articles · won praise 2 · Views 2334

Guess you like

Origin blog.csdn.net/weixin_44088559/article/details/104990335