Contenido principal

startPlaying

R2026b

Start playing ROS 2 bag data to ROS 2 network

Since R2026b

    Description

    startPlaying(bagplayer) begins publishing messages from the ROS 2 bag to the ROS 2 network. Any active ROS 2 subscribers matching the bag's topics will begin receiving messages as if from a live publisher. Messages are published in chronological order with the original recorded timing.

    example

    startPlaying(bagplayer,Name=Value) starts replaying ROS 2 bag data using one or more name-value arguments to specify include and exclude topic filters.

    Examples

    collapse all

    Create a ros2bagplayer object, start playing a selected subset of topics using include and exclude filters, change the playback speed during the run, and stop playback when the scenario is complete. This workflow is useful for playing filtered topics to the ROS 2 network and adjusting the playback rate to speed up or slow down testing.

    Create a ROS 2 bag player to play recorded 3D visualization data from a bag file.

    bagPlayer = ros2bagplayer(fullfile(pwd,"ros2bag_3D_data"));

    Start playback with topic filters. Use ExcludeTopics to skip the second marker topic and play only the scan and first marker topic. Exclude filters let you remove irrelevant topics from playback without listing every topic you want to keep. Note that ExcludeTopics can only be used when IncludeTopics is left at its default (all topics).

    startPlaying(bagPlayer, ...
        ExcludeTopics={'/visualization_marker_2'});
    disp("Playback started with filtered topics.")
    Playback started with filtered topics.
    
    disp(bagPlayer.PlayerStatus)
    Playing
    

    Allow playback to run at the default rate (1x) for an initial observation period.

    pause(2)

    Speed up the playback rate to 3x to fast-forward through a less interesting portion of the data. A rate value greater than 1.0 speeds up playback, while a value less than 1.0 slows it down. The new rate takes effect immediately.

    setRate(bagPlayer,3.0);
    disp("Playback rate set to 3x.")
    Playback rate set to 3x.
    

    After fast-forwarding, slow down the playback rate to 0.5x for detailed inspection of a critical scenario segment.

    pause(2)
    setRate(bagPlayer,0.5);
    disp("Playback rate set to 0.5x for detailed inspection.")
    Playback rate set to 0.5x for detailed inspection.
    

    Return the playback rate to the original recorded speed (1x).

    pause(2)
    setRate(bagPlayer,1.0);
    disp("Playback rate restored to 1x.")
    Playback rate restored to 1x.
    

    Stop playback when the test scenario is complete. The player resets to an idle state, and you can call startPlaying again to restart from the beginning with the same or different filters.

    pause(2)
    stopPlaying(bagPlayer);
    The player is currently idle. You must start playing before attempting to stop.
    
    disp("Playback stopped.")
    Playback stopped.
    
    disp(bagPlayer.PlayerStatus)
    Idle
    

    Input Arguments

    collapse all

    ROS 2 bag player, specified as a ros2bagplayer object.

    Name-Value Arguments

    expand all

    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: startPlaying(bagplayer,IncludeTopics={"/cam","/imu"},ExcludeTopicTypes={'sensor_msgs/Image'})

    To understand filter precedence, include filters first narrow the set of topics to play or replay, and exclude filters then further remove topics from that narrowed set.

    Include Filters

    expand all

    Name of topics to include during playback, specified as a string scalar, character vector, or a cell array.

    You can apply or modify these settings only through the startPlaying function when you start a new playback session.

    Name of topics to include during playback that match regular expressions, specified as a string scalar or character vector.

    You can apply or modify these settings only through the startPlaying function when you start a new playback session.

    Exclude Filters

    expand all

    Name of topics to exclude from playback, specified as a string scalar, character vector, or a cell array.

    You can apply or modify these settings only through the startPlaying function.

    Name of topics to exclude from playback that match regular expressions, specified as a string scalar or character vector.

    You can apply or modify these settings only through the startPlaying function.

    Version History

    Introduced in R2026b