Main Content

select

Select subset of messages in rosbag

    Description

    bagreadersel = select(bagreader) returns a rosbagreader object bagreadersel, that contains all of the messages in the rosbagreader object bagreader.

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

    example

    bagreadersel = select(bagreader,Name=Value) specifies additional parameters using one or more name-value arguments. For example Topic="/odom" selects a subset of the messages, filtered by the topic /odom.

    Examples

    collapse all

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

    Create a rosbagreader object 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 = select(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
    

    Input Arguments

    collapse all

    Index of the messages in the rosbag, specified as a rosbagreader object.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: Topic="/odom" selects a subset of the messages, filtered by the topic /odom.

    ROS message type, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Specify multiple message types by using a cell array.

    Example: select(bagreader,MessageType={"nav_msgs/Odometry","rosgraph_msgs/Clock"})

    Data Types: char | string | cell

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

    Example: select(bagreader,Time=[bag.StartTime,bag.StartTime+1])

    Data Types: double

    ROS topic name, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Specify multiple topic names by using a cell array.

    Example: select(bagreader,Topic={"/odom","/clock"})

    Data Types: char | string | cell

    Output Arguments

    collapse all

    Copy or subset of rosbag messages, returned as a rosbagreader object.

    Version History

    Introduced in R2021b