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

You have to structure the code differently than you have it now.

You must not wait or sleep or do anything time-consuming inside a Subscriber callback. You need to quickly save the callback message into a variable or a queue, and return from the callback as quickly as possible.

Then, in either your main() thread or in a background thread, you use a loop to process each message from the queue. Inside this loop it is ok to use rospy.sleep(d) or rate.sleep(), but make sure you call rospy.is_shutdown() pretty frequently and exit the loop once it returns true.

In this particular case, if images are arriving faster than you display them, you'll need to do something about that.