diff --git a/source/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.rst b/source/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.rst index 045a10d06ab..ae4a7530f20 100644 --- a/source/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.rst +++ b/source/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.rst @@ -135,7 +135,7 @@ To record the data published to a topic use the command syntax: .. code-block:: console - $ ros2 bag record + $ ros2 bag record --topics Before running this command on your chosen topic, open a new terminal and move into the ``bag_files`` directory you created earlier, because the rosbag file will save in the directory where you run it. @@ -143,7 +143,7 @@ Run the command: .. code-block:: console - $ ros2 bag record /turtle1/cmd_vel + $ ros2 bag record --topics /turtle1/cmd_vel [INFO] [rosbag2_storage]: Opened database 'rosbag2_2019_10_11-05_18_45'. [INFO] [rosbag2_transport]: Listening for topics... [INFO] [rosbag2_transport]: Subscribed to topic '/turtle1/cmd_vel' @@ -155,7 +155,7 @@ The movements don't matter, but try to make a recognizable pattern to see when y .. image:: images/record.png -Press ``Ctrl+C`` to stop recording. +Press :kbd:`Ctrl-C` to stop recording. The data will be accumulated in a new bag directory with a name in the pattern of ``rosbag2_year_month_day-hour_minute_second``. This directory will contain a ``metadata.yaml`` along with the bag file in the recorded format. @@ -163,32 +163,58 @@ This directory will contain a ``metadata.yaml`` along with the bag file in the r 3.2 Record multiple topics ~~~~~~~~~~~~~~~~~~~~~~~~~~ -You can also record multiple topics, as well as change the name of the file ``ros2 bag`` saves to. +You can also record multiple topics, as well as change the name of the bag directory ``ros2 bag`` saves to. Run the following command: .. code-block:: console - $ ros2 bag record -o subset /turtle1/cmd_vel /turtle1/pose + $ ros2 bag record -o subset --topics /turtle1/cmd_vel /turtle1/pose [INFO] [rosbag2_storage]: Opened database 'subset'. [INFO] [rosbag2_transport]: Listening for topics... [INFO] [rosbag2_transport]: Subscribed to topic '/turtle1/cmd_vel' [INFO] [rosbag2_transport]: Subscribed to topic '/turtle1/pose' [INFO] [rosbag2_transport]: All requested topics are subscribed. Stopping discovery... -The ``-o`` option allows you to choose a unique name for your bag file. -The following string, in this case ``subset``, is the file name. +The ``-o`` option allows you to choose a unique name for your bag directory. +The following string, in this case ``subset``, is the bag directory name. -To record more than one topic at a time, simply list each topic separated by a space. +To record more than one topic at a time, simply list each topic separated by a space after ``--topics``. In this case, the command output above confirms that both topics are being recorded. - -You can move the turtle around and press ``Ctrl+C`` when you're finished. +You can move the turtle around and press :kbd:`Ctrl-C` when you're finished. .. note:: There is another option you can add to the command, ``-a``, which records all the topics on your system. +3.3 Split recording into multiple files +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can also divide your recording over multiple files, based on either recording duration or file size. +``-d `` ensures that each file only lasts ```` seconds before it starts writing to +a new file, or ``-b `` ensures that each file does not exceed ```` bytes in file size. + +Run the following for at least 15 seconds, allowing for three 5-second bag files to be written: + +.. code-block:: console + + $ ros2 bag record -o subset_separate -d 5 --topics /turtle1/cmd_vel /turtle1/pose + [INFO] [rosbag2_recorder]: Press SPACE for pausing/resuming + [INFO] [rosbag2_recorder]: Listening for topics... + [INFO] [rosbag2_recorder]: Event publisher thread: Starting + [INFO] [rosbag2_recorder]: Recording... + [INFO] [rosbag2_recorder]: Subscribed to topic '/turtle1/cmd_vel' + [INFO] [rosbag2_recorder]: Subscribed to topic '/turtle1/pose' + [INFO] [rosbag2_recorder]: All requested topics are subscribed. Stopping discovery... + [INFO] [rosbag2_cpp]: Writing remaining messages from cache to the bag. It may take a while + [INFO] [rosbag2_cpp]: Writing remaining messages from cache to the bag. It may take a while + [INFO] [rosbag2_cpp]: Writing remaining messages from cache to the bag. It may take a while + +Press :kbd:`Ctrl-C` when you're finished. +You should find a ``subset_separate`` directory with these files inside: +``subset_separate_0.mcap``, ``subset_separate_1.mcap``, and so on. + 4 Inspect topic data ^^^^^^^^^^^^^^^^^^^^ @@ -198,12 +224,12 @@ You can see details about your recording by running: $ ros2 bag info -Running this command on the ``subset`` bag file will return a list of information on the file: +Running this command on the ``subset/subset_0.mcap`` bag file will return a list of information on the file: .. code-block:: console - $ ros2 bag info subset - Files: subset.mcap + $ ros2 bag info subset/subset_0.mcap + Files: subset_0.mcap Bag size: 228.5 KiB Storage id: mcap Duration: 48.47s @@ -212,19 +238,41 @@ Running this command on the ``subset`` bag file will return a list of informatio Messages: 3013 Topic information: Topic: /turtle1/cmd_vel | Type: geometry_msgs/msg/Twist | Count: 9 | Serialization Format: cdr Topic: /turtle1/pose | Type: turtlesim_msgs/msg/Pose | Count: 3004 | Serialization Format: cdr + Services: 0 + Service information: + Actions: 0 + Action information: + +Alternatively, you can also call ``ros2 bag info`` on a bag directory ``subset``, +and all bag files within it will be analyzed as one. 5 Play topic data ^^^^^^^^^^^^^^^^^ -Before replaying the bag file, enter ``Ctrl+C`` in the terminal where the teleop is running. +5.1 Play a single bag file +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Before replaying the bag file, enter :kbd:`Ctrl-C` in the terminal where the teleop is running. Then make sure your turtlesim window is visible so you can see the bag file in action. Enter the command: .. code-block:: console - $ ros2 bag play subset - [INFO] [rosbag2_storage]: Opened database 'subset'. + $ ros2 bag play subset/subset_0.mcap + [INFO] [rosbag2_player]: Set rate to 1 + [INFO] [rosbag2_player]: Adding keyboard callbacks. + [INFO] [rosbag2_player]: Press SPACE for Pause/Resume + [INFO] [rosbag2_player]: Press CURSOR_RIGHT for Play Next Message + [INFO] [rosbag2_player]: Press CURSOR_UP for Increase Rate 10% + [INFO] [rosbag2_player]: Press CURSOR_DOWN for Decrease Rate 10% + Progress bar enabled at 3 Hz. + Progress bar [?]: [R]unning, [P]aused, [B]urst, [D]elayed, [S]topped + [INFO] [rosbag2_player]: Playback until timestamp: -1 + + + ====== Playback Progress ====== + [1751923361.427372456] Duration 0.00/48.47 [R] Your turtle will follow the same path you entered while recording (though not 100% exactly; turtlesim is sensitive to small changes in the system's timing). @@ -243,6 +291,29 @@ To get an idea of how often position data is published, you can run the command: $ ros2 topic hz /turtle1/pose +5.2 Play multiple bag files +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you want to play multiple bag files that are all a part of the same recording, +simply call ``ros2 bag play`` on the bag directory, instead of a file: + +.. code-block:: console + + $ ros2 bag play subset_separate + +This will play all the files inside of the ``subset_separate`` recording consecutively. + +If you want to play a specific selection of files, that can be done by calling ``-i `` +for each file. + +.. code-block:: console + + $ ros2 bag play -i subset_separate/subset_separate_0.mcap -i subset_separate/subset_separate_2.mcap + +This will play the first and third bag files in ``subset_separate``, skipping the second. +They will play with the same relative time as when recorded, meaning there will be a 5 second pause +in between, where the ``subset_separate_1.mcap`` would have played if not omitted. + Managing Service Data --------------------- @@ -340,7 +411,7 @@ Run the command: [INFO] [1713995957.666092458] [rosbag2_recorder]: Recording... Now ``ros2 bag`` is recording the service data published on the ``/add_two_ints`` service. -To stop the recording, enter ``Ctrl+C`` in the terminal. +To stop the recording, enter :kbd:`Ctrl-C` in the terminal. The data will be accumulated in a new bag directory with a name in the pattern of ``rosbag2_year_month_day-hour_minute_second``. This directory will contain a ``metadata.yaml`` along with the bag file in the recorded format. @@ -368,7 +439,7 @@ You can see details about your recording by running: 5 Play service data ^^^^^^^^^^^^^^^^^^^ -Before replaying the bag file, enter ``Ctrl+C`` in the terminal where ``introspection_client`` is running. +Before replaying the bag file, enter :kbd:`Ctrl-C` in the terminal where ``introspection_client`` is running. When ``introspection_client`` stops running, ``introspection_service`` also stops printing the result because there are no incoming requests. Replaying the service data from the bag file will start sending the requests to ``introspection_service``. @@ -517,7 +588,7 @@ Run the command: ... Now ``ros2 bag`` is recording the action data for the ``/fibonacci`` action: goal, result, and feedback. -To stop the recording, enter ``Ctrl+C`` in the terminal. +To stop the recording, enter :kbd:`Ctrl-C` in the terminal. The data will be accumulated in a new bag directory with a name in the pattern of ``rosbag2_year_month_day-hour_minute_second``. This directory will contain a ``metadata.yaml`` along with the bag file in the recorded format.