0
$\begingroup$

Rosanswers logo

I am using rospy but I don't mind getting a solution in roscpp.

I have a publisher that publish message at a rate of 60Hz, and let say my subscriber is capable of handling messages at 6Hz. I am planning to sample the messages from the subscriber side and take the last available message from the publisher for subscription. Setting the queue_size to one, I can possibly sample the message. However, the new message that I am processing is turn out to be the one available just after the subscriber node finish processing the previous topic.

To clarify more, let say the publisher publish message at time t t = [0, 1, 2, 3, ..., 9, 10, 11, ...] sec Assuming the first subscription to occur at 0.5 Sec What I'm getting is the next subscription on the message topic occurring at time t = 11sec, what I want is to use the the message at time t=10Sec.

I hope I explain myself well.


Originally posted by hashmuke on ROS Answers with karma: 23 on 2014-03-18

Post score: 2


Original comments

Comment by demmeln on 2014-03-19:
There seems to be some confusion of terms. The publisher advertises a topic (once) and the subscriber subscribers to the topic (once). After that, what occurs repeatedly is the publisher publishing messages (not topcis) and the subscriber recieving/processing messages.

Comment by demmeln on 2014-03-19:
Having said that, I'm not sure I understand your question exactly. Do you want to process always the latest (newest) received message in your 6Hz subscriber? I.e on average every 10th message would be used? Providing some code of your subscriber and publisher could help.

Comment by hashmuke on 2014-03-19:
Thanks @demmeln, I have tries to put things in properly.

Comment by Wolf on 2014-03-19:
I would like to add that both, publisher and subscriber have a queue size. I assume both have to be at 1 for getting the behaviour you are looking for...

Comment by hashmuke on 2014-03-19:
@Wolf is it really possible to set queue_size to one in rospy.Publisher or do I have to use the other arguments?

Comment by demmeln on 2014-03-19:
@Wolf why do you say that? What happens when only subscriber has queue size 1?

Comment by Wolf on 2014-03-19:
Advertise of publisher has also arg queue_size. C++ signature: template Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false); not familiar with python. Doc of queue size says:Maximum number of outgoing messages to be queued for delivery to subscribers

Comment by Wolf on 2014-03-19:
I assume - have not tested that - that the publisher also uses this as FIFO queue if the subscriber is not able to subscribe at full rate. I. e. if subscriber queue size is 1 and publisher queue 10 you would still always get the "10 messages ago" message if publisher queue is full...

Comment by demmeln on 2014-03-20:
I would be surprised if this was the way this works. I would have assumend to publisher queue comes in effect if the publisher publishes faster than the throughput of the network connection to the subscribers. The rate at witch callbacks are processed is possibly much slower than the rate at which

Comment by demmeln on 2014-03-20:
incoming messages are received and put in the queue. So I believe having queue size 1 on the subscriber side should be sufficient to always process the latest message (assuming network throughput is sufficient to easily transport all messages on the topic), but I may be wrong.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

+1 to @demmeln for his clarification about topic/message. Please review these terms.

I would spontaneously suggest a threaded solution. You do all your time consuming work in a separate thread and in your subscriber callback just pick the messages you want, discard all the others and provide the worker thread the correct messages.


Originally posted by BennyRe with karma: 2949 on 2014-03-19

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by hashmuke on 2014-03-19:
@BennyRe thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.