Learning about tf2 and time (Python)
Description: This tutorial teaches you to use the waitf2orTransform function to wait for a transform to be available on the tf2 tree.Tutorial Level: INTERMEDIATE
Next Tutorial: Time travel with tf2 (Python) (C++)
Contents
Edit nodes/turtle_tf2_listener.py and change the lookupTransform() call to:
So, all of the sudden lookupTransform() is failing, telling you:
Traceback (most recent call last):
File "~/ros/pkgs/wg-ros-pkg-trunk/sandbox/learning_tf2/nodes/turtle_tf2_listener.py", line 25, in <module>
(trans,rot) = listener.lookupTransform('/turtle2', '/carrot1', now)
tf2.ExtrapolationException: Extrapolation Too Far in the future: target_time is 1253830476.460, but the closest tf2 data is at 1253830476.435 which is 0.024 seconds away.Extrapolation Too Far in the future: target_time is 1253830476.460, but the closest tf2 data is at 1253830476.459 which is 0.001 seconds away.Extrapolation Too Far from single value: target_time is 1253830476.460, but the closest tf2 data is at 1253830476.459 which is 0.001 seconds away. See http://pr.willowgarage.com/pr-docs/ros-packages/tf2/html/faq.html for more info. When trying to transform between /carrot1 and /turtle2. See http://www.ros.org/wiki/tf2#Frequently_Asked_Questions
1 listener.waitf2orTransform("/turtle2", "/carrot1", rospy.Time(), rospy.Duration(4.0))
2 while not rospy.is_shutdown():
3 try:
4 now = rospy.Time.now()
5 listener.waitf2orTransform("/turtle2", "/carrot1", now, rospy.Duration(4.0))
6 (trans,rot) = listener.lookupTransform("/turtle2", "/carrot1", now)
The waitf2orTransform() takes four arguments:
- Wait for the transform from this frame...
- ... to this frame,
- at this time, and
- timeout: don't wait for longer than this maximum duration
So waitf2orTransform() will actually block until the transform between the two turtles becomes available (this will usually take a few milli-seconds), OR --if the transform does not become available-- until the timeout has been reached.
So why the two waitf2orTransform() calls? At the beginning of code we spawned turtle2 but tf2 may have not ever seen the /turtle2 frame before waiting for the transform. The first waitf2orTransform() will wait until the /turtle2 frame is broadcast on tf2 before trying to waitf2orTransform() at time now.






