ROS Log Files (rosbags)Introduction
A rosbag or bag is a file format in ROS for storing ROS message
data. These bags are often created by subscribing to one or more ROS
topics, and storing the received message data in an efficient file
structure. MATLAB® can read these rosbag files and help with
filtering and extracting message data. The following sections detail
the structure of rosbags in MATLAB® and the workflow for extracting
data from them.MATLAB rosbag Structure
When accessing rosbag log files, call rosbag and specify the file path to the object. MATLAB then creates a BagSelection object that contains an
index of all the messages from the rosbag.
The BagSelection object has the following
properties related to the rosbag:
FilePath: a character vector of
the absolute path to the rosbag file.
StartTime: a scalar indicating
the time the first message was recorded
EndTime: a scalar indicating the
time the last message was recorded
NumMessages: a scalar indicating
how many messages are contained in the file
AvailableTopics: a list of what topic and message types
were recorded in the bag. This is stored as table data that lists the number of
messages, message type, and message definition for each topic. For more
information on table data types, see Access Data in Tables. Here is
an example output of this table:
ans =
NumMessages MessageType MessageDefinition
___________ ______________________ _________________
/clock 12001 rosgraph_msgs/Clock [1x185 char]
/gazebo/link_states 11999 gazebo_msgs/LinkStates [1x1247 char]
/odom 11998 nav_msgs/Odometry [1x2918 char]
/scan 965 sensor_msgs/LaserScan [1x2123 char]
MessageList: a list of every message in the bag with rows
sorted by time stamp of when the message was recorded. This list can be indexed
and you can select a portion of the list this way. Calling select allows you to select subsets
based on time stamp, topic or message type.
Also, note that the BagSelection object contains an index for all the
messages. However, you must still use functions to extract the data. For extracting this
information, see readMessages for getting messages based on
indices as a cell array or see timeseries for reading the data of specified properties as a time
series.Workflow for rosbag Selection
When working with rosbags, there is a general procedure of how
you should extract data.
Load a rosbag: Call rosbag and the file path to load
file and create BagSelection.
Examine available messages:
Examine BagSelection properties (AvailableTopics, NumMessages, StartTime, EndTime,
and MessageList) to determine how to select a subset
of messages for analysis.
Select messages: Call select to create a selection of
messages based on your desired properties.
Extract message data: Call readMessages or timeseries to get message data as
either a cell array or time series data structure.
Visualize, analyze or process
data: Use the extracted data for your specific application.
You can plot data or develop algorithms to process data.
The following figure also shows the workflow.
Limitations
There are a few limitations in the rosbag support within MATLAB:
MATLAB can only parse uncompressed rosbags. See the ROS
Wiki for a tool to decompress a compressed rosbag.
Only rosbags in the v2.0 format are supported. See the ROS Wiki for more
information on different bag formats
The file path to the rosbag must always be accessible.
Because the message selection process does not retrieve any data,
the file needs to be available for reading when the message data is
accessed.
See Also
Related Topics