Skip to content

Commit 79acc6d

Browse files
authored
rosbag2 action record/replay support. (#5239)
* rosbag2 action record/replay support. Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com> * address review comments. Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com> * address more review comments. Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com> --------- Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
1 parent d3be799 commit 79acc6d

File tree

1 file changed

+222
-8
lines changed

1 file changed

+222
-8
lines changed

source/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.rst

Lines changed: 222 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
Recording and playing back data
88
===============================
99

10-
**Goal:** Record data published on a topic and a service so you can replay and examine it any time.
10+
**Goal:** Record data published on a topic, a service and an action so you can replay and examine it any time.
1111

1212
**Tutorial level:** Beginner
1313

14-
**Time:** 15 minutes
14+
**Time:** 20 minutes
1515

1616
.. contents:: Contents
1717
:depth: 2
@@ -20,10 +20,10 @@ Recording and playing back data
2020
Background
2121
----------
2222

23-
``ros2 bag`` is a command line tool for recording data published on topics and services in your ROS 2 system.
24-
It accumulates the data passed on any number of topics and services, then saves it in a database.
23+
``ros2 bag`` is a command line tool for recording data published on topics, services and actions in your ROS 2 system.
24+
It accumulates the data passed on any number of topics, services and actions, then saves it in a database.
2525
You can then replay the data to reproduce the results of your tests and experiments.
26-
Recording topics and services is also a great way to share your work and allow others to recreate it.
26+
Recording topics, services and actions is also a great way to share your work and allow others to recreate it.
2727

2828

2929
Prerequisites
@@ -33,8 +33,8 @@ You should have ``ros2 bag`` installed as a part of your regular ROS 2 setup.
3333

3434
If you need to install ROS 2, see the :doc:`Installation instructions <../../../Installation>`.
3535

36-
This tutorial talks about concepts covered in previous tutorials, like :doc:`nodes <../Understanding-ROS2-Nodes/Understanding-ROS2-Nodes>`, :doc:`topics <../Understanding-ROS2-Topics/Understanding-ROS2-Topics>` and :doc:`services <../Understanding-ROS2-Services/Understanding-ROS2-Services>`.
37-
It also uses the :doc:`turtlesim package <../Introducing-Turtlesim/Introducing-Turtlesim>` and :doc:`Service Introspection Demo <../../Demos/Service-Introspection>`.
36+
This tutorial talks about concepts covered in previous tutorials, like :doc:`nodes <../Understanding-ROS2-Nodes/Understanding-ROS2-Nodes>`, :doc:`topics <../Understanding-ROS2-Topics/Understanding-ROS2-Topics>`, :doc:`services <../Understanding-ROS2-Services/Understanding-ROS2-Services>` and :doc:`actions <../Understanding-ROS2-Actions/Understanding-ROS2-Actions>`.
37+
It also uses the :doc:`turtlesim package <../Introducing-Turtlesim/Introducing-Turtlesim>`, :doc:`Service Introspection Demo <../../Demos/Service-Introspection>` and :doc:`Action Introspection Demo <../../Demos/Action-Introspection>`.
3838

3939
As always, don't forget to source ROS 2 in :doc:`every new terminal you open <../Configuring-ROS2-Environment>`.
4040

@@ -427,10 +427,223 @@ You can see the service request from the bag file and the service response from
427427
request: []
428428
response: [{sum: 5}]
429429
430+
Managing Action Data
431+
--------------------
432+
433+
1 Setup
434+
^^^^^^^
435+
436+
You'll be recording action data between ``fibonacci_action_client`` and ``fibonacci_action_server``, then display and replay that same data later on.
437+
To record action data between action client and server, ``Action Introspection`` must be enabled on the nodes.
438+
439+
Let's start ``fibonacci_action_client`` and ``fibonacci_action_server`` nodes and enable ``Action Introspection``.
440+
You can see more details for :doc:`Action Introspection Demo <../../Demos/Action-Introspection>`.
441+
442+
Open a new terminal and run ``fibonacci_action_server``, enabling ``Action Introspection``:
443+
444+
.. code-block:: bash
445+
446+
ros2 run action_tutorials_py fibonacci_action_server --ros-args -p action_server_configure_introspection:=contents
447+
448+
Open another terminal and run ``fibonacci_action_client``, enabling ``Action Introspection``:
449+
450+
.. code-block:: bash
451+
452+
ros2 run action_tutorials_cpp fibonacci_action_client --ros-args -p action_client_configure_introspection:=contents
453+
454+
2 Check action availability
455+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
456+
457+
``ros2 bag`` can only record data from available actions.
458+
To see the list of your system's actions, open a new terminal and run the command:
459+
460+
.. code-block:: console
461+
462+
$ ros2 action list
463+
/fibonacci
464+
465+
To check if ``Action Introspection`` is enabled on the action, run the command:
466+
467+
.. code-block:: console
468+
469+
$ ros2 action echo --flow-style /fibonacci
470+
interface: GOAL_SERVICE
471+
info:
472+
event_type: REQUEST_SENT
473+
stamp:
474+
sec: 1744917904
475+
nanosec: 760683446
476+
client_gid: [1, 15, 165, 231, 234, 109, 65, 202, 0, 0, 0, 0, 0, 0, 19, 4]
477+
sequence_number: 1
478+
request: [{goal_id: {uuid: [81, 55, 121, 145, 81, 66, 209, 93, 214, 113, 255, 100, 120, 6, 102, 83]}, goal: {order: 10}}]
479+
response: []
480+
---
481+
...
482+
483+
3 Record actions
484+
^^^^^^^^^^^^^^^^
485+
486+
To record action data, the following options are supported.
487+
Action data can be recorded with topics and services at the same time.
488+
489+
To record specific actions:
490+
491+
.. code-block:: bash
492+
493+
ros2 bag record --action <action_names>
494+
495+
To record all actions:
496+
497+
.. code-block:: bash
498+
499+
ros2 bag record --all-actions
500+
501+
Run the command:
502+
503+
.. code-block:: console
504+
505+
$ ros2 bag record --action /fibonacci
506+
[INFO] [1744953225.214114862] [rosbag2_recorder]: Press SPACE for pausing/resuming
507+
[INFO] [1744953225.218369761] [rosbag2_recorder]: Listening for topics...
508+
[INFO] [1744953225.218386223] [rosbag2_recorder]: Event publisher thread: Starting
509+
[INFO] [1744953225.218580294] [rosbag2_recorder]: Recording...
510+
[INFO] [1744953225.725417634] [rosbag2_recorder]: Subscribed to topic '/fibonacci/_action/cancel_goal/_service_event'
511+
[INFO] [1744953225.727901848] [rosbag2_recorder]: Subscribed to topic '/fibonacci/_action/feedback'
512+
[INFO] [1744953225.729655213] [rosbag2_recorder]: Subscribed to topic '/fibonacci/_action/get_result/_service_event'
513+
[INFO] [1744953225.731315612] [rosbag2_recorder]: Subscribed to topic '/fibonacci/_action/send_goal/_service_event'
514+
[INFO] [1744953225.735061252] [rosbag2_recorder]: Subscribed to topic '/fibonacci/_action/status'
515+
...
516+
517+
Now ``ros2 bag`` is recording the action data for the ``/fibonacci`` action: goal, result, and feedback.
518+
To stop the recording, enter ``Ctrl+C`` in the terminal.
519+
520+
The data will be accumulated in a new bag directory with a name in the pattern of ``rosbag2_year_month_day-hour_minute_second``.
521+
This directory will contain a ``metadata.yaml`` along with the bag file in the recorded format.
522+
523+
4 Inspect action data
524+
^^^^^^^^^^^^^^^^^^^^^
525+
526+
You can see details about your recording by running:
527+
528+
.. code-block:: console
529+
530+
$ ros2 bag info <bag_file_name>
531+
Files: rosbag2_2025_04_17-22_20_40_0.mcap
532+
Bag size: 20.7 KiB
533+
Storage id: mcap
534+
ROS Distro: rolling
535+
Duration: 9.019568080s
536+
Start: Apr 17 2025 22:20:47.263125070 (1744953647.263125070)
537+
End: Apr 17 2025 22:20:56.282693150 (1744953656.282693150)
538+
Messages: 0
539+
Topic information:
540+
Services: 0
541+
Service information:
542+
Actions: 1
543+
Action information:
544+
Action: /fibonacci | Type: example_interfaces/action/Fibonacci | Topics: 2 | Service: 3 | Serialization Format: cdr
545+
Topic: feedback | Count: 9
546+
Topic: status | Count: 3
547+
Service: send_goal | Event Count: 4
548+
Service: cancel_goal | Event Count: 0
549+
Service: get_result | Event Count: 4
550+
551+
5 Play action data
552+
^^^^^^^^^^^^^^^^^^
553+
554+
Before replaying the bag file, enter :kbd:`Ctrl-C` in the terminal where ``fibonacci_action_client`` is running.
555+
When ``fibonacci_action_client`` stops running, ``fibonacci_action_server`` also stops printing the result because there are no incoming requests.
556+
557+
Replaying the action data from the bag file will start sending the requests to ``fibonacci_action_server``.
558+
559+
Enter the command:
560+
561+
.. code-block:: console
562+
563+
$ ros2 bag play --send-actions-as-client <bag_file_name>
564+
[INFO] [1744953720.691068674] [rosbag2_player]: Set rate to 1
565+
[INFO] [1744953720.702365209] [rosbag2_player]: Adding keyboard callbacks.
566+
[INFO] [1744953720.702409447] [rosbag2_player]: Press SPACE for Pause/Resume
567+
[INFO] [1744953720.702423063] [rosbag2_player]: Press CURSOR_RIGHT for Play Next Message
568+
[INFO] [1744953720.702431404] [rosbag2_player]: Press CURSOR_UP for Increase Rate 10%
569+
[INFO] [1744953720.702437677] [rosbag2_player]: Press CURSOR_DOWN for Decrease Rate 10%
570+
Progress bar enabled at 3 Hz.
571+
Progress bar [?]: [R]unning, [P]aused, [B]urst, [D]elayed, [S]topped
572+
[INFO] [1744953720.702577680] [rosbag2_player]: Playback until timestamp: -1
573+
574+
575+
====== Playback Progress ======
576+
[1744953656.281683207] Duration 9.02/9.02 [R]
577+
578+
Your ``fibonacci_action_server`` terminal will once again start printing the following service messages:
579+
580+
.. code-block:: console
581+
582+
[INFO] [1744953720.815577088] [fibonacci_action_server]: Executing goal...
583+
[INFO] [1744953720.815927050] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1])
584+
[INFO] [1744953721.816509658] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2])
585+
[INFO] [1744953722.817220270] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3])
586+
[INFO] [1744953723.817876426] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3, 5])
587+
[INFO] [1744953724.818498515] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3, 5, 8])
588+
[INFO] [1744953725.819182228] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3, 5, 8, 13])
589+
[INFO] [1744953726.820032562] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3, 5, 8, 13, 21])
590+
[INFO] [1744953727.820738690] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34])
591+
[INFO] [1744953728.821449308] [fibonacci_action_server]: Feedback: array('i', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
592+
593+
This is because ``ros2 bag play`` sends the action goal request data from the bag file to the ``/fibonacci`` action.
594+
595+
We can also introspect action communication as ``ros2 bag play`` is playing it back to verify the ``fibonacci_action_server``.
596+
597+
Run this command before ``ros2 bag play`` to see the ``fibonacci_action_server``:
598+
599+
.. code-block:: bash
600+
601+
ros2 action echo --flow-style /fibonacci
602+
603+
You can see the action goal request from the bag file and the service response from ``fibonacci_action_server``.
604+
605+
.. code-block:: console
606+
607+
interface: STATUS_TOPIC
608+
status_list: [{goal_info: {goal_id: {uuid: [34, 116, 225, 217, 48, 121, 146, 36, 240, 98, 99, 134, 55, 227, 184, 72]}, stamp: {sec: 1744953720, nanosec: 804984321}}, status: 4}]
609+
---
610+
interface: GOAL_SERVICE
611+
info:
612+
event_type: REQUEST_RECEIVED
613+
stamp:
614+
sec: 1744953927
615+
nanosec: 957359210
616+
client_gid: [1, 15, 165, 231, 190, 254, 1, 50, 0, 0, 0, 0, 0, 0, 19, 4]
617+
sequence_number: 1
618+
request: [{goal_id: {uuid: [191, 200, 153, 122, 221, 251, 152, 172, 60, 69, 94, 20, 212, 160, 40, 12]}, goal: {order: 10}}]
619+
response: []
620+
---
621+
interface: GOAL_SERVICE
622+
info:
623+
event_type: RESPONSE_SENT
624+
stamp:
625+
sec: 1744953927
626+
nanosec: 957726145
627+
client_gid: [1, 15, 165, 231, 190, 254, 1, 50, 0, 0, 0, 0, 0, 0, 19, 4]
628+
sequence_number: 1
629+
request: []
630+
response: [{accepted: true, stamp: {sec: 1744953927, nanosec: 957615866}}]
631+
---
632+
interface: STATUS_TOPIC
633+
status_list: [{goal_info: {goal_id: {uuid: [191, 200, 153, 122, 221, 251, 152, 172, 60, 69, 94, 20, 212, 160, 40, 12]}, stamp: {sec: 1744953927, nanosec: 957663383}}, status: 2}]
634+
---
635+
interface: FEEDBACK_TOPIC
636+
goal_id:
637+
uuid: [191, 200, 153, 122, 221, 251, 152, 172, 60, 69, 94, 20, 212, 160, 40, 12]
638+
feedback:
639+
sequence: [0, 1, 1]
640+
---
641+
...
642+
430643
Summary
431644
-------
432645

433-
You can record data passed on topics and services in your ROS 2 system using the ``ros2 bag`` command.
646+
You can record data passed on topics, services and actions in your ROS 2 system using the ``ros2 bag`` command.
434647
Whether you're sharing your work with others or introspecting your own experiments, it's a great tool to know about.
435648

436649
Next steps
@@ -444,4 +657,5 @@ Related content
444657

445658
A more thorough explanation of ``ros2 bag`` can be found in the README `here <https://github.com/ros2/rosbag2>`__.
446659
For more information on service recording and playback can be found in the design document `here <https://github.com/ros2/rosbag2/blob/{DISTRO}/docs/design/rosbag2_record_replay_service.md>`__.
660+
For more information on action recording and playback can be found in the design document `here <https://github.com/ros2/rosbag2/blob/{DISTRO}/docs/design/rosbag2_record_replay_action.md>`__.
447661
For more information on QoS compatibility and ``ros2 bag``, see :doc:`../../../How-To-Guides/Overriding-QoS-Policies-For-Recording-And-Playback`.

0 commit comments

Comments
 (0)