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

About the tf.Exception

asked 2017-05-06 09:29:06 -0500

little_bob gravatar image

I practice the tf according to tf_tutorials,but after I changed the codes liske what it said,an error happened and the process was killed.

Traceback (most recent call last):File "/home/bob/bob_catkin_practice/src/learning_tf/nodes/turtle_tf_listener.py", line 33, in <module>
"/world",rospy.Duration(2.0))tf.Exception: Lookup would require extrapolation into the past.  Requested time 1494079818.464235067 but the earliest data is at time 1494079823.260601044, when looking up transform from frame [turtle1] to frame [world][listener-6] process has died [pid 16244, exit code 1, cmd /home/bob/bob_catkin_practice/src/learning_tf/nodes/turtle_tf_listener.py __name:=listener __log:=/home/bob/.ros/log/bc22b5f4-3265-11e7-a3a0-000c2998b220/listener-6.log].log file: /home/bob/.ros/log/bc22b5f4-3265-11e7-a3a0-000c2998b220/listener-6*.log

Here is the file:

#!/usr/bin/env python
#coding:utf-8

import roslib
roslib.load_manifest('learning_tf')
import rospy
import math
import tf
import geometry_msgs.msg
import turtlesim.srv

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","/turtle1",rospy.Time(),rospy.Duration(4.0))

    while not rospy.is_shutdown():
        try:
            now=rospy.Time.now()
            past=now-rospy.Duration(5.0)
            listener.waitForTransformFull("/turtle2",now,
                                          "/turtle1",past,
                                          "/world",rospy.Duration(1.0))
            #(trans,rot)=listener.lookupTransform('/turtle2','/carrot1',now)
            (trans,rot)=listener.lookupTransformFull("/turtle2",now,
                                                     "/turtle1",past,
                                                     "/world")
        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 am not very clear about the time in tf.

edit retag flag offensive close merge delete

Comments

OS:Ubuntu 12.04 Distro:Hydro

little_bob gravatar image little_bob  ( 2017-05-06 20:14:28 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-05-09 01:24:59 -0500

little_bob gravatar image

OK,maybe this question didn't attract anyone.But i will still post my solution,whether it is correct. I add the tf.Exception to the try...exceptfunction,and it ignores the exception,program still works and it seems turtle2 follows the turtle1 as designed. Thank you.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-05-06 09:29:06 -0500

Seen: 203 times

Last updated: May 09 '17