You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/Tutorials/Intermediate/Tf2/Time-Travel-With-Tf2-Py.rst
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,14 +39,16 @@ Edit the ``lookup_transform()`` call in ``turtle_tf2_listener.py`` file to
39
39
.. code-block:: python
40
40
41
41
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:
47
49
48
50
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:
50
52
51
53
.. code-block:: console
52
54
@@ -70,13 +72,15 @@ Your code now would look like this:
70
72
.. code-block:: python
71
73
72
74
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(
74
77
target_frame=to_frame_rel,
75
78
target_time=rclpy.time.Time(),
76
79
source_frame=from_frame_rel,
77
80
source_time=when,
78
81
fixed_frame='world',
79
82
timeout=rclpy.duration.Duration(seconds=0.05))
83
+
except TransformException as ex:
80
84
81
85
The advanced API for ``lookup_transform_full()`` takes six arguments:
82
86
@@ -100,7 +104,7 @@ And at the current time, tf2 computes the transform from the ``world`` to the ``
100
104
Checking the results
101
105
--------------------
102
106
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:
0 commit comments