ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How do you determine the number of messages left in your subcriber buffer queue?

asked 2016-12-06 16:45:33 -0600

Grim gravatar image

updated 2016-12-07 06:57:38 -0600

If I have a subscriber with a buffer size of 10, and my callback has dealt with 3 messages, is there a way to access the number of messages left in the queue ( retrieve the value of 7 )?

Basically I want my subscriber to deal with a batch of messages, and then do some task once they have all come through, then deal with the next batch of messages, and then do the task again. I do not know the size of the batch of messages.

Ideally I just need an indication that the buffer is empty.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-12-06 17:03:59 -0600

paulbovbel gravatar image

updated 2016-12-06 17:04:52 -0600

Push your messages shared_ptr to another data structure as they come in (such as std::queue), and do your batch processing there instead.

The inner workings of the ROS subscriber's message buffer are not exposed through the roscpp API.

edit flag offensive delete link more


While I think this may be a solution, I don't know how to do it. I have not dealt with std::shared_ptr or std::queue. And I am not sure if learning it right now would be worth my time for this project. This also needs to be memory efficient since the messages themselves are quite large.

Grim gravatar image Grim  ( 2016-12-07 06:48:37 -0600 )edit

You'd be pushing the boost::shared_ptr to the message (as received by your callback, ConstPtr) to the queue, so memory impact would be negligible.

If you're going to work with C++, I suggest becoming very familiar with the basics of std, particularly containers ( )

paulbovbel gravatar image paulbovbel  ( 2016-12-07 09:05:07 -0600 )edit

Question Tools



Asked: 2016-12-06 16:45:33 -0600

Seen: 539 times

Last updated: Dec 07 '16