Ask Your Question
1

tf.LookupException: "base_link" passed to lookupTransform argument target_frame does not exist.

asked 2016-07-26 10:28:00 -0600

Bant gravatar image

updated 2016-07-27 04:23:58 -0600

Hello together,

I am new with ros tf's and already worked myself threw the tf tutorials. (I am using ros indigo) As my first test with tf's after the tutorial I wrote 2 small nodes.

The first one is sending a tf:

#!/usr/bin/env python

import rospy
import tf

class tf_firsttry_pub_class():
    def __init__(self):
        rospy.init_node('tf_firsttry_pub')
        now = rospy.Time.now()
        br = tf.TransformBroadcaster()
        while not rospy.is_shutdown():
            br.sendTransform((1, 1, 1), (0, 0, 0, 1), rospy.Time(), 'one','base_link')
            rospy.Rate(50)


if __name__ == '__main__':
    try:
        tf_firsttry_pub_class()
    except rospy.ROSInterruptException:
        pass

The second is listening to the tf:

#!/usr/bin/env python

import rospy
import tf

class tf_firsttry_listen_class():
    def __init__(self):
        rospy.init_node('tf_firsttry_listen')
        listener = tf.TransformListener()
        now = rospy.Time.now()
        while not rospy.is_shutdown():
            (trans,rot)=listener.lookupTransform('/base_link','/one',rospy.Time(0))
            print trans

if __name__ == '__main__':
    try:
        tf_firsttry_listen_class()
    except rospy.ROSInterruptException:
        pass

When starting the second node this error occurs:

line 11, in __init__ (trans,rot)=listener.lookupTransform('/base_link','/one',rospy.Time(0)) tf.LookupException: "base_link" passed to lookupTransform argument target_frame does not exist.

I already found in a different question that a try: except: shell around the listener could help as it may only fail at the beginning but that doesn't help.

As you see the code is easy but I am totally stuck. I think I misunderstood something but can't figure out what.

Any solutions?

Thanks in advance!

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2016-07-26 16:57:22 -0600

alexvs gravatar image

At first glance, your frames are different in the first node than the second node. 'Baselink' in the first node became '/base_link' in the second node and 'One' became '/one'. The strings identify the frames and when you lookup the transform you need to look for the frames with the same string that you publish them with.

edit flag offensive delete link more

Comments

1

Sorry about that. I got messed up with the names during testing. But even with the same names the error remains.

Bant gravatar imageBant ( 2016-07-27 04:25:45 -0600 )edit
1

Fixed. A wait for transform in the second code and a rospy.rate(150) in the first one made it working. ;)

Bant gravatar imageBant ( 2016-07-27 04:45:27 -0600 )edit
2

answered 2016-07-27 04:50:53 -0600

Bant gravatar image

updated 2016-07-27 04:51:51 -0600

Hello together,

I fixed it and now it feels way to easy. But I will leave the solution here anyway. Maybe it helps the next person starting with tf's.

The running code: first node:

#!/usr/bin/env python

import rospy
import tf

class tf_firsttry_pub_class():
    def __init__(self):
        rospy.init_node('tf_firsttry_pub')
        now = rospy.Time.now()
        br = tf.TransformBroadcaster()
        R = rospy.Rate(150)
        while not rospy.is_shutdown():
            br.sendTransform((1, 1, 1), (0, 0, 0, 1), rospy.Time(), 'One','base_link')      
            R.sleep()


if __name__ == '__main__':
    try:
        tf_firsttry_pub_class()
    except rospy.ROSInterruptException:
        pass

second node:

#!/usr/bin/env python

import rospy
import tf


class tf_firsttry_listen_class():
    def __init__(self):
        rospy.init_node('tf_firsttry_listen')
        listener = tf.TransformListener()
        now = rospy.Time.now()
        while not rospy.is_shutdown():
            listener.waitForTransform('/base_link','/One',rospy.Time(), rospy.Duration(4.0))
            (trans, rot) = listener.lookupTransform('/base_link', '/One', rospy.Time(0))
            print trans


if __name__ == '__main__':
    try:
        tf_firsttry_listen_class()
    except rospy.ROSInterruptException:
        pass

Note the R = rospy.Rate(150) and R.sleep() in the first code and the listener.waitForTransform in the second!

edit flag offensive delete link more

Comments

Thanks - far, far too many question topics end with "thanks; it's working" and no code left to help other people!

Will Chamberlain gravatar imageWill Chamberlain ( 2018-09-26 05:55:13 -0600 )edit
0

answered 2019-11-02 13:48:18 -0600

suab123 gravatar image

updated 2019-11-02 13:51:28 -0600

The reason for this error is that your listener sometimes cannot catch the transform frame which you want for transformation due to latency issue in rate with which a broadcaster is publishing.There are two solutions to this problem

1.to create a timer for your callback listener with litlle more duration as compared to what you were using before.

2.using a try-catch block

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-07-26 10:28:00 -0600

Seen: 4,727 times

Last updated: Nov 02