Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions source/Tutorials/Intermediate/Tf2/Adding-A-Frame-Cpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,48 @@ Finally, add the ``install(TARGETS…)`` section so ``ros2 run`` can find your e
~~~~~~~~~~~~~~~~~~~~~~~~~

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

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
:language: python
.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
:language: python

.. group-tab:: XML

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.xml
:language: xml

.. group-tab:: YAML

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.yaml
:language: yaml

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.

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

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
:language: python
:lines: 14-18
.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.py
:language: python
:lines: 14-18

.. group-tab:: XML

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.xml
:language: xml
:lines: 3-4

.. group-tab:: YAML

.. literalinclude:: launch/turtle_tf2_fixed_frame_demo_launch.yaml
:language: yaml
:lines: 6-9

1.4 Build
~~~~~~~~~
Expand Down Expand Up @@ -275,7 +305,7 @@ Now you can start the turtle broadcaster demo:

.. code-block:: console

$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.py
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.xml # .py or .yaml are also acceptable

You should notice that the new ``carrot1`` frame appeared in the transformation tree.

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

.. code-block:: console

$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.py target_frame:=carrot1
$ ros2 launch learning_tf2_cpp turtle_tf2_fixed_frame_demo_launch.xml target_frame:=carrot1 # .py or .yaml are also acceptable

The second way is to update the launch file.
To do so, open the ``turtle_tf2_fixed_frame_demo_launch.py`` file, and add the ``'target_frame': 'carrot1'`` parameter via ``launch_arguments`` argument.
Expand Down Expand Up @@ -442,10 +472,24 @@ Finally, add the ``install(TARGETS…)`` section so ``ros2 run`` can find your e
2.3 Write the launch file
~~~~~~~~~~~~~~~~~~~~~~~~~

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:
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:

.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.py
:language: python

.. group-tab:: XML

.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.xml
:language: xml

.. group-tab:: YAML

.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.py
:language: python
.. literalinclude:: launch/turtle_tf2_dynamic_frame_demo_launch.yaml
:language: yaml


2.4 Build
Expand Down Expand Up @@ -528,7 +572,7 @@ Now you can start the dynamic frame demo:

.. code-block:: console

$ ros2 launch learning_tf2_cpp turtle_tf2_dynamic_frame_demo_launch.py
$ ros2 launch learning_tf2_cpp turtle_tf2_dynamic_frame_demo_launch.xml # .py or .yaml are also acceptable

You should see that the second turtle is following the carrot's position that is constantly changing.

Expand Down
70 changes: 57 additions & 13 deletions source/Tutorials/Intermediate/Tf2/Adding-A-Frame-Py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,49 @@ Add the following line between the ``'console_scripts':`` brackets:
~~~~~~~~~~~~~~~~~~~~~~~~~

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

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
:name: turtle_tf2_fixed_frame_demo_launch.py
:language: python
.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
:name: turtle_tf2_fixed_frame_demo_launch.py
:language: python

.. group-tab:: XML

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.xml
:language: xml

.. group-tab:: YAML

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.yaml
:language: yaml

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.

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

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
:language: python
:lines: 14-18
.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.py
:language: python
:lines: 14-18

.. group-tab:: XML

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.xml
:language: xml
:lines: 3-4

.. group-tab:: YAML

.. literalinclude:: launch/py_turtle_tf2_fixed_frame_demo_launch.yaml
:language: yaml
:lines: 6-9

1.4 Build
~~~~~~~~~
Expand Down Expand Up @@ -253,7 +283,7 @@ Now you can start the turtle broadcaster demo:

.. code-block:: console

$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.py
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.xml # .py or .yaml are also acceptable

You should notice that the new ``carrot1`` frame appeared in the transformation tree.

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

.. code-block:: console

$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.py target_frame:=carrot1
$ ros2 launch learning_tf2_py turtle_tf2_fixed_frame_demo_launch.xml target_frame:=carrot1 # .py or .yaml are also acceptable

