Skip to content

Commit cb056d2

Browse files
mergify[bot]lsy3ahcorde
authored
Add XML/YAML launch file equivalents to Tf2 tutorials (backport #6031) (#6162)
* Add XML/YAML launch file equivalents to Tf2 tutorials (#6031) Signed-off-by: Luke Sy <[email protected]> (cherry picked from commit 81786ba) Signed-off-by: Alejandro Hernandez Cordero <[email protected]> Co-authored-by: lsy3 <[email protected]> Co-authored-by: Alejandro Hernandez Cordero <[email protected]>
1 parent 6276577 commit cb056d2

30 files changed

+836
-89
lines changed

source/Tutorials/Intermediate/Tf2/Adding-A-Frame-Cpp.rst

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,48 @@ Finally, add the ``install(TARGETS…)`` section so ``ros2 run`` can find your e
184184
~~~~~~~~~~~~~~~~~~~~~~~~~
185185

186186
Now let's create a launch file for this example.
187-
With your text editor, create a new file called ``turtle_tf2_fixed_frame_demo.launch.py`` in the ``src/learning_tf2_cpp/launch`` directory, and add the following lines:
187+
With your text editor, create a new file called ``turtle_tf2_fixed_frame_demo_launch`` with extension ``.py``, ``.xml``, or ``.yaml`` in the ``src/learning_tf2_cpp/launch`` directory, and add the following lines:
188188

189-
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
190-
:language: python
189+
.. tabs::
190+
191+
.. group-tab:: Python
192+
193+
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
194+
:language: python
195+
196+
.. group-tab:: XML
197+
198+
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.xml
199+
:language: xml
200+
201+
.. group-tab:: YAML
202+
203+
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.yaml
204+
:language: yaml
191205

192206
This launch file imports the required packages and then creates a ``demo_nodes`` variable that will store nodes that we created in the previous tutorial's launch file.
193207

194208
The last part of the code will add our fixed ``carrot1`` frame to the turtlesim world using our ``fixed_frame_tf2_broadcaster`` node.
195209

196-
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
197-
:language: python
198-
:lines: 14-18
210+
.. tabs::
211+
212+
.. group-tab:: Python
213+
214+
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
215+
:language: python
216+
:lines: 14-18
217+
218+
.. group-tab:: XML
219+
220+
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.xml
221+
:language: xml
222+
:lines: 3-4
223+
224+
.. group-tab:: YAML
225+
226+
.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.yaml
227+
:language: yaml
228+
:lines: 6-9
199229

200230
1.4 Build
201231
~~~~~~~~~
@@ -277,7 +307,7 @@ Now you can start the turtle broadcaster demo:
277307

278308
.. code-block:: console
279309
280-
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo.launch.py
310+
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.xml # .py or .yaml are also acceptable
281311
282312
You should notice that the new ``carrot1`` frame appeared in the transformation tree.
283313

@@ -292,7 +322,7 @@ One way is to pass the ``target_frame`` argument to the launch file directly fro
292322

293323
.. code-block:: console
294324
295-
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo.launch.py target_frame:=carrot1
325+
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.xml target_frame:=carrot1 # .py or .yaml are also acceptable
296326
297327
The second way is to update the launch file.
298328
To do so, open the ``turtle_tf2_fixed_frame_demo.launch.py`` file, and add the ``'target_frame': 'carrot1'`` parameter via ``launch_arguments`` argument.
@@ -446,10 +476,24 @@ Finally, add the ``install(TARGETS…)`` section so ``ros2 run`` can find your e
446476
2.3 Write the launch file
447477
~~~~~~~~~~~~~~~~~~~~~~~~~
448478

449-
To test this code, create a new launch file ``turtle_tf2_dynamic_frame_demo.launch.py`` in the ``src/learning_tf2_cpp/launch`` directory and paste the following code:
479+
To test this code, create a new launch file ``turtle_tf2_dynamic_frame_demo_launch`` with extension ``.py``, ``.xml``, or ``.yaml`` in the ``src/learning_tf2_cpp/launch`` directory and paste the following code:
480+
481+
.. tabs::
482+
483+
.. group-tab:: Python
484+
485+
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.py
486+
:language: python
487+
488+
.. group-tab:: XML
489+
490+
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.xml
491+
:language: xml
492+
493+
.. group-tab:: YAML
450494

451-
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.py
452-
:language: python
495+
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.yaml
496+
:language: yaml
453497

454498

455499
2.4 Build
@@ -532,7 +576,7 @@ Now you can start the dynamic frame demo:
532576

533577
.. code-block:: console
534578
535-
$ ros2 launch learning_tf2_cpp turtle_tf2_dynamic_frame_demo.launch.py
579+
$ ros2 launch learning_tf2_cpp turtle_tf2_dynamic_frame_demo_launch.xml # .py or .yaml are also acceptable
536580
537581
You should see that the second turtle is following the carrot's position that is constantly changing.
538582

source/Tutorials/Intermediate/Tf2/Adding-A-Frame-Py.rst

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,49 @@ Add the following line between the ``'console_scripts':`` brackets:
160160
~~~~~~~~~~~~~~~~~~~~~~~~~
161161

162162
Now let's create a launch file for this example.
163-
With your text editor, create a new file called ``turtle_tf2_fixed_frame_demo.launch.py`` in the ``src/learning_tf2_py/launch`` directory, and add the following lines:
163+
With your text editor, create a new file called ``turtle_tf2_fixed_frame_demo_launch`` with extension ``.py``, ``.xml``, or ``.yaml`` in the ``src/learning_tf2_py/launch`` directory, and add the following lines:
164164

165-
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
166-
:name: turtle_tf2_fixed_frame_demo_launch.py
167-
:language: python
165+
.. tabs::
166+
167+
.. group-tab:: Python
168+
169+
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
170+
:name: turtle_tf2_fixed_frame_demo_launch.py
171+
:language: python
172+
173+
.. group-tab:: XML
174+
175+
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.xml
176+
:language: xml
177+
178+
.. group-tab:: YAML
179+
180+
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.yaml
181+
:language: yaml
168182

169183
This launch file imports the required packages and then creates a ``demo_nodes`` variable that will store nodes that we created in the previous tutorial's launch file.
170184

171185
The last part of the code will add our fixed ``carrot1`` frame to the turtlesim world using our ``fixed_frame_tf2_broadcaster`` node.
172186

173-
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
174-
:language: python
175-
:lines: 14-18
187+
.. tabs::
188+
189+
.. group-tab:: Python
190+
191+
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
192+
:language: python
193+
:lines: 14-18
194+
195+
.. group-tab:: XML
196+
197+
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.xml
198+
:language: xml
199+
:lines: 3-4
200+
201+
.. group-tab:: YAML
202+
203+
.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.yaml
204+
:language: yaml
205+
:lines: 6-9
176206

177207
1.4 Build
178208
~~~~~~~~~
@@ -254,7 +284,7 @@ Now you can start the turtle broadcaster demo:
254284

255285
.. code-block:: console
256286
257-
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo.launch.py
287+
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.xml # .py or .yaml are also acceptable
258288
259289
You should notice that the new ``carrot1`` frame appeared in the transformation tree.
260290

@@ -269,7 +299,7 @@ One way is to pass the ``target_frame`` argument to the launch file directly fro
269299

270300
.. code-block:: console
271301
272-
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo.launch.py target_frame:=carrot1
302+
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.xml target_frame:=carrot1 # .py or .yaml are also acceptable
273303
274304
The second way is to update the launch file.
275305
To do so, open the ``turtle_tf2_fixed_frame_demo.launch.py`` file, and add the ``'target_frame': 'carrot1'`` parameter via ``launch_arguments`` argument.
@@ -400,10 +430,24 @@ Add the following line between the ``'console_scripts':`` brackets:
400430
2.3 Write the launch file
401431
~~~~~~~~~~~~~~~~~~~~~~~~~
402432

403-
To test this code, create a new launch file ``turtle_tf2_dynamic_frame_demo.launch.py`` in the ``src/learning_tf2_py/launch`` directory and paste the following code:
433+
To test this code, create a new launch file ``turtle_tf2_dynamic_frame_demo_launch`` with extension ``.py``, ``.xml``, or ``.yaml`` in the ``src/learning_tf2_py/launch`` directory and paste the following code:
434+
435+
.. tabs::
436+
437+
.. group-tab:: Python
438+
439+
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.py
440+
:name: turtle_tf2_dynamic_frame_demo_launch.py
441+
442+
.. group-tab:: XML
443+
444+
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.xml
445+
:language: xml
446+
447+
.. group-tab:: YAML
404448

405-
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.py
406-
:name: turtle_tf2_dynamic_frame_demo_launch.py
449+
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.yaml
450+
:language: yaml
407451

408452

409453
2.4 Build
@@ -487,7 +531,7 @@ Now you can start the dynamic frame demo:
487531

488532
.. code-block:: console
489533
490-
$ ros2 launch learning_tf2_py turtle_tf2_dynamic_frame_demo.launch.py
534+
$ ros2 launch learning_tf2_py turtle_tf2_dynamic_frame_demo_launch.xml # .py or .yaml are also acceptable
491535
492536
You should see that the second turtle is following the carrot's position that is constantly changing.
493537

source/Tutorials/Intermediate/Tf2/Debugging-Tf2-Problems.rst

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,48 @@ to
7272
} catch (tf2::TransformException & ex) {
7373

7474
And save changes to the file.
75-
In order to run this demo, we need to create a launch file ``start_tf2_debug_demo.launch.py`` in the ``launch`` subdirectory of package ``learning_tf2_cpp``:
75+
In order to run this demo, we need to create a launch file ``start_tf2_debug_demo_launch`` with extension ``.py``, ``.xml``, or ``.yaml`` in the ``launch`` subdirectory of package ``learning_tf2_cpp``:
7676

77-
.. literalinclude:: launch/start_tf2_debug_demo_launch.py
78-
:language: python
77+
.. tabs::
78+
79+
.. group-tab:: Python
80+
81+
.. literalinclude:: launch/start_tf2_debug_demo_launch.py
82+
:language: python
83+
84+
.. group-tab:: XML
85+
86+
.. literalinclude:: launch/start_tf2_debug_demo_launch.xml
87+
:language: xml
88+
89+
.. group-tab:: YAML
90+
91+
.. literalinclude:: launch/start_tf2_debug_demo_launch.yaml
92+
:language: yaml
7993

8094
Don't forget to add the ``turtle_tf2_listener_debug`` executable to the ``CMakeLists.txt`` and build the package.
8195

8296
Now let's run it to see what happens:
8397

84-
.. code-block:: console
98+
.. tabs::
99+
100+
.. group-tab:: XML
101+
102+
.. code-block:: console
85103
86-
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo.launch.py
104+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.xml
105+
106+
.. group-tab:: YAML
107+
108+
.. code-block:: console
109+
110+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.yaml
111+
112+
.. group-tab:: Python
113+
114+
.. code-block:: console
115+
116+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
87117
88118
You will now see that the turtlesim came up.
89119
At the same time, if you run the ``turtle_teleop_key`` in another terminal window, you can use the arrow keys to drive the ``turtle1`` around.
@@ -156,13 +186,37 @@ To fix this bug, just replace ``turtle3`` with ``turtle2`` in line 67.
156186

157187
And now stop the running demo, build it, and run it again:
158188

159-
.. code-block:: console
189+
.. tabs::
190+
191+
.. group-tab:: XML
160192

161-
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo.launch.py
162-
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
163-
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
164-
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
165-
transform from frame [turtle1] to frame [turtle2]
193+
.. code-block:: console
194+
195+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.xml
196+
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
197+
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
198+
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
199+
transform from frame [turtle1] to frame [turtle2]
200+
201+
.. group-tab:: YAML
202+
203+
.. code-block:: console
204+
205+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.yaml
206+
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
207+
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
208+
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
209+
transform from frame [turtle1] to frame [turtle2]
210+
211+
.. group-tab:: Python
212+
213+
.. code-block:: console
214+
215+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
216+
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
217+
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
218+
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
219+
transform from frame [turtle1] to frame [turtle2]
166220
167221
And right away we run into the next problem.
168222

@@ -205,9 +259,25 @@ In the new code we are asking for the transform between the turtles 100 millisec
205259
It is usual to use a longer periods, just to make sure that the transform will arrive.
206260
Stop the demo, build and run:
207261

208-
.. code-block:: console
262+
.. tabs::
263+
264+
.. group-tab:: XML
265+
266+
.. code-block:: console
267+
268+
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.xml
269+
270+
.. group-tab:: YAML
271+
272+
.. code-block:: console
273+
274+
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.yaml
275+
276+
.. group-tab:: Python
277+
278+
.. code-block:: console
209279
210-
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo.launch.py
280+
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.py
211281
212282
And you should finally see the turtle move!
213283

source/Tutorials/Intermediate/Tf2/Learning-About-Tf2-And-Time-Cpp.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Now try to run the launch file.
6767

6868
.. code-block:: console
6969
70-
$ ros2 launch learning_tf2_cpp turtle_tf2_demo.launch.py
70+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.xml # .py or .yaml are also acceptable
7171
[INFO] [1629873136.345688064] [listener]: Could not transform turtle2 to turtle1: Lookup would
7272
require extrapolation into the future. Requested time 1629873136.345539 but the latest data
7373
is at time 1629873136.338804, when looking up transform from frame [turtle1] to frame [turtle2]
@@ -103,9 +103,25 @@ It will block for up to that duration waiting for it to timeout.
103103

104104
You can now run the launch file.
105105

106-
.. code-block:: console
106+
.. tabs::
107+
108+
.. group-tab:: XML
109+
110+
.. code-block:: console
111+
112+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.xml
113+
114+
.. group-tab:: YAML
115+
116+
.. code-block:: console
117+
118+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.yaml
119+
120+
.. group-tab:: Python
121+
122+
.. code-block:: console
107123
108-
$ ros2 launch learning_tf2_cpp turtle_tf2_demo.launch.py
124+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.py
109125
110126
You should notice that ``lookupTransform()`` will actually block until the transform between the two turtles becomes available (this will usually take a few milliseconds).
111127
Once the timeout has been reached (fifty milliseconds in this case), an exception will be raised only if the transform is still not available.

0 commit comments

Comments
 (0)