Ask Your Question

Using spinOnce inside Services

asked 2014-01-16 08:15:44 -0600

orion gravatar image

updated 2014-01-28 17:06:39 -0600

ngrennan gravatar image

I would like to know whether it is safe or bad practice to spin ROS inside a while loop that exists inside a service callback. I am unable to use actions for this particular goal, and have confirmed that spinOnce inside the loop behaves as I expected, but before I go further I wanted to see if I was missing anything. Basically, there will be another process that will break the while loop and return either true or false based on the purpose of the break.

Edit: This question originally pertained to C++ packages, but has since also started to focus on python. Basically, I may have a service that is called, but should not respond until another action has finished (communications). I do not want this pause to effect other functions of the package, so I would like to find a way to have the service wait on responding, but spin ROS and let other callbacks react. I see that AsyncSpinner may be a good solution, but not sure of one for python.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-16 22:52:01 -0600

Adolfo Rodriguez T gravatar image

IIUC from the question, you need to service ROS callbacks during the execution of a service callback. Have you considered an asynchronous spinner as an alternative?. This wiki entry on Callbacks and Spinning is quite complete and might prove useful to your usecase.

edit flag offensive delete link more


Example: I create a service. When the service callback begins, I initiate something. Until that something is finished, I do not send the response for the service. My thought was to have while loop on variable that the something would set to send the response. I will checkout the asynch spnner.

orion gravatar imageorion ( 2014-01-24 04:28:51 -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


Asked: 2014-01-16 08:15:44 -0600

Seen: 560 times

Last updated: Jan 24 '14