Recording and playing back data

Recording and playing back data

This tutorial will teach you how to record data from a running ROS system into a .bag file, and then to play back the data to produce similar behavior in a running system.

rostopic list -v

//This should yield the following output:
Published topics:
 * /turtle1/color_sensor [turtlesim/Color] 1 publisher
 * /turtle1/cmd_vel [geometry_msgs/Twist] 1 publisher
 * /rosout [rosgraph_msgs/Log] 2 publishers
 * /rosout_agg [rosgraph_msgs/Log] 1 publisher
 * /turtle1/pose [turtlesim/Pose] 1 publisher

Subscribed topics:
 * /turtle1/cmd_vel [geometry_msgs/Twist] 1 subscriber
 * /rosout [rosgraph_msgs/Log] 1 subscriber

只有topic list中列出的类型的msg才可以被record到data log file。

The list of published topics are the only message types that could potentially be recorded in the data log file, as only published messages are recorded.

rosbag用法如下:

suchang@suchang-virtual-machine:~/bagfiles$ rosbag 
Usage: rosbag <subcommand> [options] [args]

A bag is a file format in ROS for storing ROS message data. The rosbag command can record, replay and manipulate bags.

Available subcommands:
   check    Determine whether a bag is playable in the current system, or if it can be migrated.
   compress     Compress one or more bag files.
   decompress   Decompress one or more bag files.
   decrypt      Decrypt one or more bag files.
   encrypt      Encrypt one or more bag files.
   filter   Filter the contents of the bag.
   fix      Repair the messages in a bag file so that it can be played in the current system.
   help  
   info     Summarize the contents of one or more bag files.
   play     Play back the contents of one or more bag files in a time-synchronized fashion.
   record   Record a bag file with the contents of specified topics.
   reindex      Reindexes one or more bag files.

For additional information, see http://wiki.ros.org/rosbag

在真的发送bag file中记录的msg之前会等待0.2s,以防止前几个msg丢失.

In its default mode rosbag play will wait for a certain period (.2 seconds) after advertising each message before it actually begins publishing the contents of the bag file. Waiting for some duration allows any subscriber of a message to be alerted that the message has been advertised and that messages may follow. If rosbag play publishes messages immediately upon advertising, subscribers may not receive the first several published messages. The waiting period can be specified with the -d option.

rosbag play可以不从bag file的开始播放,可以用-s 指定从距离文件初始记录时间xx秒开始.

rosbag play -r 2 ./2019-03-25-13-48-22.bag
-r 参数指定播放倍速.

在一个复杂系统里,可能有成百上千个topic,我们不可能记录所有topic上的msg.

// -O means output.生成一个subset.bag文件.  只记录/turtle1/cmd_vel /turtle1/pose这两个topic上的msg.
rosbag record -O subset /turtle1/cmd_vel /turtle1/pose

rosbag record/play的局限

rosbag很难精确地复制一个running systerm中的行为,因为rosrecord记录的msg的时间很难做到足够精确,比方说系统1s的时候发了msg1,2s的时候发了msg2,rosbag记录到的时候可能已经是1.01s和2.02s,这样的话就差出了0.01s,在play back的时候可能就会产生微小误差.

In the previous section you may have noted that the turtle's path may not have exactly mapped to the original keyboard input - the rough shape should have been the same, but the turtle may not have exactly tracked the same path. The reason for this is that the path tracked by turtlesim is very sensitive to small changes in timing in the system, and rosbag is limited in its ability to exactly duplicate the behavior of a running system in terms of when messages are recorded and processed by rosrecord, and when messages are produced and processed when using rosplay. For nodes like turtlesim, where minor timing changes in when command messages are processed can subtly alter behavior, the user should not expect perfectly mimicked behavior.

猜你喜欢

转载自www.cnblogs.com/sdu20112013/p/10593771.html
今日推荐