# subscribing to tf's transformation change

Is there a way I could somehow subscribe to a transformation update? I.e. I want to write a callback function each time there is an update of transformation from source_frame to target_frame.

The only way I could think of is polling, or subscribing to /tf and filtering myself - both sounds bad to me.

edit retag close merge delete

1

To avoid an xy-problem could you perhaps add a little info on why you want to do this? There may be easier (and supported) ways to do what you actually want to do.

( 2020-01-14 05:30:13 -0600 )edit

Sort by » oldest newest most voted

With as generic of a statement of your problem you are right that there's limited solutions. However as @gvdhoorn suggests it's likely that if you more clearly define your problem there might be a better solution.

For example a common tool to use for receiving data with low latency is to use a tf2_ros::MessageFilter if you're processing data and need to wait for current information it will do all of that for you.

The only way I could think of is polling, or subscribing to /tf and filtering myself - both sounds bad to me.

This depends on what metric you want to use to define "bad" are you looking for minimum latency, minimum computational resources, minimal network resources. What are the rates of all components in your system? In most scenarios low rate polling will be by far the lowest CPU overhead, but will have higher latency.

Similarly do you really want an update every time that a transform updates? /tf topics may come in at 1000Hz. Is there not a minimum threshold for the update etc? An example of doing something like this is already implemented in the tf2_web_republisher

more

In TF "changes" are distributed by broadcasting frames, which are essentially publications on the /tf topic.

There is no update of the TF tree inbetween transforms (which I get the feeling you are somewhat expecting). Lookups for frames at timepoints which fall between two updates are interpolated (but of course: only when actually requested).

So a naive approach would indeed be to subscribe to /tf yourself and then pick out the frames you're interested in.

There is no infrastructure that could do the filtering for you available afaik, but tf/tfMessage is relatively trivial: it consists of a list of geometry_msgs/TransformStamped, which have child_frame_id and frame_id (in the header).

more

Thanks. Just making sure - tf is a pretty high rate topic, so subscribing to it directly will be quite wasteful right?

( 2020-01-14 09:58:05 -0600 )edit

It'll be no different from instantiating a tf2_ros::TransformListener.

( 2020-01-14 10:09:49 -0600 )edit

I think subscribing to the TF topic is the right answer. The Listeners are also doing that and then dumping the results into a buffer used to get transforms and interpolate. If you want to trigger something based on an update of a specific frame, this seems to be the clearest way to handle it.

( 2020-01-14 15:41:48 -0600 )edit