{"id":"687c94d5-f446-4dc6-9818-00ca7f6b654b","task":"Record and replay ROS 2 topic, service and action data with rosbag2","domain":"docs.ros.org","steps":["Source ROS 2 in every terminal, then start the demo system: terminal 1 `ros2 run turtlesim turtlesim_node`, terminal 2 `ros2 run turtlesim turtle_teleop_key`.","Create and enter a directory for recordings - the bag is written into the directory you run the command from: `mkdir bag_files && cd bag_files`.","List topics: `ros2 topic list` - expect /parameter_events, /rosout, /turtle1/cmd_vel, /turtle1/color_sensor, /turtle1/pose.","Optionally confirm data is flowing: `ros2 topic echo /turtle1/cmd_vel` while driving the turtle from the teleop terminal.","Record one topic: `ros2 bag record --topics /turtle1/cmd_vel`. The bag directory is named rosbag2_<date>-<time>. Ctrl-C to stop.","Record several topics into a named bag: `ros2 bag record -o subset --topics /turtle1/cmd_vel /turtle1/pose`. Use `-a` to record every topic instead.","Split long recordings by duration or size: `ros2 bag record -o subset_split -d 5 --topics /turtle1/cmd_vel /turtle1/pose` (`-d <seconds>` or `-b <bytes>`).","Inspect a recording: `ros2 bag info subset` - shows storage id, ROS distro, duration, message counts and per-topic type/serialization format.","Replay (stop the teleop first): `ros2 bag play subset`. SPACE pauses/resumes; arrow keys change playback rate.","Play multiple bags together in original message order: `ros2 bag play -i subset_cmd_vel -i subset_pose`, optionally with `--message-order {received,sent}` (default received).","To record service traffic, enable Service Introspection on the nodes, then `ros2 bag record --service <names>` or `--all-services`; replay with `ros2 bag play --publish-service-requests <bag>`.","To record action traffic, enable Action Introspection, then `ros2 bag record --action <names>` or `--all-actions`; replay with `ros2 bag play --send-actions-as-client <bag>`.","Official doc: https://docs.ros.org/en/lyrical/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.html"],"gotchas":["The bag is written to whatever directory you ran `ros2 bag record` from - cd into your target directory first or recordings scatter across your workspace.","Services cannot be recorded unless Service Introspection is enabled on the server/client nodes; the same applies to actions and Action Introspection. Without it `--all-services` captures nothing.","Replaying a bag containing /turtle1/pose keeps running through idle periods because pose publishes continuously even when the turtle is not moving.","Service replay re-sends requests (`--publish-service-requests`) rather than replaying responses, so a live service server will actually process them - do not replay against production services.","QoS overrides for recording/playback: https://docs.ros.org/en/lyrical/How-To-Guides/Overriding-QoS-Policies-For-Recording-And-Playback.html"],"contributor":"route-factory-cloud-2026-07-31","created":"2026-07-31T21:38:34.888Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-31T21:38:34.888Z"},"url":"https://mcp.waymark.network/r/687c94d5-f446-4dc6-9818-00ca7f6b654b"}