I want to subscribe to a limited number of header.frame_id topics in TF.
Hello. When I subscribe to a TF topic in roscpp, I want to subscribe to only one particular header.frameid topic among several header.frameids.
How can I do this?
Thanks.
Asked by nemunatu on 2022-09-29 23:11:21 UTC
Answers
I want to subscribe to a limited number of header.frame_id topics in TF. [..] How can I do this?
You can't.
ROS 1 does not support content based subscriptions. You either subscribe to a topic, or you don't. And if you do, it's the subscribers responsibility to filter out messages it isn't interested in.
Could you describe why you'd want to do this? You could have a valid use-case, but in general it's an anti-pattern to directly subscribe to /tf
. That's the job of a tf2_ros::TransformListener
. Retrieving a single transform would then be done by interrogating the associated tf2_ros::Buffer
(using lookupTransform(..)
for instance).
PS: pedantic, but:
I want to subscribe to only one particular
header.frame_id
topic [..]
header.frame_id
is a field in the header
field of a tf2_msgs/TFMessage
message. The topics would be /tf
and /tf_static
.
Edit: from #q407180:
I asked this question [..] because the /tf topic delivers a transform for the camera position in addition to the AR marker transform, and I would like to subscribe to only one of the two topics.
To lookup a specific transform, you don't look at TFMessage
s directly. You'd use tf2_ros::Buffer::lookupTransform(..)
.
I'd recommend taking a look at the wiki/tf2/Tutorials, specifically Writing a tf2 listener (C++) (or the Python version). lookupTransform(..)
is used here (Python version).
Asked by gvdhoorn on 2022-09-30 00:43:50 UTC
Comments
So what is it you actually want to do?
Asked by gvdhoorn on 2022-09-30 03:14:11 UTC
Comments
Instead of directly subscribing to
/tf
topic, please usetf
API and lettf
do the magic!Asked by ravijoshi on 2022-09-30 01:47:04 UTC