Recording and playing back data

Recording data (creating a bag file)

This section of the tutorial will instruct you how to record topic data from a running ROS system. The topic data will be accumulated in a bag file.

First, execute the following two commands:

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

This will start two nodes - the turtlesim visualizer and a node that allows for the keyboard control of turtlesim using the arrows keys on the keyboard. If you select the terminal window from which you launched turtle_keyboard, you should see something like the following:

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

Pressing the arrow keys on the keyboard should cause the turtle to move around the screen. Note that to move the turtle you must have the terminal from which you launched turtlesim selected and not the turtlesim window.

Recording all published topics

First lets examine the full list of topics that are currently being published in the running system. To do this, open a new terminal and execute the command:

rostopic list -v
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

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. The topic /turtle1/cmd_vel is the command message published by teleop_turtle that is taken as input by the turtlesim process. The messages /turtle1/color_sensor and /turtle1/pose are output messages published by turtlesim.

We now will record the published data. Open a new terminal window. In this window run the following commands:

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

Here we are just making a temporary directory to record data and then running rosbag record with the option -a, indicating that all published topics should be accumulated in a bag file.

Move back to the terminal window with turtle_teleop and move the turtle around for 10 or so seconds.

In the window running rosbag record exit with a Ctrl-C. Now examine the contents of the directory ~/bagfiles. You should see a file with a name that begins with the year, data, and time and the suffix .bag. This is the bag file that contains all topics published by any node in the time that rosbag record was running.

Examining and playing the bag file

Now that we‘ve recorded a bag file using rosbag record we can examine it and play it back using the commands rosbag info and rosbag play. First we are going to see what‘s recorded in the bag file. We can do the info command -- this command checks the contents of the bag file without playing it back. Execute the following command from the bagfiles directory:

rosbag info <your bagfile>

You should see something like:

path:        2014-12-10-20-08-34.bag
version:     2.0
duration:    1:38s (98s)
start:       Dec 10 2014 20:08:35.83 (1418270915.83)
end:         Dec 10 2014 20:10:14.38 (1418271014.38)
size:        865.0 KB
messages:    12471
compression: none [1/1 chunks]
types:       geometry_msgs/Twist [9f195f881246fdfa2798d1d3eebca84a]
             rosgraph_msgs/Log   [acffd30cd6b6de30f120938c17c593fb]
             turtlesim/Color     [353891e354491c51aabe32df673fb446]
             turtlesim/Pose      [863b248d5016ca62ea2e895ae5265cf9]
topics:      /rosout                    4 msgs    : rosgraph_msgs/Log   (2 connections)
             /turtle1/cmd_vel         169 msgs    : geometry_msgs/Twist
             /turtle1/color_sensor   6149 msgs    : turtlesim/Color
             /turtle1/pose           6149 msgs    : turtlesim/Pose

This tells us topic names and types as well as the number (count) of each message topic contained in the bag file. We can see that of the topics being advertised that we saw in the rostopic output, four of the five were actually published over our recording interval. As we ran rosbag record with the -a flag it recorded all messages published by all nodes.

The next step in this tutorial is to replay the bag file to reproduce behavior in the running system. First kill the teleop program that may be still running from the previous section - a Ctrl-C in the terminal where you started turtle_teleop_key. Leave turtlesim running. In a terminal window run the following command in the directory where you took the original bag file:

rosbag play <your bagfile>

In this window you should immediately see something like:

[ INFO] [1418271315.162885976]: Opening 2014-12-10-20-08-34.bag

Waiting 0.2 seconds after advertising topics... done.

Hit space to toggle paused, or ‘s‘ to step.

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.

Eventually the topic /turtle1/cmd_vel will be published and the turtle should start moving in turtlesim in a pattern similar to the one you executed from the teleop program. The duration between running rosbag play and the turtle moving should be approximately equal to the time between the original rosbag record execution and issuing the commands from the keyboard in the beginning part of the tutorial. You can have rosbag play not start at the beginning of the bag file but instead start some duration past the beginning using the -s argument. A final option that may be of interest is the -r option, which allows you to change the rate of publishing by a specified factor. If you execute:

rosbag play -r 2 <your bagfile>

You should see the turtle execute a slightly different trajectory - this is the trajectory that would have resulted had you issued your keyboard commands twice as fast.

Recording a subset of the data

The rosbag record command supports logging only particular topics to a bag file, allowing a user to only record the topics of interest to them.

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

The -O argument tells rosbag record to log to a file named subset.bag, and the topic arguments cause rosbag record to only subscribe to these two topics. Move the turtle around for several seconds using the keyboard arrow commands, and then Ctrl-C the rosbag record.

Now check the contents of the bag file (rosbag info subset.bag). You should see something like this, with only the indicated topics:

