Learning ROS: Recording and playing back data

本文主要部分来源于ROS官网的Tutorials.

Description: 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.

roscore &
rosrun turtlesim turtlesim_node  &
rosrun turtlesim turtle_teleop_key
rostopic list -v  # examine the full list of topics that are currently being published in the running system.

# making a temporary directory to record data and then running rosbag record with the option -a
mkdir ~/bagfiles
cd ~/bagfiles
rosbag record -a # Now all published topics will be accumulated in a bag file. 

现在可以用方向键控制乌龟运动,所有Topics都会被记录到*.bag文件,本例文件名是当前时间。

接下来回放:

rosbag play <your bagfile>

可以看到乌龟根据回放的message运动。

Recording a subset of the data

rosrun turtlesim turtlesim_node 
rosrun turtlesim turtle_teleop_key

rosbag record -O subset /turtle1/cmd_vel /turtle1/pose # 只记录感兴趣的topics, 记录到subset.bag中

The limitations of rosbag record/play

play(回放模拟)的效果可能和record(真实历史)时不完全一样,因为:

  • rosbag是通过记录topics来回放模拟历史msgs信息。
  • 仿真的轨迹与 初始状态有关系。
  • 考虑到系统调度的复杂性,难以保证时间完全精确, 仿真的轨迹与 微小的时间差 也有关系。
原文地址:https://www.cnblogs.com/xbit/p/8479414.html