The second way is to update the launch file.
To do so, open the ``turtle_tf2_fixed_frame_demo_launch.py`` file, and add the ``'target_frame': 'carrot1'`` parameter via ``launch_arguments`` argument.
Expand Down Expand Up @@ -398,10 +428,24 @@ Add the following line between the ``'console_scripts':`` brackets:
2.3 Write the launch file
~~~~~~~~~~~~~~~~~~~~~~~~~

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:
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:

.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.py
:name: turtle_tf2_dynamic_frame_demo_launch.py

.. group-tab:: XML

.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.xml
:language: xml

.. group-tab:: YAML

.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.py
:name: turtle_tf2_dynamic_frame_demo_launch.py
.. literalinclude:: launch/py_turtle_tf2_dynamic_frame_demo_launch.yaml
:language: yaml


2.4 Build
Expand Down Expand Up @@ -485,7 +529,7 @@ Now you can start the dynamic frame demo:

.. code-block:: console

$ ros2 launch learning_tf2_py turtle_tf2_dynamic_frame_demo_launch.py
$ ros2 launch learning_tf2_py turtle_tf2_dynamic_frame_demo_launch.xml # .py or .yaml are also acceptable

You should see that the second turtle is following the carrot's position that is constantly changing.

Expand Down
96 changes: 83 additions & 13 deletions source/Tutorials/Intermediate/Tf2/Debugging-Tf2-Problems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,48 @@ to
} catch (const tf2::TransformException & ex) {

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

.. literalinclude:: launch/start_tf2_debug_demo_launch.py
:language: python
.. tabs::

.. group-tab:: Python

.. literalinclude:: launch/start_tf2_debug_demo_launch.py
:language: python

.. group-tab:: XML

.. literalinclude:: launch/start_tf2_debug_demo_launch.xml
:language: xml

.. group-tab:: YAML

.. literalinclude:: launch/start_tf2_debug_demo_launch.yaml
:language: yaml

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

Now let's run it to see what happens:

.. code-block:: console
.. tabs::

.. group-tab:: XML

.. code-block:: console

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.xml

.. group-tab:: YAML

.. code-block:: console

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.yaml

.. group-tab:: Python

.. code-block:: console

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py

You will now see that the turtlesim came up.
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.
Expand Down Expand Up @@ -153,13 +183,37 @@ To fix this bug, just replace ``turtle3`` with ``turtle2`` in line 65.

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

.. code-block:: console
.. tabs::

.. group-tab:: XML

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
transform from frame [turtle1] to frame [turtle2]
.. code-block:: console

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.xml
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
transform from frame [turtle1] to frame [turtle2]

.. group-tab:: YAML

.. code-block:: console

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.yaml
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
transform from frame [turtle1] to frame [turtle2]

.. group-tab:: Python

.. code-block:: console

$ ros2 launch learning_tf2_cpp start_tf2_debug_demo_launch.py
[turtle_tf2_listener_debug-4] [INFO] [1630223704.617382464] [listener_debug]: Could not
transform turtle2 to turtle1: Lookup would require extrapolation into the future. Requested
time 1630223704.617054 but the latest data is at time 1630223704.616726, when looking up
transform from frame [turtle1] to frame [turtle2]

And right away we run into the next problem.

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

.. code-block:: console
.. tabs::

.. group-tab:: XML

.. code-block:: console

$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.xml

.. group-tab:: YAML

.. code-block:: console

$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.yaml

.. group-tab:: Python

.. code-block:: console

$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.py
$ ros2 launch turtle_tf2 start_tf2_debug_demo_launch.py

And you should finally see the turtle move!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Now build the package and try to run the launch file.

.. code-block:: console

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

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

.. code-block:: console
.. tabs::

.. group-tab:: XML

.. code-block:: console

$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.xml

.. group-tab:: YAML

.. code-block:: console

$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.yaml

.. group-tab:: Python

.. code-block:: console

$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.py
$ ros2 launch learning_tf2_cpp turtle_tf2_demo_launch.py

You should notice that ``lookupTransform()`` will actually block until the transform between the two turtles becomes available (this will usually take a few milliseconds).
Once the timeout has been reached (fifty milliseconds in this case), an exception will be raised only if the transform is still not available.
Expand Down
Loading