Skip to content

Commit 68d8fe7

Browse files
Nils-ChristianIsekemergify[bot]
authored andcommitted
Add $ to Demos (#5352)
Signed-off-by: Nils-Christian Iseke <[email protected]> Signed-off-by: Nils-Christian Iseke <[email protected]> Signed-off-by: Christophe Bedard <[email protected]> Co-authored-by: Christophe Bedard <[email protected]> (cherry picked from commit 8d1b99d) # Conflicts: # source/Tutorials/Demos/Action-Introspection.rst
1 parent 98e812e commit 68d8fe7

9 files changed

+645
-243
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
Configure action introspection
2+
==============================
3+
4+
**Goal:** Configure action introspection for an action client and an action server.
5+
6+
**Tutorial level:** Advanced
7+
8+
**Time:** 15 minutes
9+
10+
.. contents:: Table of Contents
11+
:depth: 1
12+
:local:
13+
14+
Overview
15+
--------
16+
17+
ROS 2 applications usually consist of actions to execute specific long-running procedures or work in remote nodes.
18+
It is possible to introspect action data communication with action introspection.
19+
20+
ROS 2 actions are built on topics and services, so action introspection is based on :doc:`Service Introspection <Service-Introspection>`.
21+
22+
In this demo, we'll be highlighting how to configure action introspection state for an action client and an action server and monitor action communication with ``ros2 action echo``.
23+
24+
Installing the demo
25+
-------------------
26+
27+
See the :doc:`installation instructions <../../Installation>` for details on installing ROS 2.
28+
29+
If you've installed ROS 2 binary packages, ensure that you have ``ros-{DISTRO}-demo-nodes-cpp`` and ``ros-{DISTRO}-demo-nodes-py`` installed.
30+
If you downloaded the archive or built ROS 2 from source, it will already be part of the installation.
31+
32+
Introspection Configuration State
33+
---------------------------------
34+
35+
There are three configuration states for action introspection that are the same states as service introspection.
36+
37+
.. list-table:: Action Introspection Configuration State
38+
:widths: 25 25
39+
40+
* - RCL_SERVICE_INTROSPECTION_OFF
41+
- Disabled
42+
* - RCL_SERVICE_INTROSPECTION_METADATA
43+
- Only metadata without any user data contents
44+
* - RCL_SERVICE_INTROSPECTION_CONTENTS
45+
- User data contents with metadata
46+
47+
Introspection demo
48+
------------------
49+
50+
This demo shows how to manage action introspection and monitor the action data communication with using ``ros2 action echo``.
51+
52+
Action server
53+
^^^^^^^^^^^^^
54+
55+
You can find the source code here: `fibonacci_action_server.py <https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/action_tutorials/action_tutorials_py/action_tutorials_py/fibonacci_action_server.py>`__.
56+
``FibonacciActionServer`` has a parameter named ``action_server_configure_introspection`` to configure the action introspection state.
57+
58+
.. code-block:: python
59+
60+
class FibonacciActionServer(Node):
61+
...
62+
def on_post_set_parameters_callback(self, parameter_list):
63+
for param in parameter_list:
64+
if param.name != 'action_server_configure_introspection':
65+
continue
66+
67+
introspection_state = ServiceIntrospectionState.OFF
68+
if param.value == 'disabled':
69+
introspection_state = ServiceIntrospectionState.OFF
70+
elif param.value == 'metadata':
71+
introspection_state = ServiceIntrospectionState.METADATA
72+
elif param.value == 'contents':
73+
introspection_state = ServiceIntrospectionState.CONTENTS
74+
75+
self._action_server.configure_introspection(self.get_clock(),
76+
qos_profile_system_default,
77+
introspection_state)
78+
break
79+
...
80+
81+
If you want to try the C++ version, you can find the source code here: `fibonacci_action_server.cpp <https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/action_tutorials/action_tutorials_cpp/src/fibonacci_action_server.cpp>`__.
82+
83+
Action introspection is disabled by default, so users need to enable it with ``action_server_configure_introspection`` parameter when the server starts up.
84+
In this demo, ``FibonacciActionServer`` enables action introspection when the value of the ``action_server_configure_introspection`` parameter is ``contents``.
85+
86+
.. code-block:: console
87+
88+
$ ros2 run action_tutorials_py fibonacci_action_server --ros-args -p action_server_configure_introspection:=contents
89+
90+
To change action introspection state, we need to set the ``action_server_configure_introspection`` parameter as follows.
91+
92+
To change it to user data contents with metadata:
93+
94+
.. code-block:: console
95+
96+
$ ros2 param set /fibonacci_action_server action_server_configure_introspection contents
97+
98+
To change it to only metadata:
99+
100+
.. code-block:: console
101+
102+
$ ros2 param set /fibonacci_action_server action_server_configure_introspection metadata
103+
104+
To disable:
105+
106+
.. code-block:: console
107+
108+
$ ros2 param set /fibonacci_action_server action_server_configure_introspection disabled
109+
110+
Action client
111+
^^^^^^^^^^^^^
112+
113+
You can find the source code here: `fibonacci_action_client.cpp <https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/action_tutorials/action_tutorials_cpp/src/fibonacci_action_client.cpp>`__.
114+
``FibonacciActionClient`` has a parameter named ``action_client_configure_introspection`` to configure the action introspection state.
115+
116+
.. code-block:: c++
117+
118+
namespace action_tutorials_cpp
119+
{
120+
class FibonacciActionClient : public rclcpp::Node
121+
...
122+
auto post_set_parameter_callback =
123+
[this](const std::vector<rclcpp::Parameter> & parameters) {
124+
for (const rclcpp::Parameter & param : parameters) {
125+
if (param.get_name() != "action_client_configure_introspection") {
126+
continue;
127+
}
128+
129+
rcl_service_introspection_state_t introspection_state = RCL_SERVICE_INTROSPECTION_OFF;
130+
131+
if (param.as_string() == "disabled") {
132+
introspection_state = RCL_SERVICE_INTROSPECTION_OFF;
133+
} else if (param.as_string() == "metadata") {
134+
introspection_state = RCL_SERVICE_INTROSPECTION_METADATA;
135+
} else if (param.as_string() == "contents") {
136+
introspection_state = RCL_SERVICE_INTROSPECTION_CONTENTS;
137+
}
138+
139+
this->client_ptr_->configure_introspection(
140+
this->get_clock(), rclcpp::SystemDefaultsQoS(), introspection_state);
141+
break;
142+
}
143+
};
144+
...
145+
146+
If you want to try the Python version, you can find the source code here: `fibonacci_action_client.py <https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/action_tutorials/action_tutorials_py/action_tutorials_py/fibonacci_action_client.py>`__.
147+
148+
And then, we start and configure ``FibonacciActionClient`` in the same way.
149+
150+
.. code-block:: console
151+
152+
$ ros2 run action_tutorials_cpp fibonacci_action_client --ros-args -p action_client_configure_introspection:=contents
153+
154+
To change action introspection state, we need to set the ``action_client_configure_introspection`` parameter as follows.
155+
Note that ``FibonacciActionClient`` only runs in short time, so it is recommended to set the parameter before running the client as above.
156+
157+
To change it to user data contents with metadata:
158+
159+
.. code-block:: console
160+
161+
$ ros2 param set /fibonacci_action_client action_client_configure_introspection contents
162+
163+
To change it to only metadata:
164+
165+
.. code-block:: console
166+
167+
$ ros2 param set /fibonacci_action_client action_client_configure_introspection metadata
168+
169+
To disable:
170+
171+
.. code-block:: console
172+
173+
$ ros2 param set /fibonacci_action_client action_client_configure_introspection disabled
174+
175+
Introspect
176+
^^^^^^^^^^
177+
178+
In this tutorial, the following is an example output with action introspection state ``contents`` on both ``FibonacciActionServer`` and ``FibonacciActionClient``.
179+
To monitor action communication between ``FibonacciActionServer`` and ``FibonacciActionClient``, let's run it:
180+
181+
.. code-block:: console
182+
183+
$ ros2 action echo /fibonacci example_interfaces/action/Fibonacci --flow-style
184+
interface: GOAL_SERVICE
185+
info:
186+
event_type: REQUEST_SENT
187+
stamp:
188+
sec: 1742070798
189+
nanosec: 400435819
190+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 20, 4]
191+
sequence_number: 1
192+
request: [{goal_id: {uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]}, goal: {order: 10}}]
193+
response: []
194+
---
195+
interface: GOAL_SERVICE
196+
info:
197+
event_type: REQUEST_RECEIVED
198+
stamp:
199+
sec: 1742070798
200+
nanosec: 400706446
201+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 20, 4]
202+
sequence_number: 1
203+
request: [{goal_id: {uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]}, goal: {order: 10}}]
204+
response: []
205+
---
206+
interface: RESULT_SERVICE
207+
info:
208+
event_type: REQUEST_SENT
209+
stamp:
210+
sec: 1742070798
211+
nanosec: 401486678
212+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 24, 4]
213+
sequence_number: 1
214+
request: [{goal_id: {uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]}}]
215+
response: []
216+
---
217+
interface: FEEDBACK_TOPIC
218+
goal_id:
219+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
220+
feedback:
221+
sequence: [0, 1, 1]
222+
---
223+
interface: STATUS_TOPIC
224+
status_list: [{goal_info: {goal_id: {uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]}, stamp: {sec: 1742070798, nanosec: 401146752}}, status: 2}]
225+
---
226+
interface: GOAL_SERVICE
227+
info:
228+
event_type: RESPONSE_SENT
229+
stamp:
230+
sec: 1742070798
231+
nanosec: 401109161
232+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 20, 4]
233+
sequence_number: 1
234+
request: []
235+
response: [{accepted: true, stamp: {sec: 0, nanosec: 0}}]
236+
---
237+
interface: RESULT_SERVICE
238+
info:
239+
event_type: REQUEST_RECEIVED
240+
stamp:
241+
sec: 1742070798
242+
nanosec: 401579875
243+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 24, 4]
244+
sequence_number: 1
245+
request: [{goal_id: {uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]}}]
246+
response: []
247+
---
248+
interface: GOAL_SERVICE
249+
info:
250+
event_type: RESPONSE_RECEIVED
251+
stamp:
252+
sec: 1742070798
253+
nanosec: 401234269
254+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 20, 4]
255+
sequence_number: 1
256+
request: []
257+
response: [{accepted: true, stamp: {sec: 0, nanosec: 0}}]
258+
---
259+
interface: FEEDBACK_TOPIC
260+
goal_id:
261+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
262+
feedback:
263+
sequence: [0, 1, 1, 2]
264+
---
265+
interface: FEEDBACK_TOPIC
266+
goal_id:
267+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
268+
feedback:
269+
sequence: [0, 1, 1, 2, 3]
270+
---
271+
interface: FEEDBACK_TOPIC
272+
goal_id:
273+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
274+
feedback:
275+
sequence: [0, 1, 1, 2, 3, 5]
276+
---
277+
interface: FEEDBACK_TOPIC
278+
goal_id:
279+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
280+
feedback:
281+
sequence: [0, 1, 1, 2, 3, 5, 8]
282+
---
283+
interface: FEEDBACK_TOPIC
284+
goal_id:
285+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
286+
feedback:
287+
sequence: [0, 1, 1, 2, 3, 5, 8, 13]
288+
---
289+
interface: FEEDBACK_TOPIC
290+
goal_id:
291+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
292+
feedback:
293+
sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21]
294+
---
295+
interface: FEEDBACK_TOPIC
296+
goal_id:
297+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
298+
feedback:
299+
sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
300+
---
301+
interface: FEEDBACK_TOPIC
302+
goal_id:
303+
uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]
304+
feedback:
305+
sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
306+
---
307+
interface: RESULT_SERVICE
308+
info:
309+
event_type: RESPONSE_SENT
310+
stamp:
311+
sec: 1742070807
312+
nanosec: 402339670
313+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 24, 4]
314+
sequence_number: 1
315+
request: []
316+
response: [{status: 4, result: {sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]}}]
317+
---
318+
interface: RESULT_SERVICE
319+
info:
320+
event_type: RESPONSE_RECEIVED
321+
stamp:
322+
sec: 1742070807
323+
nanosec: 402698784
324+
client_gid: [1, 15, 165, 231, 194, 197, 167, 157, 0, 0, 0, 0, 0, 0, 24, 4]
325+
sequence_number: 1
326+
request: []
327+
response: [{status: 4, result: {sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]}}]
328+
---
329+
interface: STATUS_TOPIC
330+
status_list: [{goal_info: {goal_id: {uuid: [230, 96, 12, 6, 100, 69, 69, 70, 220, 205, 135, 251, 210, 2, 231, 110]}, stamp: {sec: 1742070798, nanosec: 401146752}}, status: 4}]
331+
---
332+
...
333+
334+
You can see the ``interface: GOAL_SERVICE`` and ``interface: RESULT_SERVICE``, those introspection service events take place in both ``FibonacciActionServer`` and ``FibonacciActionClient``.
335+
And you can also see ``interface: FEEDBACK_TOPIC`` and ``interface: STATUS_TOPIC`` data, those topics are published by ``FibonacciActionServer`` and subscribed by ``FibonacciActionClient``.
336+
337+
Now you can see the action communication between ``FibonacciActionServer`` and ``FibonacciActionClient`` with ``ros2 action echo``.
338+
339+
Related content
340+
---------------
341+
342+
- `Action Introspection REP-2018 <https://github.com/ros-infrastructure/rep/pull/405>`__.

