Main Content

ros2bagreader

Access ROS 2 bag log file information

Since R2021a

    Description

    The ros2bagreader object is an index of the messages within a ROS 2 bag file. You can use it to extract message data from a ROS 2 bag file or select messages based on specific criteria.

    Creation

    Description

    bagreader = ros2bagreader(folderpath) creates an indexable ros2bagreader object, bagreader, that contains all the messages from the ROS 2 bag file at the input path filepath. The folderpath input sets the value of the FilePathproperty.

    ROS 2 bag files are used for storing message data. Their primary use is in the logging of messages transmitted over a ROS 2 network. The resulting bag file can be used for offline analysis, visualization, and storage. MATLAB provides functionality for reading existing bag files.

    Note

    If the ROS 2 bag log file contains custom messages, create custom messages for MATLAB using ros2genmsg function before creating the ros2bagreader object.

    Properties

    expand all

    This property is read-only.

    Absolute path to the ROS 2 bag files, specified as a character vector.

    Data Types: char

    This property is read-only.

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

    Data Types: double

    This property is read-only.

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

    Data Types: double

    This property is read-only.

    Number of messages, specified as a scalar.

    Data Types: double

    This property is read-only.

    Table of available topics, specified as a table. Each row in the table lists one topic, the number of messages for this topic, the message type, and the message definition.

    Data Types: table

    This property is read-only.

    List of messages, specified as a table. Each row in the table lists one message.

    Data Types: table

    Object Functions

    readMessagesRead messages from ros2bagreader object
    selectSelect subset of messages in ros2bagreader

    Examples

    collapse all

    Extract the zip file that contains the ROS 2 bag log file and specify the full path to the log folder.

    unzip('ros2_netwrk_bag.zip');
    folderPath = fullfile(pwd,'ros2_netwrk_bag');

    Create a ros2bagreader object that contains all messages in the log file.

    bag = ros2bagreader(folderPath);

    Get information on the contents of the ros2bagreader object.

    baginfo = ros2("bag","info",folderPath)
    baginfo = struct with fields:
             Path: '/tmp/Bdoc23a_2213998_1465327/tp20a21dc3/ros-ex96596996/ros2_netwrk_bag/ros2_netwrk_bag.db3'
          Version: '1'
        StorageId: 'sqlite3'
         Duration: 207.9020
            Start: [1x1 struct]
              End: [1x1 struct]
             Size: 16839538
         Messages: 166867
            Types: [4x1 struct]
           Topics: [4x1 struct]
    
    

    Get all the messages in the ros2bagreader object.

    msgs = readMessages(bag);

    Select a subset of the messages, filtered by topic.

    bagSel = select(bag,"Topic","/odom");

    Get the messages in the selection.

    msgsFiltered = readMessages(bagSel);

    Version History

    Introduced in R2021a

    expand all

    See Also

    Functions