ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

tf.Exception thrown while using waitForTransform

asked 2015-04-12 09:27:56 -0500

sklaw gravatar image

updated 2015-04-21 10:44:51 -0500

Hi everyone! I am a ros beginner and I am using ros indigo and tf 1.11.6.

I am following the tf tutorials at this site Learning about tf and time (Python)

But I got an error when I changed the code to use

listener.waitForTransform("/turtle2", "/carrot1", rospy.Time(), rospy.Duration(4.0))

Here is what i got:

Traceback (most recent call last):
  File "/home/sklaw/Desktop/experiment/ros/indigo/tutorials_ws/src/learning_tf/nodes/turtle_tf_listener.py", line 18, in <module>
    listener.waitForTransform("/turtle2", "/carrot1", rospy.Time(), rospy.Duration(4.0))
tf.Exception

I tried to look up "tf.Exception" in the documentation of tf, but nothing found.

so what is wrong with that?

Any help would be great! Thanks!

here is the code of the turtle_tf_listener.py:

#!/usr/bin/env python  
import roslib
roslib.load_manifest('learning_tf')
import rospy
import math
import tf
import geometry_msgs.msg
import turtlesim.srv
import sys, traceback
if __name__ == '__main__':
    rospy.init_node('tf_turtle')
    listener = tf.TransformListener()
    rospy.wait_for_service('spawn')
    spawner = rospy.ServiceProxy('spawn', turtlesim.srv.Spawn)
    spawner(4, 2, 0, 'turtle2')
    turtle_vel = rospy.Publisher('turtle2/cmd_vel', geometry_msgs.msg.Twist,queue_size=1)
    rate = rospy.Rate(10.0)
    listener.waitForTransform("/turtle2", "/carrot1", rospy.Time(), rospy.Duration(4.0))
    while not rospy.is_shutdown():
        try:
            now = rospy.Time.now()
            listener.waitForTransform("/turtle2", "/carrot1", now, rospy.Duration(4.0))
            (trans,rot) = listener.lookupTransform("/turtle2", "/carrot1", now)
        except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
            continue    
        angular = 4 * math.atan2(trans[1], trans[0])
        linear = 0.5 * math.sqrt(trans[0] ** 2 + trans[1] ** 2)
        cmd = geometry_msgs.msg.Twist()
        cmd.linear.x = linear
        cmd.angular.z = angular
        turtle_vel.publish(cmd)
        rate.sleep()

Update 1: 6:29 AM Tuesday, April 21, 2015 Greenwich Mean Time (GMT)

I used tf 1.11.4 to see if this is related to some bugs of tf 1.11.6, but the same error still exists.(my classmates use tf 1.11.4 and they don't have the problem.)

And then I found this page: tf wait for transform failure

Taking the advice from the answer, I added "import time" to the import list, and put a "time.sleep(5)" just before the first waitForTransform.

Though the program is still not working, this time the error is not at the first waitForTransform. It's at the second one, with more details compared with before:

Traceback (most recent call last):
  File "/home/sklaw/Desktop/experiment/ros/indigo/tutorials_ws/src/learning_tf/nodes/turtle_tf_listener.py", line 30, in <module>
    listener.waitForTransform("/turtle2", "/carrot1", now, rospy.Duration(4.0))
tf.Exception: Lookup would require extrapolation into the future.  Requested time 1429597531.491660118 but the latest data is at time 1429597531.490922928, when looking up transform from frame [carrot1] to frame [turtle2]

It seems that the waitForTransfrom never waits. So when I added a "sleep(5)" before the first waitForTransfrom, it can survive at runtime because I "manually" make a "wait" happened for the first waitForTransfrom.

Update 2: 2:46 PM Tuesday, April 21, 2015 Greenwich Mean Time (GMT)

This ... (more)

edit retag flag offensive close merge delete

Comments

Hi, I am also working though the TF tutorials (indigo). I have found the same tf.Exception on the waitForTransform(). I am also struggling to debug this and work out what is going on. I have followed the TF debugging tutorial but I am still stuck. Any help on this would be appreciated. Paul

amp gravatar image amp  ( 2015-04-17 11:35:53 -0500 )edit

Some of my classmates have no problem in following the tf tutorial. And they're using tf 1.11.4 while I'm using tf 1.11.6. But after I removed the current tf, downloaded version 1.11.4 from github and catkin_make it in my own workspace, the problem still existed. So I think tf is not the cause

sklaw gravatar image sklaw  ( 2015-04-21 01:17:15 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-04-21 03:22:46 -0500

marcoesposito1988 gravatar image

updated 2015-04-21 03:45:15 -0500

Hi, I also just got this error with code that used to work until the end of March.

If your case is really the same as mine, even if you use Time.now() as parameter for the first waitForTransform this will succede but then lookupTransform will throw an 'Extrapolation into the future' exception. Could you please check?

UPDATE:

I think I have found the problem. This happens if one of the frames doesn't exist yet in the TF database. I already opened an issue and I will forward this information to the TF people.

UPDATE 2:

The bug must be in TF2 (TF is now implemented as a shim layer over TF2). @sklaw, you were on the right path: you should check out both geometry on the tag 1.11.4 and geometry-experimental 0.5.7. This should give you a working configuration.

edit flag offensive delete link more

Comments

I used "rospy.Time.now()" to replace the "rospy.Time()" in the first waitForTransform, but it still reproted the same error at the first waitForTransfrom. Maybe we are not in the same trouble. Thanks anyway...

sklaw gravatar image sklaw  ( 2015-04-21 01:10:53 -0500 )edit

Yes, it works!

tf 1.11.4 and tf2 0.5.7 is the working combination that my classmates are using.

And thank you for the generous help and posting the issue to github for more help!!

sklaw gravatar image sklaw  ( 2015-04-21 09:43:21 -0500 )edit
0

answered 2015-04-21 09:33:52 -0500

sklaw gravatar image

updated 2015-04-21 09:37:18 -0500

OMG!!! I solve it!!!

When I used tf 1.11.6 and tf2 0.5.9, the problem showed up.

And I am using tf 1.11.4 and tf2 0.5.7 now, and amazingly, the problem is gone!!!

I think maybe this is caused by some compatibility issue between tf and tf2.

Thanks for everyone's help!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-12 09:27:56 -0500

Seen: 2,719 times

Last updated: Apr 21 '15