Recording Data Using Bag Files
Todo
Update for ROS2.
You can record data conveniently in bags. More information on bag files can be found here. The standard tool to record and play back bag files is rosbag.
Typically, you want to use this tool from the command-line.
Attention
Please check the command-line documentation here: http://wiki.ros.org/rosbag/Commandline!
Recording bag files
You can record data using rosbag record
. This subscribes to topics and writes a bag file with the contents of all messages published on those topics.
To record specific topics, use
$ rosbag record topic1 topic2
High bandwidth messages, such as camera images, can overload the network. For this reason, do not record camera images. If you really need camera data, include just a single topic. Due to image processing, our setup includes a lot of camera image topics. Recording all of these topics will overload the network.
You can exclude topics matching regular expressions with -x
.
To record all but the camera topics, execute
$ rosbag record -a -x "(.*)camera(.*)"
where (.*)
stands for an arbitrary number of arbitrary characters. This means that any topic including the substring camera
will not be recorded.
Attention
While a temporary binary file is created when rosbag record
is called, the final file isn’t written until stopping the recording using Ctrl + C.
Always make sure to properly end your recording!
Checking and playing back bag files
Once you have recorded a bag file, you might want to check its contents. Often times, you realize after the experiments that some topic is missing, due to e.g. typos. Note that we cannot give you additional lab time if you forgot to record all data, so make sure to check while still in the lab! It can be useful to record a test-bag in the beginning for this purpose.
Use rosbag info
to display a human-readable summary of the contents of the bag files.
Additionally, rqt
has a tool to analyze bag files. You can find it under Plugins/Logging/Bags
.
After loading your bag file, you get a list of recorded topics. Moreover, you can see at what times during the recording messages were actually received (displayed in blue here).
Finally, you can replay bag files using rosbag play
.
Attention
Never replay rosbag files while the real vehicle is running. ROS cannot differentiate between messages send live and messages replayed at that moment. While the time stamp may be different, replaying e.g. actuator signals will lead to unexpected behaviour!