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 sourceframe to targetframe.
The only way I could think of is polling, or subscribing to /tf and filtering myself - both sounds bad to me.
Asked by kobytg on 2020-01-14 04:43:30 UTC
Answers
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
).
Asked by gvdhoorn on 2020-01-14 06:29:40 UTC
Comments
Thanks. Just making sure - tf is a pretty high rate topic, so subscribing to it directly will be quite wasteful right?
Asked by kobytg on 2020-01-14 10:58:05 UTC
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?
Asked by gvdhoorn on 2020-01-14 11:09:49 UTC
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.
Asked by stevemacenski on 2020-01-14 16:41:48 UTC
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
Asked by tfoote on 2020-01-14 16:50:32 UTC
Comments
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.
Asked by gvdhoorn on 2020-01-14 06:30:13 UTC