Contenido principal

resumePlaying

R2026b

Resume playing ROS 2 bag data after pausing

Since R2026b

    Description

    resumePlaying(bagplayer) continues playing ROS 2 bag messages after a paused session. The player resumes publishing messages to the ROS 2 network from the paused playback position, allowing the session to continue where it left off.

    example

    Examples

    collapse all

    This example shows how to create a ros2bagplayer object for a ROS 2 bag file, start playback, pause at a moment of interest, seek to a specific target timestamp, resume playback from that point, and stop when the investigation is complete. Use this workflow to navigate to a relevant event in a large bag without replaying the entire file from the beginning.

    Create a ROS 2 bag player to play recorded ROS 2 network data from a bag file.

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

    Verify the player status before starting playback.

    disp(bagPlayer.PlayerStatus)
    Idle
    

    Start playing all topics from the bag file to the ROS 2 network. The player publishes bag messages in chronological order.

    startPlaying(bagPlayer);
    disp("Playback started.")
    Playback started.
    
    disp(bagPlayer.PlayerStatus)
    Playing
    

    You can run ros2 topic echo topicName with topicName specified as any of topic from the bag to verify that the player is publishing messages. Here is a sample code:

    ros2 topic echo /scan
    

    Allow playback to run briefly, then pause the player to inspect a moment of interest. Pausing preserves the playback position so you can investigate downstream system behavior.

    pause(3)
    pausePlaying(bagPlayer);
    disp("Playback paused.")
    disp(bagPlayer.PlayerStatus)

    Seek to a target timestamp in the bag to skip directly to the event of interest. The player repositions to the specified time point (in seconds) or the nearest valid time point in the bag.

    targetTime = 120.5;
    seekPlayer(bagPlayer,targetTime);
    disp("Seeked to " + targetTime + " seconds in the bag.")

    Resume playback from the new position. The player continues publishing messages from the seeked time point.

    resumePlaying(bagPlayer);
    disp("Playback resumed from seeked position.")
    disp(bagPlayer.PlayerStatus)

    Allow playback to continue for the duration of interest, then stop the player to end the investigation. Stopping returns the player to an idle state.

    pause(5)
    stopPlaying(bagPlayer);
    disp("Playback stopped.")
    disp(bagPlayer.PlayerStatus)

    Input Arguments

    collapse all

    ROS 2 bag player, specified as a ros2bagplayer object.

    Version History

    Introduced in R2026b