Skip to content

Commit 2374cf0

Browse files
mergify[bot]lsy3
andauthored
Add XML/YAML launch file equivalents to Tf2 tutorials (#6031) (#6161)
(cherry picked from commit 81786ba) Signed-off-by: Luke Sy <[email protected]> Co-authored-by: lsy3 <[email protected]>
1 parent b173a6b commit 2374cf0

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
@@ -182,18 +182,48 @@ Finally, add the ``install(TARGETS…)`` section so ``ros2 run`` can find your e
182182
~~~~~~~~~~~~~~~~~~~~~~~~~
183183

184184
Now let's create a launch file for this example.
185-
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:
185+
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:
186186

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

190204
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.
191205

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

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

198228
1.4 Build
199229
~~~~~~~~~
@@ -275,7 +305,7 @@ Now you can start the turtle broadcaster demo:
275305

276306
.. code-block:: console
277307
278-
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.py
308+
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.xml # .py or .yaml are also acceptable
279309
280310
You should notice that the new ``carrot1`` frame appeared in the transformation tree.
281311

@@ -290,7 +320,7 @@ One way is to pass the ``target_frame`` argument to the launch file directly fro
290320

291321
.. code-block:: console
292322
293-
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.py target_frame:=carrot1
323+
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.xml target_frame:=carrot1 # .py or .yaml are also acceptable
294324
295325
The second way is to update the launch file.
296326
To do so, open the ``turtle_tf2_fixed_frame_demo_launch.py`` file, and add the ``'target_frame': 'carrot1'`` parameter via ``launch_arguments`` argument.
@@ -442,10 +472,24 @@ Finally, add the ``install(TARGETS…)`` section so ``ros2 run`` can find your e
442472
2.3 Write the launch file
443473
~~~~~~~~~~~~~~~~~~~~~~~~~
444474

445-
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:
475+
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:
476+
477+
.. tabs::
478+
479+
.. group-tab:: Python
480+
481+
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.py
482+
:language: python
483+
484+
.. group-tab:: XML
485+
486+
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.xml
487+
:language: xml
488+
489+
.. group-tab:: YAML
446490

447-
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.py
448-
:language: python
491+
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.yaml
492+
:language: yaml
449493

450494

451495
2.4 Build
@@ -528,7 +572,7 @@ Now you can start the dynamic frame demo:
528572

529573
.. code-block:: console
530574
531-
$ ros2 launch learning_tf2_cpp turtle_tf2_dynamic_frame_demo_launch.py
575+
$ ros2 launch learning_tf2_cpp turtle_tf2_dynamic_frame_demo_launch.xml # .py or .yaml are also acceptable
532576
533577
You should see that the second turtle is following the carrot's position that is constantly changing.
534578

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

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

161161
Now let's create a launch file for this example.
162-
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:
162+
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:
163163

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

168182
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.
169183

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

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

176206
1.4 Build
177207
~~~~~~~~~
@@ -253,7 +283,7 @@ Now you can start the turtle broadcaster demo:
253283

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

@@ -268,7 +298,7 @@ One way is to pass the ``target_frame`` argument to the launch file directly fro
268298

269299
.. code-block:: console
270300
271-
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.py target_frame:=carrot1
301+
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.xml target_frame:=carrot1 # .py or .yaml are also acceptable
272302
273303
The second way is to update the launch file.
274304
To do so, open the ``turtle_tf2_fixed_frame_demo_launch.py`` file, and add the ``'target_frame': 'carrot1'`` parameter via ``launch_arguments`` argument.
@@ -398,10 +428,24 @@ Add the following line between the ``'console_scripts':`` brackets:
398428
2.3 Write the launch file
399429
~~~~~~~~~~~~~~~~~~~~~~~~~
400430

401-
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:
431+
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:
432+
433+
.. tabs::
434+
435+
.. group-tab:: Python
436+
437+
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.py
438+
:name: turtle_tf2_dynamic_frame_demo_launch.py
439+
440+
.. group-tab:: XML
441+
442+
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.xml
443+
:language: xml
444+
445+
.. group-tab:: YAML
402446

403-
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.py
404-
:name: turtle_tf2_dynamic_frame_demo_launch.py
447+
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.yaml
448+
:language: yaml
405449

406450

407451
2.4 Build
@@ -485,7 +529,7 @@ Now you can start the dynamic frame demo:
485529

486530
.. code-block:: console
487531
488-
$ ros2 launch learning_tf2_py turtle_tf2_dynamic_frame_demo_launch.py
532+
$ ros2 launch learning_tf2_py turtle_tf2_dynamic_frame_demo_launch.xml # .py or .yaml are also acceptable
489533
490534
You should see that the second turtle is following the carrot's position that is constantly changing.
491535

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

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

7272
And save changes to the file.
73-
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``:
73+
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``:
7474

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

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

8094
Now let's run it to see what happens:
8195

82-
.. code-block:: console
96+
.. tabs::
97+
98+
.. group-tab:: XML
99+
100+
.. code-block:: console
83101
84-
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
102+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.xml
103+
104+
.. group-tab:: YAML
105+
106+
.. code-block:: console
107+
108+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.yaml
109+
110+
.. group-tab:: Python
111+
112+
.. code-block:: console
113+
114+
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
85115
86116
You will now see that the turtlesim came up.
87117
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.
@@ -153,13 +183,37 @@ To fix this bug, just replace ``turtle3`` with ``turtle2`` in line 65.
153183

154184
And now stop the running demo, build it, and run it again:
155185

156-
.. code-block:: console
186+
.. tabs::
187+
188+
.. group-tab:: XML
157189

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

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

204-
.. code-block:: console
258+
.. tabs::
259+
260+
.. group-tab:: XML
261+
262+
.. code-block:: console
263+
264+
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.xml
265+
266+
.. group-tab:: YAML
267+
268+
.. code-block:: console
269+
270+
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.yaml
271+
272+
.. group-tab:: Python
273+
274+
.. code-block:: console
205275
206-
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.py
276+
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.py
207277
208278
And you should finally see the turtle move!
209279

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
@@ -70,7 +70,7 @@ Now build the package and try to run the launch file.
7070

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

109109
You can now build the package and run the launch file.
110110

111-
.. code-block:: console
111+
.. tabs::
112+
113+
.. group-tab:: XML
114+
115+
.. code-block:: console
116+
117+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.xml
118+
119+
.. group-tab:: YAML
120+
121+
.. code-block:: console
122+
123+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.yaml
124+
125+
.. group-tab:: Python
126+
127+
.. code-block:: console
112128
113-
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.py
129+
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.py
114130
115131
You should notice that ``lookupTransform()`` will actually block until the transform between the two turtles becomes available (this will usually take a few milliseconds).
116132
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)