# Calculating velocity from tf

When listening to transforms on tf, is there a way to ask specifically for the one before the latest one? And when you have received a transform, how do you query it for its timestamp?

I have position information being intermittently broadcast onto tf. Because I don't know exactly when this is going to happen I can't ask for a transform with a specific time delay. I would like to ask for the latest two transforms, find the time delay between them and divide by this to give an estimate of velocity.

Any help would be much appreciated!

James

edit retag close merge delete

Sort by ยป oldest newest most voted

As @dlaz mentioned you want to use Transformer::lookupTwist()

If you use a target_time of zero it will give you the latest reading. And if you set a very small averaging_interval to a very small value(less than the minimum time between your tf updates) it will effectively do what you want. This will cause the target time to be the last update. And it will use linear interpolation between the last two updates to compute the other endpoint of the interval.

Note: This will be very noisy data! You are doing discreet differentiation over small time samples, the result will be very biased by noise in the tf positions.

more

The standard way to get velocities from TF is with Transformer::lookupTwist(), which will return velocity as a geometry_msgs/Twist. I'm not sure how that will work with your intermittent TF broadcasting though.

more

@tfoote So this is a bit older, but I'm running into an Issue with TF2 in that I can't find a substitute function for TFs lookupTwist. Was this dropped from TF2? if so, Oops. It's really useful.

Any tips on how to calculate it myself? I've create a related question here.

more

1

( 2018-02-12 17:49:33 -0600 )edit

^ I edited to link to the related question

( 2018-02-12 17:53:04 -0600 )edit
1

( 2018-02-12 18:22:37 -0600 )edit