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

How to prevent the second publisher to publish on the same topic?

asked 2021-02-11 09:13:26 -0600

ali ekber celik gravatar image

updated 2021-02-12 02:04:30 -0600

Hello everyone,

I am working with ROS2 in my project and I know ROS/ROS2 is capable to handle multiple publishers and subscribers on the same topic. Due to some limitations in my project, I would like to prevent the second publisher to publish on the same topic. It needs to be kind of one publisher for one topic.

Basically, is it something doable in the ROS environment? If so, is there any option or notification infrastructure that notifies the first publisher or any other node?

Thanks in advance.

edit retag flag offensive close merge delete

Comments

an observation: you tagged this question as ROS1 and ROS2, spanning multiple distros (noetic&melodic vs. foxy&eloquent). Anything specific this refers to?

mgruhler gravatar image mgruhler  ( 2021-02-12 01:55:01 -0600 )edit
1

twist_mux package does something similar for geometry_msgs::Twist messages.

skpro19 gravatar image skpro19  ( 2021-02-12 15:45:19 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-12 02:05:56 -0600

mgruhler gravatar image

No, the intent of the Publish-Subscrib-Pattern is to allow that. See also the ROS1 wiki and the ROS2 wiki for background information.

Note that you could work around that with using the (getNumPublishersfunction)[http://docs.ros.org/en/noet... of subscribers (in ROS1 at least) to check if this is actually fine. Even though that would then not allow you to do a rostopic pub for testing purposes...

You need to make sure manually, that this requirement is met.

edit flag offensive delete link more

Comments

Thanks for your answer. I will take look at rclcpp API more and probably the method you told will help me somehow.

ali ekber celik gravatar image ali ekber celik  ( 2021-02-12 04:33:35 -0600 )edit
1

By the way, the corresponding method of getNumPublishers() in ROS2 is count_publishers()

ali ekber celik gravatar image ali ekber celik  ( 2021-02-15 01:29:18 -0600 )edit

does count_publishers() get the total publishers of a topic, or the number of publishers for a node?

variable gravatar image variable  ( 2022-01-06 12:08:29 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-02-11 09:13:26 -0600

Seen: 736 times

Last updated: Feb 12 '21