主要内容

stopPlaying

R2026b

Stop playing ROS 2 bag data to ROS 2 network

Since R2026b

    Description

    stopPlaying(bagplayer) stops playing ROS 2 bag data and returns the player to an idle state. After stopping, the player resets the playback position to the beginning of the bag. You can call startPlaying again on the same object to restart playback.

    example

    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.

    Version History

    Introduced in R2026b