ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Does ros rate make sense in a service ?

asked 2022-06-02 20:30:29 -0600

tomkimsour gravatar image

Hi,

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 ?

It feels like ros rate is only made for topics.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-06-03 01:55:04 -0600

gvdhoorn gravatar image

updated 2022-06-03 02:20:28 -0600

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.

edit flag offensive delete link more

Comments

I didn't try creating an action server maybe this would solve my problem as neither service or publishing node does the work as I would like

tomkimsour gravatar image tomkimsour  ( 2022-06-19 23:52:47 -0600 )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: 2022-06-02 20:30:29 -0600

Seen: 62 times

Last updated: Jun 03