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

You might try this approach:

  • Set up a queue inside your node for incoming messages, with some fixed size.
  • Callback function for your message subscriber (which runs in its own thread) puts incoming messages into the queue, unless full, in which case it drops the message and increments a count of dropped messages.
  • Main loop follows the logic below.

    while (ros::ok()) {
        nh.spinOnce();
    
        if  (droppedMessageCount > 0) {
            ROS_ERROR("%d messages were dropped", droppedMessageCount);
        }
        droppedMessageCount = 0;
    
        if (message queue not empty) {
            take first message from queue and process it
        }
    }
    

This doesn't use any ROS facilities to find out if messages are dropped, but would allow your node to give an indication in the log.