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

Can you check how many messages are in a subscriber's Queue?

asked 2013-07-11 11:55:12 -0500

Toletum gravatar image

updated 2013-07-11 11:55:53 -0500

For testing purposes, I want to plot the number of messages waiting in a subscriber's topic Queue over time.

Having too many old messages is undesirable since up to date information is critical. However, I don't want to arbitrarily shorten the Queue since one size will definitely not fit all in my situation.

So, is there a simple way I can get the current number of messages in the Queue? I can't seem to find anything in the Subscriber documentation http://www.ros.org/doc/api/roscpp/html/classros_1_1Subscriber.html.

Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-07-11 12:47:01 -0500

cmaltzan gravatar image

Not that I know of from ROS's perspective.

However, there is a simple solution from a programming perspective. Make a counter, numCreated, for the total number of messages published on the given topic. Then you have two choices:

Choice #1: Make a second variable, numRemoved, that counts the number of messages you have removed from the queue. At any point in time: "numInQueue = numCreated - numRemoved"

Choice #2: Every time you go through the loop and process a message, decrease numCreated by one. (I would also change the name of numCreated to numInQueue)

One thing to be aware of is that if you have multiple nodes publishing to your topic, you must have global access to your counter.

edit flag offensive delete link more

Comments

But how I would declare a global variable between two nodes? Would they be properly linked?

Toletum gravatar image Toletum  ( 2013-07-13 18:38:02 -0500 )edit

@Toletum that's valid question but please refrain from asking new question in comment area. Open another question thread (like you've done) and link to this if relevant so that others get a flow that would possibly raise the chance of getting answers.

130s gravatar image 130s  ( 2013-07-14 18:00:04 -0500 )edit

Question Tools

Stats

Asked: 2013-07-11 11:55:12 -0500

Seen: 3,023 times

Last updated: Jul 11 '13