rosbagreader
Description
The rosbagreader
object is an index of the messages within a
rosbag. You can use it to extract message data from a rosbag, select messages based on
specific criteria, or create a time series of the message properties.
Creation
Description
creates an indexable bagreader
= rosbagreader(filepath
)rosbagreader
object,
bagreader
, that contains all the messages from the rosbag log file
at the input path filepath
. The filepath
input
argument sets the FilePath
property. To access the data, you can call readMessages
or timeseries
to extract relevant data.
Properties
FilePath
— Absolute path to rosbag file
character vector
This property is read-only.
Absolute path to the rosbag file, specified as a character vector.
Data Types: char
StartTime
— Timestamp of first message in selection
scalar
This property is read-only.
Timestamp of the first message in the selection, specified as a scalar in seconds.
Data Types: double
EndTime
— Timestamp of last message in selection
scalar
This property is read-only.
Timestamp of the last message in the selection, specified as a scalar in seconds.
Data Types: double
NumMessages
— Number of messages in selection
scalar
This property is read-only.
Number of messages in the selection, specified as a scalar. When you first load a
rosbag, this property contains the number of messages in the rosbag. Once you select a
subset of messages with select
, the
property shows the number of messages in this subset.
Data Types: double
AvailableTopics
— Table of topics in selection
table
This property is read-only.
Table of topics in the selection, specified as a table. Each row in the table lists one topic, the number of messages for this topic, the message type, and the definition of the type.
Data Types: table
AvailableFrames
— List of available coordinate frames
cell array of character vectors
This property is read-only.
List of available coordinate frames, specified as a cell array of character vectors.
Use canTransform
to check whether specific
transformations between frames are available, or getTransform
to query a transformation.
Data Types: cell
MessageList
— List of messages in selection
table
This property is read-only.
List of messages in the selection, specified as a table. Each row in the table lists one message.
Data Types: table
Object Functions
select | Select subset of messages in rosbag |
readMessages | Read messages from rosbag |
timeseries | Create time series object for selected message properties |
canTransform | Verify if transformation is available |
getTransform | Retrieve transformation between two coordinate frames |
Examples
Create rosbag Selection Using rosbagreader
Object
Load a rosbag log file and parse out specific messages based on the selected criteria.
Create a rosbagreader
object of all the messages in the rosbag log file.
bagMsgs = rosbagreader("ros_multi_topics.bag")
bagMsgs = rosbagreader with properties: FilePath: '/mathworks/devel/bat/Bdoc23b/build/matlab/examples/ros/data/ros_multi_topics.bag' StartTime: 201.3400 EndTime: 321.3400 NumMessages: 36963 AvailableTopics: [4x3 table] AvailableFrames: {0x1 cell} MessageList: [36963x4 table]
Select a subset of the messages based on their timestamp and topic.
bagMsgs2 = select(bagMsgs,... Time=[bagMsgs.StartTime bagMsgs.StartTime + 1],... Topic='/odom')
bagMsgs2 = rosbagreader with properties: FilePath: '/mathworks/devel/bat/Bdoc23b/build/matlab/examples/ros/data/ros_multi_topics.bag' StartTime: 201.3400 EndTime: 202.3200 NumMessages: 99 AvailableTopics: [1x3 table] AvailableFrames: {0x1 cell} MessageList: [99x4 table]
Retrieve the messages in the selection as a cell array.
msgs = readMessages(bagMsgs2)
msgs=99×1 cell array
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
{1x1 Odometry}
⋮
Return certain message properties as a time series.
ts = timeseries(bagMsgs2,... 'Pose.Pose.Position.X', ... 'Twist.Twist.Angular.Y')
timeseries Timeseries contains duplicate times. Common Properties: Name: '/odom Properties' Time: [99x1 double] TimeInfo: tsdata.timemetadata Data: [99x2 double] DataInfo: tsdata.datametadata
Get Transformations from rosbag File Using rosbagreader
Object
Get transformations from rosbag (.bag
) files by loading the rosbag and checking the available frames. From these frames, use getTransform
to query the transformation between two coordinate frames.
Load the rosbag.
bagMsgs = rosbagreader("ros_turtlesim.bag")
bagMsgs = rosbagreader with properties: FilePath: '/tmp/Bdoc23b_2361005_1400741/tpe66d0b34/ros-ex81142742/ros_turtlesim.bag' StartTime: 1.5040e+09 EndTime: 1.5040e+09 NumMessages: 6089 AvailableTopics: [6x3 table] AvailableFrames: {2x1 cell} MessageList: [6089x4 table]
Get a list of available frames.
frames = bagMsgs.AvailableFrames
frames = 2x1 cell
{'turtle1'}
{'world' }
Get the latest transformation between two coordinate frames.
tf = getTransform(bagMsgs,'world',frames{1})
tf = ROS TransformStamped message with properties: MessageType: 'geometry_msgs/TransformStamped' Header: [1x1 Header] Transform: [1x1 Transform] ChildFrameId: 'turtle1' Use showdetails to show the contents of the message
Check for a transformation available at a specific time and retrieve the transformation. Use canTransform
to check if the transformation is available. Specify the time using rostime
.
tfTime = rostime(bagMsgs.StartTime + 1); if (canTransform(bagMsgs,'world',frames{1},tfTime)) tf2 = getTransform(bagMsgs,'world',frames{1},tfTime); end
Version History
Introduced in R2021b
See Also
select
| readMessages
| timeseries
| canTransform
| getTransform
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)