Main Content

readMessages

Read messages from ros2bagreader object

Since R2021a

    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.

    example

    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 the messages in the log file.

    bagReader = ros2bagreader(folderPath);

    Get information about the contents of the ros2bagreader object.

    baginfo = ros2("bag","info",folderPath)
    baginfo = struct with fields:
             Path: 'C:\Users\ros2_netwrk_bag\ros2_netwrk_bag.db3'
          Version: '1'
        StorageId: 'sqlite3'
         Duration: 207.9020
            Start: [1×1 struct]
              End: [1×1 struct]
             Size: 16839538
         Messages: 166867
            Types: [4×1 struct]
           Topics: [4×1 struct]
    

    Get all the messages in the ros2bagreader object.

    msgs = readMessages(bagReader);

    Select a subset of the messages, filtered by topic.

    bagSel = select(bagReader,"Topic","/odom")
    bagSel = 
      ros2bagreader with properties:
    
               FilePath: 'C:\Users\ros2_netwrk_bag'
          AvailableBags: "ros2_netwrk_bag.db3"
              StartTime: 1.6020e+09
                EndTime: 1.6020e+09
        AvailableTopics: [1×3 table]
        AvailableFrames: {0×1 cell}
            MessageList: [5275×3 table]
            NumMessages: 5275
    

    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