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

Service to tell an image publisher to continuously start / stop publishing?

asked 2017-01-20 18:23:02 -0600

updated 2017-01-22 01:44:24 -0600

Hi,

So the GetPolledImage service from the polled_camera package ( http://wiki.ros.org/polled_camera ) makes a single request to the image publisher.

Is there another "core" ROS service similar to GetPolledImage that tells the image publisher to continuously publish at N Hz (ie StartPollImage) until told to stop (perhaps via a StopPollImage service)?

Or do I just need to roll, create my own (trying not to reinvent the wheel)?


(edit 1/21) - I've been asked to give my use case. I have an IP Camera and a ROS node that can HTTP request an image from the IP Camera. A Start/StopPollImage can 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. Hope this makes sense. Happy to further clarify.

Thanks! Jack

edit retag flag offensive close merge delete

Comments

I'm not saying there aren't valid use-cases for it, but can you provide a bit more context to see whether another approach might solve your problem as well? Know that ROS does not use network bandwidth if there are no subscriptions, and that a publisher can inquire about the nr of subscribers.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-21 03:18:12 -0600 )edit

No prob! Edit will edit my main post with use case.

jackp510 gravatar image jackp510  ( 2017-01-22 01:40:25 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-22 04:21:49 -0600

gvdhoorn gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-20 18:23:02 -0600

Seen: 738 times

Last updated: Jan 22 '17