tf transform tutorial issue (past extrapolation)
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 ...
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".
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
andhostname
as generic fill-ins.If you do that please mention it so that it's clear to those of us trying to help you.
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?