Ask Your Question
0

No tf between odom and base

asked 2019-01-03 06:14:11 -0500

stevemartin gravatar image

I want to obtain the current position (odometry position) of my robot by listening to the tf between odom and the base of the robot (base_footprint). However, even though the tf exists the code cannot find any.

Here is my code:

def get_start_position():
    tf = TransformListener()
    if tf.frameExists("base_footprint") and tf.frameExists("odom"):
        print "Frames exist"
        t = tf.getLatestCommonTime("/base_link", "/map")
        p,q = tf.lookupTransform("/odom", "/base_footprint", t)
        print p
    x = 1
    y = 5.9
    z = 0
    w = 1
    return [x,y,z,w]

And here is my tf tree: image description

For some reason, the function does not return true tf values instead returns dummy values as specified above.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-03 06:46:37 -0500

This question comes up a lot. The problem comes from a misunderstanding of how the TransformListener object works, you cannot create it and then query it for transforms straight away.

The object works by listening to the TF topic, so after 100 milliseconds to a second or so it will have collected enough TF messages to be able to correctly respond to transform requests. However if you query it to early before it has had a change to receive many messages then it will not be able to find the transform you're requesting.

The correct way to use this object is to create a single TransformListener object when your node is started then use that object for the lifetime of your node. You can add a one second sleep after creating it to be on the safe side.

Hope this helps.

edit flag offensive delete link more

Comments

Thanks. Would you mind looking at this question? LINK

I do not understand why ros service causes this problem

stevemartin gravatar image stevemartin  ( 2019-01-03 07:06:29 -0500 )edit

@PeteBlackerThe3rd I actually think that initiating TF causes the problem specified in the link above. I declared the tf at the very top and the problem in the link above occurred straight away

stevemartin gravatar image stevemartin  ( 2019-01-03 07:13:33 -0500 )edit

Added a comment to my question in the link above

stevemartin gravatar image stevemartin  ( 2019-01-03 07:17:19 -0500 )edit

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: 2019-01-03 06:14:11 -0500

Seen: 413 times

Last updated: Jan 03 '19