ROS publish/subscribe queues
We have two nodes in our system where one node publishes frames from the inbuilt camera and the other processing node takes the image and shows it using imshow in opencv. The messages are essentially Images from sensor_msgs. Both publish and subscribe nodes have queues set to 1 and in the case of subscriber node we also set the to buffer size to 2**24 (we are using rospy).
In the publisher node we set the timestamp to ropsy.Time.now() and in the subscriber node we compare the current time with the timestamp of the message to check how old the frame from the camera is, essentially the delay of communication. If the subscriber node does nothing else then show the image, the delay is very small, few miliseconds. However, if we simulate that the subscriber node needs to do something to process the frame and then show it, the delays increase substantially (we measure the delay before the messages are "processed"). For example, if we set the processing delay of 1 second, then all incoming frames are delayed by 1 second plus the additional 1 second of "processing time". If we take the how queues should work then the input queue on the subscriber should be overwritten with a new frame just before the callback is called (given that it publishes 30 FPS) which would then make the delay of only 1 second due to processing. Right now it seems that the previous message is somehow cached or that the subscriber queue is updated only when the callback function is called and never overwritten.
Are we thinking in the wrong way here, is this expected behaviour?
Asked by zlaja on 2017-12-08 05:43:11 UTC
Comments
Try with a
queue_size
ofNone
. That should result in "the subscriber should be overwritten with a new frame just before the callback is called". Related question: #q269855.Asked by gvdhoorn on 2017-12-08 06:06:51 UTC
On the subscriber side? The delay is only increasing. If put on the publisher side then this would make force the synchronous mode which is not really what we want if I understand it correctly.
Asked by zlaja on 2017-12-08 06:47:57 UTC
If I understood the response of the poster in #q269855 correctly adding this on the subscriber side should essentially give you a
queue_size
of 1 but with the 'overwriting' semantics that you are looking for.If not, then either there is something else going on, or #q269855 was incorrect.
Asked by gvdhoorn on 2017-12-08 06:50:11 UTC
I checked now more throughly the behaviour and it seems that if the queue size is set to None the subscriber will receive 5-6 consecutive images (with consecutive sequence numbers) and then it will jump ca 200 frames forward but still with quite substantial delay which is always increasing.
Asked by zlaja on 2017-12-08 07:38:46 UTC
Converted my answer to a comment
queue_size=None
appears not to work for you.Asked by gvdhoorn on 2017-12-09 04:21:44 UTC
"ROS Spinning, Threading, Queuing Effective use of multi spinner threads, different queues in ROS" https://levelup.gitconnected.com/ros-spinning-threading-queuing-aac9c0a793f
Asked by cascais on 2020-08-06 13:32:33 UTC
@cascais The answers on this forum should be more direct to what the questioner's asking about. While the link you posted looks like a valuable, relevant source, just linking to it doesn't sound like a direct answer. And looks like you've posted the exact same answer to several other posts. Someone flagged your post as offensive, which I think is a reasonable suggestion. Please consider updating your posts.
Asked by 130s on 2020-08-07 02:09:43 UTC
I've converted @cascais answer to a comment. @130s is correct: link-only answers are essentially not answers.
@cascais: please don't spam links like that.
The blog post does seem like a good resource, but if it ever disappears (and it will, as all web pages eventually disappear), the link will
404
and the answer will lose all its value.Please post an answer with the relevant parts quoted from the blog post instead.
Asked by gvdhoorn on 2020-08-07 02:22:00 UTC
Hi @130s, @gvdhoorn, I didn't mean to spam or anything but I didn't want to copy and paste the all content of the blog. but I understand your concern about the link disappearing. I will keep it in my mind.
Asked by cascais on 2020-08-07 02:28:57 UTC
You don't need to copy the entire blog post.
But if you want to post answers, you should copy the parts from the blog post which actually answer the question.
If you don't, and just post a link, future readers will have to read the entire blog post and figure out what exactly in it answers their question.
So again: please quote the relevant parts from the blog post into an answer. That would be fine.
You could still include a link to the blog post, but at least the answer would be stand-alone.
Asked by gvdhoorn on 2020-08-07 02:35:19 UTC
It is difficult to choose a quote that answers exactly the question but I felt it is helpful for questioner(including future ones) to get as much relevant information and think what can apply to their specific problems. But again I understand your point and I will not just paste links from now but try to make the answer stand alone way.
Asked by cascais on 2020-08-07 03:00:01 UTC
If your answer is not an answer, but additional information, then perhaps it should not be posted as answers.
Asked by gvdhoorn on 2020-08-07 03:09:07 UTC