ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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