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

ros service callback blocks the other node callbacks?

asked 2011-06-27 22:38:26 -0600

quimnuss gravatar image

Hi all! Does a slow service callback prevent the other callbacks from running? Is there a multi-thread solution behind the scenes, or a FIFO queue?

In the situation that there's a service with a publisher/subscriber structure for what should be a service, is there a neat wait to sincronize the request with the published answer? It looks like waiting on a mutex or flag prevents the subscription callback from running.

Cheers!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2011-06-27 23:17:29 -0600

Lorenz gravatar image

It depends on the number of spin threads you have running. If you have only one, the service callback will block subscriptions. If you have more than one running, subscriptions should still work. The easiest way to run multiple spin threads is the AsyncSpinner class.

edit flag offensive delete link more

Comments

Understood, so there's only one thread if there's a sinle ros::spin. I'll take a look at the AsyncSpinner class, although i'll probably change the node to provide a service functionality rather than a publisher/subscriber structure (I'll set both, actually). Thanks!
quimnuss gravatar image quimnuss  ( 2011-06-28 03:57:58 -0600 )edit

Sorry I didn't get. If I have a single node with a global variable, single spin and two callbacks, if I try to modify the variable on one callback I'm ensured that there will be no race conditions while I try to modify the same variable on the other callback?

mark_vision gravatar image mark_vision  ( 2015-05-05 09:58:30 -0600 )edit
2

answered 2011-06-28 02:59:15 -0600

dornhege gravatar image

Are you designing the service yourself? If is something that takes quite long (like executing a command on a robot), it might be worth making this an action using actionlib as that is designed exactly for that.

edit flag offensive delete link more

Comments

Yeah, I though about that too. But seems to me it doesn't take long enough to be though as an action. Like a minute of computing at most.
quimnuss gravatar image quimnuss  ( 2011-06-28 03:55:16 -0600 )edit
Generally, you can (and maybe should :)) use an action if you have code that runs for quite some time and where it could make sense to preempt it at some point during execution. Preemption is not possible with services.
Lorenz gravatar image Lorenz  ( 2011-06-28 05:04:30 -0600 )edit
A minute is a very long time, you should make it an action. It will report when finished. You can wait until it's done or cancel it if something else comes up.
joq gravatar image joq  ( 2011-06-28 08:00:56 -0600 )edit
Interesting, I misunderstood actions for more "clean the dishes" kind long-term goal. I'll switch everything to actions.
quimnuss gravatar image quimnuss  ( 2011-07-12 21:08:37 -0600 )edit

Question Tools

Stats

Asked: 2011-06-27 22:38:26 -0600

Seen: 2,865 times

Last updated: Jun 28 '11