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

Revision history [back]

The standard design approach is to put your image processing steps in a callback, then call ros::spin() in the main program, as shown here.

You should not need to call ros::shutdown() and ros::init() for every callback. If your code is getting stuck in the callback function, then the issue probably lies with the contents of your callback. If you post the callback function here, we might be able to help.

The standard design approach is to put your image processing steps in a callback, then call ros::spin() in the main program, as shown here.

You should not need to call ros::shutdown() and ros::init() for every callback. If your code is getting stuck in the callback function, then the issue probably lies with the contents of your callback. If you post the callback function here, we might be able to help.

Edit:
I still don't quite understand your issues. It would help if you could provide more detail in your original question: callback code, what you expect to see, what is actually happening, etc.

If your callback takes longer to execute than new messages are received, the new messages will be buffered by ROS behind the scenes. Your callback should not be interrupted when new messages are received. The messages will be delivered in the order received, as long as there is space remaining in the message buffer. Eventually, when the message buffer is full, the oldest message will be dropped to make room for new messages. If you always want to process the last-received message, set the queue size to 1 in the ros::subscriber constructor.

So, if your intent is to always process the most-recent image, you shouldn't need to worry about how long your image-processing steps take. Set the subscriber queue size to 1, and ROS will automatically call your callback with the most-recent message as soon as you've finished processing the previous image.