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.

583030-20190325145820479-1384966493.png

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

583030-20190325145838079-881111949.png

在真的发送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.

转载于:https://www.cnblogs.com/sdu20112013/p/10593771.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值