Main Content

readMessages

Read messages from ros2bagreader object

    Description

    msgs = readMessages(bag) returns data from all of the messages in the ros2bagreader object bag. The messages are returned as a cell array of structures.

    msgs = readMessages(bag,rows) returns data from the messages in the rows specified by rows. The range of the rows is [1 bag.NumMessages].

    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/Bdoc22b_2054784_2434877/tpe79d7e9c/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);

    Input Arguments

    collapse all

    Messages in the ros2bagreader object, specified as a ros2bagreader object.

    Rows of the ros2bagreader object, specified as an n-element vector. n is the number of rows to retrieve messages from. Each entry in the vector corresponds to a numbered message in the bag. The range of the rows is [1 bag.NumMessages].

    Output Arguments

    collapse all

    ROS 2 message data, returned as a cell array of structures.

    Version History

    Introduced in R2021a

    See Also

    Objects

    Functions