[ROS2] What's the best way to wait for a new message?
I'm trying to sync up some behaviors and some data while avoiding callback hell. What's a good way to effectively wait for a new data on a subscription in a synchronous manner?
Here's the high level of what I'd like to do:
start_process_callback() {
trigger_led();
wait_seconds();
leftimage = get_left_image();
trigger_different_led();
rightimage = get_right_image();
result = do_things_to_images(leftimage, rightimage);
send_result(result);
}
Where the LED functions are publishers and the get_image functions block until a new image is received on a topic then return that image. I hope this helps clarify things. ROS1 had a wait_for_message, but ROS2 doesn't seem to have anything like that. The only other alternative I can think of is to have a convoluted state machine in a bunch of nested callbacks, but I'd really rather not do that if possible.
Thoughts?