Subscriber callback not entered after publisher is relaunched
I have one publisher and one subscriber. If I launch the publisher first and then subscriber, the callback has been entered with no problem. However, if I launched the subscriber first and then publisher, the callback is not entered immediately. After more than 2 minutes' wait, the callback finally gets entered....
In my subscriber, there is a class, and the subscriber is a member variable. In the main loop, there is a while loop, with ros::spinOnce() and rate.sleep() for each iteration.
If I launched only the subscriber itself, and publish messages in command line, the subscriber works fine. But when I launched the publisher and cut it. Then the subscriber is frozen, and cannot come back to life.
With the information you provided it is very difficult to tell what the problem is. Could you attach a minimal source code example that produces this effect?
Thanks for commenting. After I commented out all the function code and only left constructor, callback, an empty while loop, spinOnce, and sleep, the problem still happened. So I don't think it's about my code. After a reboot, the problem disappeared....
The behaviour is not normal and has never happened to me before. My guess is that at some point the subscriber gets in an unknown state, if you are doing it in C++, there is also the probability of some uncontrolled memory leak that may lead to random behaviours. This is why we need your code to help you. Without it, it is very difficult.