Main Content

rosbagreader

Access rosbag log file information

    Description

    Therosbagreaderobject 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

    example

    bagreader= rosbagreader(filepath)creates an indexablerosbagreaderobject,bagreader, that contains all the messages from the rosbag log file at the input pathfilepath. Thefilepathinput argument sets theFilePathproperty. To access the data, you can callreadMessagesortimeseriesto extract relevant data.

    Properties

    expand all

    This property is read-only.

    Absolute path to the rosbag file, specified as a character vector.

    Data Types:char

    This property is read-only.

    Timestamp of the first message in the selection, specified as a scalar in seconds.

    Data Types:double

    This property is read-only.

    Timestamp of the last message in the selection, specified as a scalar in seconds.

    Data Types:double

    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 withselect, the property shows the number of messages in this subset.

    Data Types:double

    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

    This property is read-only.

    List of available coordinate frames, specified as a cell array of character vectors. UsecanTransformto check whether specific transformations between frames are available, orgetTransformto query a transformation.

    Data Types:cell

    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

    collapse all

    Load a rosbag log file and parse out specific messages based on the selected criteria.

    Create arosbagreaderobject of all the messages in the rosbag log file.

    bagMsgs = rosbagreader("ros_multi_topics.bag")
    bagMsgs = rosbagreader with properties: FilePath: '/mathworks/devel/bat/Bdoc22a/build/matlab/toolbox/robotics/robotexamples/ros/data/bags/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 =选择(bagMsgs,...Time=[bagMsgs.StartTime bagMsgs.StartTime + 1],...Topic='/odom')
    bagMsgs2 = rosbagreader with properties: FilePath: '/mathworks/devel/bat/Bdoc22a/build/matlab/toolbox/robotics/robotexamples/ros/data/bags/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 (.bag) files by loading the rosbag and checking the available frames. From these frames, usegetTransformto query the transformation between two coordinate frames.

    Load the rosbag.

    bagMsgs = rosbagreader("ros_turtlesim.bag")
    bagMsgs = rosbagreader with properties: FilePath: '/tmp/Bdoc22a_1891349_144921/tp509d8402/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. UsecanTransform检查是否转移mation is available. Specify the time usingrostime.

    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