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

Question about Multiple callbacks in spinOnce()

asked 2015-01-24 06:42:39 -0500

ZiyangLI gravatar image

Dear all,

I have a node which subscribes to 3 different topics and let's call them

A: 80Hz B: 120Hz C: 50Hz

And I define the subscribers like this:

nh.subscribe("A/B/C", 1, A/B/C_callback, ros::TransportHints().tcpNoDelay());

in the main loop(which is 60Hz), I call spinOnce() and do some control task. But I have noticed that at some times I never enter B_callback. I can confirm that the publishers are all working, so why is this happening?

Best,

Ziyang

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-24 07:39:55 -0500

This Q/A also has some relevant information. If I read your subscriber definition correctly. you have 3 separate subscribers, all with a queue size of 1. This means that when spinOnce() is called at 60 Hz, you should get your callbacks called for all your subscribers. As you publish faster than 60 Hz on A and B and only have a queue size of 1, it is expected that some messages on both topic are dropped (in fact, on average half of them for B). I'm not sure why B_callback sometimes is never called, but I'd recommend increasing the queue size on your subscribers to see if that improves things.

edit flag offensive delete link more

Comments

Dear @Stefan, you understand my question correctly. I am not sure if your suggestion will work, but I don't want to increase the queue_size because I only want to do control based on the latest messages. I am thinking assigning each subscriber its own message queue, do you think that is necessary?

ZiyangLI gravatar image ZiyangLI  ( 2015-01-24 07:51:26 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-24 06:42:39 -0500

Seen: 977 times

Last updated: Jan 24 '15