Ask Your Question
2

How to Detect Subscriber Drops a Message

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

Nanoha gravatar image

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

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 imageNEngelhard ( 2016-09-24 15:15:12 -0500 )edit

3 Answers

Sort by » oldest newest most voted
1

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

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 imageNanoha ( 2016-09-24 09:21:31 -0500 )edit
2

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

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 imageMark Rose ( 2016-09-23 22:44:13 -0500 )edit

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

Nanoha gravatar imageNanoha ( 2016-09-24 09:26:36 -0500 )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 imagedanielsnider ( 2017-09-04 21:49:57 -0500 )edit
1

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

danielsnider gravatar image

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

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 imagegvdhoorn ( 2017-09-05 03:14:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 1,728 times

Last updated: Sep 04 '17