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.
Verify the player status before starting playback.
Start playing all topics from the bag file to the ROS 2 network. The player publishes bag messages in chronological order.
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:
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.
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.
Resume playback from the new position. The player continues publishing messages from the seeked time point.
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.