How to get new messages while executing a service request?
I have written a class called "Driver" which advertises a service. Basically, this service will accept a point (x,y) and return a boolean. It rotates the turtlebot towards the point, and then drives until it reaches that point. The boolean it returns indicates whether or not the robot successfully reached that point.
The design of the service is relatively simple. It periodically sends velocity commands to the robot, as required.
The only time it will return false is when one of the robot bumpers is activated, which can be detected via messages.
My question is: what is the correct design for detecting this bumper change while executing the service request?
My way of doing this is to make another callback inside of the Driver class which specifically handles the bumper message. Then, I would call ros::spinOnce() inside my velocity command loop so that I can detect the message incoming. The bumper callback would set some state in the Driver class, which would be detected by my service request.
I think this would work, but is there a better way?
I was also curious what would happen if multiple service requests were sent to my node. Wouldn't the ros::spinOnce() inside my loop detect the second request and start executing it? This would screw everything up because I can't be handling two services at once. Or perhaps I misunderstand the ROS API behavior in that case.
Thank you for your help.