Design advice for executing sequence of ros msg interactions
I am struggling with a good design for nodes that when receiving a callback must perform a sequence of interactions with one or more other ros nodes.
So far I ended up mixing spin and spinOnce but something tells me that this is far from optimal. Here is some pseudo code of what I am trying to achieve:
void actionCallback() {
// want to write some logic in sequential style,
// but the sequence involves multiple ros message send/receive:
result1 = rosService1();
result2 = rosService2();
result3 = waitForSomeMessageOnTopic();
// ...
}
Result rosService1() {
// This my attempt of simulating a synchronous call to a ros service
... call service 1
while (response from service1 not received) {
spin_once();
... sleep a bit
}
... return result from service1 response
}
int main() {
...
startActionServer();
spin();
}
I guess this design challenge has some better well-proven solutions. Please advice.