Skip to content

Commit 36a5087

Browse files
Update to "Travel in time (Python)" after testing (ros2#3582)
* Update code section to match state of turtle_tf2_listener.py after previous tutorials. Add hint to re-build package when needed.
1 parent 0f48507 commit 36a5087

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

source/Tutorials/Intermediate/Tf2/Time-Travel-With-Tf2-Py.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ Edit the ``lookup_transform()`` call in ``turtle_tf2_listener.py`` file to
3939
.. code-block:: python
4040
4141
when = self.get_clock().now() - rclpy.time.Duration(seconds=5.0)
42-
trans = self.tf_buffer.lookup_transform(
43-
to_frame_rel,
44-
from_frame_rel,
45-
when,
46-
timeout=rclpy.duration.Duration(seconds=0.05))
42+
try:
43+
t = self.tf_buffer.lookup_transform(
44+
to_frame_rel,
45+
from_frame_rel,
46+
when,
47+
timeout=rclpy.duration.Duration(seconds=0.05))
48+
except TransformException as ex:
4749
4850
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.
49-
But what happens after these 5 seconds? Let's just give it a try:
51+
But what happens after these 5 seconds? Build the package as usual then let's just give it a try:
5052

5153
.. code-block:: console
5254
@@ -70,13 +72,15 @@ Your code now would look like this:
7072
.. code-block:: python
7173
7274
when = self.get_clock().now() - rclpy.time.Duration(seconds=5.0)
73-
trans = self.tf_buffer.lookup_transform_full(
75+
try:
76+
t = self.tf_buffer.lookup_transform_full(
7477
target_frame=to_frame_rel,
7578
target_time=rclpy.time.Time(),
7679
source_frame=from_frame_rel,
7780
source_time=when,
7881
fixed_frame='world',
7982
timeout=rclpy.duration.Duration(seconds=0.05))
83+
except TransformException as ex:
8084
8185
The advanced API for ``lookup_transform_full()`` takes six arguments:
8286

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

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

105109
.. code-block:: console
106110

0 commit comments

Comments
 (0)