I have an uncontrolled thread called in my service callback and it looks like the frequency at which it s executed is a bit slow. Is there a way I could put a ros rate in my service in order to force more ressources on my thread within the callback ?
I don't believe a Rate
would do what you describe.
ros::Rate
is essentially a bookkeeping version of a generic sleep(..)
or delay(..)
.
bookkeeping, in that it measures the time already "used up" between the previous invocation to Rate::sleep()
and the current one, compares that to the period it has been configured with, and then only sleeps for the remaining amount of time (ie: the time needed to get as close as possible to the configured period).
See also wiki/roscpp/Overview: Sleeping and Rates.
Rate
is not a scheduling mechanism -- or at least: it cannot influence "resource usage" by other threads of execution directly.
If however, you're currently busy-waiting on the completion of your external thread (ie: a tight while(true);
), and thereby starving that thread, adding some form of sleep(..)
could help (but you could also use a condition variable or some other form of inter-thread communication).
But it would not have to be a Rate
per se.
It feels like ros rate is only made for topics.
there is nothing in ros::Rate
which makes it specific to topics -- or services, or actions, or anything else really. It's just a slightly more "intelligent" version of sleep(..)
.
And off-topic (and perhaps pedantic), but: a service server which spins up an additional thread to process an incoming request almost starts to sound like this should actually be an action server.