ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
You should not sleep in subscriber callbacks. The sleeps will block all other callbacks if you have just one spin thread. And I guess that's exactly what's happening. What probably happens is the following:
That means withing 5 seconds, you get two messages re-published for the string which would explain the rate of 2.5Hz.
Instead of sleeping in the callbacks, implement your re-publisher differently. The simplest solution would be to re-publish in a main loop if enough time since the last publish call passed. Don't forget to call spinOnce in your main loop to execute the subscriber callbacks.