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

What to do with unused node?

asked 2012-06-05 03:49:20 -0600

liborw gravatar image

updated 2014-04-20 14:09:31 -0600

ngrennan gravatar image


there are some tasks (topics) that are needed only from time to time (i.e. camera capture and processing), however, it is not good idea to implement them as services (i.e. the topic is subscribed by many nodes).

One option that come to my mind are to use parameter server to control where the node is computing and where is doing nothing.

What are the the other options? Or what is the advised approach to deal with unused nodes?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-06-05 04:02:48 -0600

DimitriProsser gravatar image

The ros::Publisher class provides a method that you could use:

ros::Rate poll_rate(100);
while(chatter_pub.getNumSubscribers() == 0)

This block of code will wait until there's a subscriber connected to continue. I'm not sure if this is what you need, but it is one option.

I'm not sure how your system of nodes is configured, but another option you could use would be to provide a "start" and "stop" service that you could call to tell the node when to compute. This is much easier than using the parameter server to do so.

edit flag offensive delete link more

answered 2012-06-05 03:59:41 -0600

Lorenz gravatar image

You can write nodes that only produce data when there is at least one subscriber. Two ways to achieve that:

  1. NodeHandle::advertise supports subscription callbacks that are executed whenever a node subscribes or unsubscribes from the topic.

  2. The Publisher object returned by advertise has a method getNumSubscribers.

edit flag offensive delete link more

Question Tools


Asked: 2012-06-05 03:49:20 -0600

Seen: 325 times

Last updated: Jun 05 '12