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

Revision history [back]

I think I can see why your code is behaving in this way. While your callback is waiting for the user to press a key the image subscriber is still operating and queuing up messages to process, so that when the callback finishes the next image is immediately processed and so on in a loop.

To be clear, do you want the node to take a single picture when you press 1 or a sequence of pictures until you press 2?

If you just want to take a single picture then you should make your subscriber object image_sub a global initially set to None Then in the image callback call the image_sub.unregister() function so that only a single callback will be executed until the subscriber is re-created again.

If you want to continuously take pictures until 2 is pressed then you'll want to create the subscriber with a queue size of 1:

image_sub = rospy.Subscriber("/camera/rgb/image_raw",Image,test, queue_size=1)

And move the call to image_sub.unregister() into the if movement ==1: case.

Hope this helps.