Ros subscriber not up to date

我的未来我决定 提交于 2019-12-05 16:12:50

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.

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 :)

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

The reason for the visible lag is most probably that your callback function takes up a lot of time. If at all possible, try to fix that. Setting the queue size to 1 essentially means asking ROS to process whatever frames it can hold on to.

Set your queue size to a larger number, say 5 or 10. This way, (hopefully, if the processing delay isn't too much) all of your frames will be processed, but they'll be lagging behind in time. That is, the video processing will run a few steps behind but without any "jerks" and missing frames in between.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!