主要内容

setRate

R2026b

Change replay rate of ROS 2 bag player

Since R2026b

    Description

    setRate(bagplayer,rate) changes the replay rate of the ROS 2 bag player to the specified playback-rate multiplier. A rate of 1.0 replays at the original recorded speed. Values greater than 1.0 speed up replay, and values less than 1.0 slow it down. You can change the rate during an active replay session, and the new rate takes effect immediately. The rate value must be a positive numeric scalar.

    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.

    Playback-rate multiplier, specified as a positive numeric scalar. A value of 1.0 replays at the original recorded speed. Values greater than 1.0 speed up replay, and values less than 1.0 slow it down. For example, a rate of 2.0 replays at twice the original speed, and a rate of 0.5 replays at half speed.

    Data Types: double

    Version History

    Introduced in R2026b