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

How to Detect Subscriber Drops a Message

asked 2016-09-23 05:56:30 -0600

Nanoha gravatar image

updated 2016-09-23 05:57:31 -0600

I made a subscriber which reads LIDAR data from rosbag-play. I use C++(roscpp).

But when I do rosbag-play with normal speed, subscriber's callback function cannot catch up with LIDAR stream speed, then subscriber's queue become easily full, and many data is dropped and algorithm doesn't work properly.

So I have to control the speed of rosbag-play, and to decide appropriate speed, I need to know whether subscriber is dropping data or not. How can I detect that ?

(Making queue-size very big is not my choice, because it's just a matter of time until the queue gets full...)

(I googled about this question and expected someone already answered, but I could not find any concrete solutions)

Thank you for your time, in advance.


Best regards,

Nanoha.

edit retag flag offensive close merge delete

Comments

1

Why do you need the rosbag play? Can't you implement a testing interface in which the node pulls the data directly from the bagfile with the C++-Api?

NEngelhard gravatar image NEngelhard  ( 2016-09-24 15:15:12 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2016-09-23 13:41:55 -0600

Mark Rose gravatar image

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.

edit flag offensive delete link more

Comments

Thank you for replies. You mean making a class like below, or make global queue? class LaserSub { static queue<sensor_msgs> input; static void callback(&msg) { // if queue is full print error, if not full just process }; // main scan_sub = nh.subscriber("hoge", 1, &LaserSub::callback, this) ;

Nanoha gravatar image Nanoha  ( 2016-09-24 09:21:31 -0600 )edit
2

answered 2016-09-23 20:26:14 -0600

kmhallen gravatar image

There is a sequence number in the header. As long as the messages are generated by a single node, you could check msg->header.seq for any skips.

edit flag offensive delete link more

Comments

Unfortunately, the sequence number is not reliable, according to the design comments around ROS2. ROS2 drops the sequence number therefore.

Mark Rose gravatar image Mark Rose  ( 2016-09-23 22:44:13 -0600 )edit

Thank you kmhallen. I learned this matter, too. Your idea was not in my dictionary.

Nanoha gravatar image Nanoha  ( 2016-09-24 09:26:36 -0600 )edit
1

In ROS1 this works. You can even see it yourself on this line of code in rospy's implementation:

if self.last_seq_ + 1 != msg.header.seq:
    self.dropped_msgs_ = self.dropped_msgs_ + 1

/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/statistics.py:255

danielsnider gravatar image danielsnider  ( 2017-09-04 21:49:57 -0600 )edit
1

answered 2017-09-04 21:52:22 -0600

danielsnider gravatar image

updated 2017-09-04 22:03:23 -0600

For the subscriber's drop count, you'll have to check within your own subscriber that the header.seq number is always incrementing by only one.

You can see the number of dropped messages from the publisher's queue by enabling topic statistics. Read more about it here: http://wiki.ros.org/Topics#Topic_statistics

edit flag offensive delete link more

Comments

1

As already remarked by @Mark Rose, relying on seq is not robust. Not all client libraries will set it, and even if they do, it may be lost along the way (ie: when republishing or publishing derived msgs).

I'm not saying that you cannot use this approach, but be aware of the limitations.

gvdhoorn gravatar image gvdhoorn  ( 2017-09-05 03:14:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-23 05:56:30 -0600

Seen: 3,933 times

Last updated: Sep 04 '17