Main Content

select

Select subset of messages in ros2bag

    Description

    bagsel = select(bag) returns a ros2bag object, bagsel, that contains all of the messages in the ros2bag object, bag.

    This function creates a copy of the ros2bag object or returns a new ros2bag object that contains the specified message selection.

    example

    bagsel = select(bag,Name,Value) provides additional options specified by one or more name-value pair arguments. For example, "Topic","/scan" selects a subset of the messages, filtered by the topic /scan.

    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 ros2bag object that contains all messages in the log file.

    bag = ros2bag(folderPath);

    Get information on the contents of the ros2bag object.

    bag2info = ros2("bag","info",folderPath)
    bag2info = struct with fields:
             Path: '/tmp/Bdoc21b_1757077_4312/tp471a65de/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 ros2bag 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 ros2bag object, specified as a ros2bag object.

    Name-Value Arguments

    Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

    Example: select(bag,"Topic","/scan") selects a subset of the messages, filtered by the topic /scan.

    ROS 2 message type, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Multiple message types can be specified with a cell array.

    Example: select(bag,"MessageType",{"sensor_msgs/CameraInfo","sensor_msgs/LaserScan"})

    Data Types: char | string | cell

    Start and end times of the ros2bag selection, specified as an n-by-2 vector.

    Example: select(bag,"Time",[bag.MessageList(1,1).Time,bag.MessageList(2,1).Time])

    Data Types: uint64

    ROS 2 topic name, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Multiple topic names can be specified with a cell array.

    Example: select(bag,"Topic",{"/scan","/clock"})

    Data Types: char | string | cell

    Output Arguments

    collapse all

    Copy or subset of ros2bag messages, returned as a ros2bag object.

    See Also

    Objects

    Functions

    Introduced in R2021a