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

Producer-consumer problem in ROS

asked 2013-01-23 22:08:47 -0500

Javier J. Salmerón García gravatar image

updated 2014-01-28 17:14:58 -0500

ngrennan gravatar image

Hello everyone,

I have a newbie problem here. I am trying to implement a ROS Architecture which is similar to a producer-consumer problem. I have one node which is publishing images and a group of nodes that would take the image and do some processing in it. The behaviour that I want to implement is the following: If a consumer node takes one image, I do not want the others to receive that same image. Using the default image_transport publisher, I suppose that all the subscribers will receive the same image at a time. How can I avoid this?

Thank you in advance

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2013-01-24 00:01:41 -0500

dornhege gravatar image

I think using a service for this might be an easy solution. The producer node would not publish, but queue images and provide a service consume_image that returns the next image or fails when empty.

Consumer nodes call this service whenever they are ready to process the next image.

edit flag offensive delete link more

answered 2013-01-23 22:37:58 -0500

KruseT gravatar image

You are right that all topic listeners will receive all images. You will probably need to coordinate the consumers in a centralized way. So you'll need a centralized instance which makes sure each consumer knows which images he has to ignore. There are several ways in which such a centralized coordination can be achieved, depending on your exact setup and needs. E.g. is the number of consumers known beforehand and fixed, or does it change? Do you assume all consumers have the same processing time per image, or is that variable as well? Do you need the consumers to produce an ordered output of produced images, or are their work producets independent of each other?

Depending on such factors, your scheduling strategy needs to be adapted.

Note that you are free to create new topics for that purpose, and you can republish images if that's useful for you. So a central node could listen to the main topic and distribute images over individual topics. Or consumer nodes could be chained with topics, where each consumer either consumes the image, or publishes it to the next. Not saying either is a good solution for you, just making sure you see these possibilities as well.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-01-23 22:08:47 -0500

Seen: 481 times

Last updated: Jan 24 '13