Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ros subscriber not up to date

I have written a ROS subscriber to one of the image topics and I have set my buffer to 1 using:

subscriber =rospy.Subscriber("/camera/rgb/image_mono/compressed",CompressedImage, callback,  queue_size=1)

However my subscriber still lags behind. Any idea what might be causing this? Am I setting the queue size correctly?

like image 972
Sello Mkantjwa Avatar asked Oct 16 '14 23:10

Sello Mkantjwa


3 Answers

I was having the exact same problem (it wasnt the choppy framerate that was the issue, it was the actual lag). When I would kill whatever image source was publishing (rosbag, camera driver, etc.), my node would still process ~5-10 frames even after the source was killed (and I was sure I had queue_size=1)

Here is the github issue I made and it was resolved. It turns out there are multiple queues involved (not just the one that you set queue_size to 1). In my case, the default buff_size was smaller than my images, and so my node wasn't processing them fast enough, and there always was a number of images backed up in some queue.

TL;DR increase the buff_size for your subscriber, as I did here. It worked for me :)

like image 124
Cashew Avatar answered Oct 19 '22 11:10

Cashew


The queue is for queueing incoming messages. This means, if your callback takes longer to proccess than new messages arrive, only queue size is kept, the others are not processed by your node.

I would suggest to print out a message in the publisher node before publishing and a message at the top of your callback method. Then you can exactly measure the time it takes for ros to handle your messages. All other timing issues will be possibly caused by your callback method.

like image 21
Steffen Avatar answered Oct 19 '22 10:10

Steffen


A supplement to why buff_size matters.
Also the official document can help explain another reason that causes lag from the perspective of pub.publish.

publish() in rospy is synchronous by default (for backward compatibility reasons) which means that the invocation is blocking until:

the messages has been serialized into a buffer and that buffer has been written to the transport of every current subscriber

like image 43
Qinsheng Zhang Avatar answered Oct 19 '22 11:10

Qinsheng Zhang