Ask Your Question

subscribing to tf's transformation change

asked 2020-01-14 03:43:30 -0500

kobytg gravatar image

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 flag offensive close merge delete



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.

gvdhoorn gravatar image gvdhoorn  ( 2020-01-14 05:30:13 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2020-01-14 15:50:32 -0500

tfoote gravatar image

updated 2020-01-14 15:51:53 -0500

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

edit flag offensive delete link more

answered 2020-01-14 05:29:40 -0500

gvdhoorn gravatar image

updated 2020-01-14 10:15:08 -0500

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).

edit flag offensive delete link more


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

kobytg gravatar image kobytg  ( 2020-01-14 09:58:05 -0500 )edit

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

Could you please respond to my question about your motivation for wanting to do this?

gvdhoorn gravatar image gvdhoorn  ( 2020-01-14 10:09:49 -0500 )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.

stevemacenski gravatar image stevemacenski  ( 2020-01-14 15:41:48 -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


Asked: 2020-01-14 03:43:30 -0500

Seen: 29 times

Last updated: Jan 14