0
$\begingroup$

Rosanswers logo

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.


Originally posted by orion on ROS Answers with karma: 213 on 2014-01-16

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Adolfo Rodriguez T with karma: 3907 on 2014-01-16

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by orion on 2014-01-24:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.