source/Tutorials/Demos/Content-Filtering-Subscription.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ The ``ContentFilteringPublisher`` node publishes simulated temperature data star
132132

133133
We can run the demo by running the ``ros2 run demo_nodes_cpp content_filtering_publisher`` executable (don't forget to source the setup file first):
134134

135-
.. code-block:: bash
135+
.. code-block:: console
136136
137137
$ ros2 run demo_nodes_cpp content_filtering_publisher
138138
[INFO] [1651094594.822753479] [content_filtering_publisher]: Publishing: '-100.000000'
@@ -248,7 +248,7 @@ Applications can use the ``is_cft_enabled`` method to check if content filtering
248248

249249
To test content filtering subscription, let's run it:
250250

251-
.. code-block:: bash
251+
.. code-block:: console
252252
253253
$ ros2 run demo_nodes_cpp content_filtering_subscriber
254254
[INFO] [1651094590.682660703] [content_filtering_subscriber]: subscribed to topic "/temperature" with content filter options "data < %0 OR data > %1, {-30.000000, 100.000000}"
@@ -277,7 +277,7 @@ You should see a message showing the content filtering options used and logs for
277277
If content filtering is not supported by the RMW implementation, the subscription will still be created without content filtering enabled.
278278
We can try that by executing ``RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ros2 run demo_nodes_cpp content_filtering_publisher``.
279279

280-
.. code-block:: bash
280+
.. code-block:: console
281281
282282
$ RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ros2 run demo_nodes_cpp content_filtering_subscriber
283283
[WARN] [1651096637.893842072] [content_filtering_subscriber]: Content filter is not enabled since it is not supported

0 commit comments

Comments
 (0)