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

Revision history [back]

click to hide/show revision 1
initial version

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.