getNumSubscribers and TopicManager

asked 2020-03-05 07:24:33 -0600

billkotsias gravatar image

I am trying to limit the number of subscribers a topic can get to just 1. However, I see that publisher.getNumSubscribers() and subscriber.getNumPublishers() only return either 0 or 1!

I also tried to get the TopicManager like auto manager = ros::TopicManager::instance(); // check for multi-instantiation of singleton modules and using it to check the number of subscribers per topic like: manager->getNumSubscribers(from_topic) but this ALWAYS returns 0!

The code is pretty simple, I create subscribers and publishers to the same topics, in the same function call. Between each creation, I also call ros::spinOnce().

Eventually, getNumSubscribers() increases from 0 to 1 but never to more.

Is this a feature or a bug?

edit retag flag offensive close merge delete

Comments

I am trying to limit the number of subscribers a topic can get to just 1

can you tell us how you plan to do that?

gvdhoorn gravatar image gvdhoorn  ( 2020-03-05 07:33:05 -0600 )edit

I would just throw if I saw that 2 publishers or 2 subscribers are on the same topic. So programmer will know he mustn't do it. But seems this isn't possible in current Ros version. They don't go over 1 (maybe cause they are in same process)

billkotsias gravatar image billkotsias  ( 2020-03-05 15:04:09 -0600 )edit