Skip to content

Commit

Permalink
Update to "Travel in time (Python)" after testing (ros2#3582)
Browse files Browse the repository at this point in the history
* Update code section to match state of turtle_tf2_listener.py after previous tutorials. Add hint to re-build package when needed.
  • Loading branch information
BorisBoutillier committed May 12, 2023
1 parent 0f48507 commit 36a5087
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions source/Tutorials/Intermediate/Tf2/Time-Travel-With-Tf2-Py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ Edit the ``lookup_transform()`` call in ``turtle_tf2_listener.py`` file to
.. code-block:: python
when = self.get_clock().now() - rclpy.time.Duration(seconds=5.0)
trans = self.tf_buffer.lookup_transform(
to_frame_rel,
from_frame_rel,
when,
timeout=rclpy.duration.Duration(seconds=0.05))
try:
t = self.tf_buffer.lookup_transform(
to_frame_rel,
from_frame_rel,
when,
timeout=rclpy.duration.Duration(seconds=0.05))
except TransformException as ex:
Now if you run this, during the first 5 seconds, the second turtle would not know where to go because we do not yet have a 5-second history of poses of the carrot.
But what happens after these 5 seconds? Let's just give it a try:
But what happens after these 5 seconds? Build the package as usual then let's just give it a try:

.. code-block:: console
Expand All @@ -70,13 +72,15 @@ Your code now would look like this:
.. code-block:: python
when = self.get_clock().now() - rclpy.time.Duration(seconds=5.0)
trans = self.tf_buffer.lookup_transform_full(
try:
t = self.tf_buffer.lookup_transform_full(
target_frame=to_frame_rel,
target_time=rclpy.time.Time(),
source_frame=from_frame_rel,
source_time=when,
fixed_frame='world',
timeout=rclpy.duration.Duration(seconds=0.05))
except TransformException as ex:
The advanced API for ``lookup_transform_full()`` takes six arguments:

Expand All @@ -100,7 +104,7 @@ And at the current time, tf2 computes the transform from the ``world`` to the ``
Checking the results
--------------------

Let's run the simulation again, this time with the advanced time-travel API:
Build the package as usual then let's run the simulation again, this time with the advanced time-travel API:

.. code-block:: console
Expand Down

0 comments on commit 36a5087

Please sign in to comment.