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

Polled topics never really made it (unfortunately). But I'm not entirely sure that is what you want here anyway.

[..] tell the node when to start/stop fetching from the IP Camera rather than just continuously fetch from the IP Camera regardless of who's subscribed.

I'm not sure I understand completely, but if you're just worried about fetching from the camera when there are no subscribers, this kind of Node behaviour is typically achieved using ros::Publisher::getNumSubscribers(). Something like:

[..]

ros::Publisher my_pub = n.advertise<..>(..)
ros::Rate ..

[..]

while (ros::ok())
{
  [..]

  if (my_pub.getNumSubscribers() > 0)
  {
    // poll IP camera, convert data, publish msg
  }
  else
  {
    // do nothing (or at least: don't poll IP camera)
  }

  [..]

  rate.sleep();
}

[..]

As soon as a Subscriber connects, you start polling the resource. As soon as there are no more subscribers, you stop. No explicit action required by your Subscribers.

An alternative would be to add a Service to your node (of type std_srvs/Trigger) that (en|dis)ables your Publisher, but that requires subscribing nodes to know about that service, and to know about the flow of control required to interoperate with your node. All of which reduces reusability.