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

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

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

Bant gravatar image

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

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
4

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

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 image Bant  ( 2016-07-27 04:25:45 -0500 )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 image Bant  ( 2016-07-27 04:45:27 -0500 )edit
6

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

Bant gravatar image

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

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

1

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

Will Chamberlain gravatar image Will Chamberlain  ( 2018-09-26 05:55:13 -0500 )edit

THANK YOU VERY MUCH!! SOLVED MY ISSUE!

RicoJ gravatar image RicoJ  ( 2019-12-27 22:01:33 -0500 )edit
1

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

suab123 gravatar image

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

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

Question Tools

2 followers

Stats

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

Seen: 14,526 times

Last updated: Nov 02 '19