path:        subset.bag
version:     2.0
duration:    12.6s
start:       Dec 10 2014 20:20:49.45 (1418271649.45)
end:         Dec 10 2014 20:21:02.07 (1418271662.07)
size:        68.3 KB
messages:    813
compression: none [1/1 chunks]
types:       geometry_msgs/Twist [9f195f881246fdfa2798d1d3eebca84a]
             turtlesim/Pose      [863b248d5016ca62ea2e895ae5265cf9]
topics:      /turtle1/cmd_vel    23 msgs    : geometry_msgs/Twist
             /turtle1/pose      790 msgs    : turtlesim/Pose

The limitations of rosbag record/play

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.

时间: 2024-08-04 07:40:03

Recording and playing back data的相关文章

论文笔记之:Playing for Data: Ground Truth from Computer Games

Playing for Data: Ground Truth from Computer Games ECCV 2016 Project Page:http://download.visinf.tu-darmstadt.de/data/from_games/index.html arXiv Paper : http://arxiv.org/pdf/1608.02192.pdf 摘要: 本文有意思哦,从游戏中的视频帧中得到新的训练数据,为什么用这些数据呢?众所周知,最近的计算机视觉很大程度上依赖于

2018-11-3 星期六

English: listening.speaking.reading.writing.translation 1. Do you drink a lot of water? Well, I would like to think myself as a person who drinks a lot of water, but that is not true. Sometimes I got so busy. Sometimes I got occupied that I forgot to

IOS 音频播放

iOS音频播放 (一):概述 Audio Playback in iOS (Part 1) : Introduction 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也因此对于iOS下的音频播放实现有了一定的研究.写这个系列的博客目的一方面希望能够抛砖引玉,另一方面也是希望能帮助国内其他的iOS开发者和爱好者少走弯路(我自己就遇到了不少的坑=.=). 本篇为<iOS音频播放>系列的第一篇,主要将对iOS下实现音频播放的方法进行概述. 基础 先来简单了解一

一篇对iOS音频比较完善的文章

转自:http://www.cnblogs.com/iOS-mt/p/4268532.html 感谢作者:梦想通 前言 从事音乐相关的app开发也已经有一段时日了,在这过程中app的播放器几经修改我也因此对于iOS下的音频播放实现有了一定的研究.写这个系列的博客目的一方面希望能够抛砖引玉,另一方面也是希望能帮助国内其他的iOS开发者和爱好者少走弯路(我自己就遇到了不少的坑=.=). 本篇为<iOS音频播放>系列的第一篇,主要将对iOS下实现音频播放的方法进行概述. 基础 先来简单了解一下一些基

通过WinAPI播放PCM声音

在Windows平台上,播放PCM声音使用的API通常有如下两种. waveOut and waveIn:传统的音频MMEAPI,也是使用的最多的 xAudio2:C++/COM API,主要针对游戏开发,是DirectSound的基础 在Windows Vista以后,推出了更加强大的WASAPI ,并用WASAPI封装了MME以及DirectSound API. 对于前面的两个API,在.net平台下有如下封装: NAudio Sharpdx WSAPI可能由于更加复杂,没有什么比较完善的封

使用GNU/Linux播放电视节目

目前,生活中很多事情都可以在电脑前完成,学习.工作.音乐.视频等.如果也可以在电脑上收看有线电视节目的话,那就更好了.为此,我购买了圆刚视频采集卡AverMedia C725B.如下图所示. 官方给出的此卡介绍为(详见这里): C725标清采集卡是一张支持AV端子.S端子以及立体声输入的PCI-E撷取卡,可将PAL.NTSC和SECAM等模拟格式影像数字化,撷取并另存为 无压缩的AVI格式档案.C725标清采集卡随附的软件开发工具包(SDK)提供常用功能,能帮助开发者或系统整合商轻松且有效率地完

Using Sahi(转)

Using Sahi - Before you start - Prerequisites Java 1.5 or above is needed for running Sahi. Download Sahi Download Sahi V3 (2009-11-30) from SourceForge Install Sahi Unzip sahi.zip to a desired location Start proxy of Sahi: Windows: - Go to <sahi_roo

【转载】How to develop your own Boot Loader【怎么样开发自己的bootloader】

How to develop your own Boot Loader 怎么样开发自己的bootloader Table of content[目录] 1. Who may be interested[谁可能会感兴趣]2. What is Boot Loader [Bootloader是什么]3. Be ready to go deeper [深入探究前的准备]3.1. So what language you should know to develop Boot Loader [开发Boot

iOS音频播放(二):AudioSession

(本文转自码农人生) 前言 在实施前一篇中所述的7个步骤步之前还必须面对一个麻烦的问题,AudioSession. AudioSession简介 AudioSession这个玩意的主要功能包括以下几点(图片来自官方文档): 1. 确定你的app如何使用音频(是播放?还是录音?) 2. 为你的app选择合适的输入输出设备(比如输入用的麦克风,输出是耳机.手机功放或者airplay) 3. 协调你的app的音频播放和系统以及其他app行为(例如有电话时需要打断,电话结束时需要恢复,按下静音按钮时是否