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

tf transform tutorial issue (past extrapolation)

asked 2017-06-30 16:54:15 -0500

jwhendy gravatar image

updated 2017-07-03 13:51:23 -0500

I'm working through the python tf tutorial and am having an issue with an extrapolation into the past. Here's the section:

So let's go back to where we ended in the previous tutorial. Go to your package for the tutorial:

$ roscd learning_tf

Now, instead of making the second turtle go to where the first turtle is now, make the second turtle go to where the first turtle was 5 seconds ago. Edit nodes/turtle_tf_listener.py:

try:
    now = rospy.Time.now() - rospy.Duration(5.0)
    listener.waitForTransform("/turtle2", "/carrot1", now, rospy.Duration(1.0))
    (trans, rot) = listener.lookupTransform("/turtle2", "/carrot1", now)

except (tf.Exception, tf.LookupException, tf.ConnectivityException):

The referenced "previous tutorial" taught about waitForTransform() and fixed a future extrapolation like so:

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)

Based on that (which worked) and the changes shown above, here is my full code:

#!/usr/bin/env python

import rospy
import tf
import turtlesim.srv
import geometry_msgs.msg
import math

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)

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

    while not rospy.is_shutdown():
        try:
            now = rospy.Time.now() - rospy.Duration(5.0)
            listener.waitForTransform('/turtle2', '/carrot1', now, rospy.Duration(1.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()

I'm getting these types of errors about past extrapolation when I run the above:

listener.waitForTransform('/turtle2', '/carrot1', now, rospy.Duration(1.0))
tf.Exception: Lookup would require extrapolation into the past.  Requested time 1498858934.730669022 but the earliest data is at time 1498858934.911530972, when looking up transform from frame [carrot1] to frame [turtle2]. canTransform returned after 1.00266 timeout was 1.

I've tried inserting a rospy.sleep(5) above the while section to ensure that there's 5 seconds of data, as well as having the first call to waitForTransform use rospy.Time.now() - rospy.Duration(5.0) to match the second argument. I'm not really sure what's going on. The tutorial goes on to suggest this is not really what you want anyway, but it still shows it like it should run so I'm confused at my results!


EDIT: I've left the original question as-is, but wanted to respond to the comments by making this more reproducible. I started over from the beginning, creating versions of each file as I went. These are now on github. If you want ... (more)

edit retag flag offensive close merge delete

Comments

Re your edit about log files: If you're having errors with urls like "http://hostname:38196/" you need to double check your network setup. You should see valid hostnames there not the string "hostname".

tfoote gravatar image tfoote  ( 2017-07-03 13:59:53 -0500 )edit

That was intentional. I'm not network savvy and am not sure what constitutes something I don't want floating around on the internet. I used username and hostname as generic fill-ins.

jwhendy gravatar image jwhendy  ( 2017-07-03 14:13:20 -0500 )edit

If you do that please mention it so that it's clear to those of us trying to help you.

tfoote gravatar image tfoote  ( 2017-07-03 15:00:10 -0500 )edit

Will do. I thought cloning/reproducing was the best way to just get to whether this is an issue or not... can you reproduce the error, or does it work for you?

jwhendy gravatar image jwhendy  ( 2017-07-03 15:03:06 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-06-30 17:10:32 -0500

tfoote gravatar image

It looks like you're off by 2 tenths of a second still. Waiting will almost never resolve an extrapolation into the past.

My guess is that you'll get that error for a little bit, and then it will go away as time moves forward and the cache extends beyond 5 seconds into the past.

Your posted code isn't printing the exceptions so I'm guessing there are other local changes besides the sleep.

edit flag offensive delete link more

Comments

Sorry; should have posted the full error. turtle_tf_listener dies after the above. Full error is here. I'm not sure what exceptions I should see instead. Also, I pushed this all to github if you want to replicate. You can check for 'local changes' this way, too.

jwhendy gravatar image jwhendy  ( 2017-07-03 13:31:42 -0500 )edit
0

answered 2018-05-22 23:42:21 -0500

kiranpalla gravatar image

I see the same behavior/issues while doing tf tutorials today. Is there a fix?

In Time travel with tf tutorial there are two issues -

First, I don't see uncontrolled behavior of turtle2.

Second, I get an exception with advanced APIs (tf2.TransformException: Lookup would require extrapolation into the past).

edit flag offensive delete link more

Comments

I just tried this today. Adding the following two lines above the while loop worked for me. listener.waitForTransformFull("/turtle2",rospy.Time(),"/turtle1",rospy.Time(),"/world",rospy.Duration(5.0)) rospy.sleep(5.0)

musaup gravatar image musaup  ( 2019-03-19 09:06:09 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-30 16:54:15 -0500

Seen: 1,152 times

Last updated: May 22 '18