Increase the frequency at which images are updated in a subscriber
I am using code which tracks the image of a robot. Specifically, the rospy-based code I am using is here.
Here's the relevant part of the code.
"""
The DataCollector class polls data from the rostopics periodically. It manages
the messages that come from ros.
"""
class DataCollector:
def __init__(self,
camera_left_topic="/endoscope/left/",
camera_right_topic="/endoscope/right/",
camera_info_str='camera_info',
camera_im_str='image_rect_color'):
self.left_image = None
rospy.Subscriber(camera_left_topic + camera_im_str, Image,
self.left_image_callback, queue_size=1)
This segment defines the DataCollector class and subscribes to a "left image callback method" which continually updates self.left_image
to be the image as seen by the robot's left camera:
def left_image_callback(self, msg):
if rospy.is_shutdown():
return
self.left_image = self.bridge.imgmsg_to_cv2(msg, "rgb8")
I timed how often the left_image_callback
method is called, and it updates at roughly intervals of 0.5 seconds. In other words, if the robot is moving, the self.left_image
will only update every 0.5 seconds.
My question is simple: how do I increase the rate at which the image gets updated? Ideally I can get this to be 0.2 seconds, if possible. If it matters, I'm using ros indigo, and the robot is Intuitive Surgical da Vinci.
Callbacks get called when they receive data. So, you'd have to publish the images at the rate you want the images to be updated at. Also, if
rospy
is shutdown, I don't believe that your callback will be executed...Perhaps the image processing is CPU-bound, in either the publisher or subscriber? You might also be IO-bound somewhere, particularly if the image data has to travel over wifi.
@jayess Thank you for the comment. How do I find where the images are published? Is this part of the
launch
files? (Sorry, I am new to ROS) Also @clyde the images should not be through wifi since the computer which records the images is directly connected to the robot computer.You would have to increase it from what ever driver/node your camera is using/publishing from.
I resolved it, it was because my callback images were processing the images. That takes up precious time. I commented out any image processing code and now I can get images updated at 0.1 seconds.
Ok that makes sense. I tend to think of callbacks as interrupts. You want to keep them short and and not do too much in them. Perhaps you can write up your solution as an answer here?