Robotics StackExchange | Archived questions

ros2 async api / figure out if I need to spin

Hi,

I don't get how to program a generic library that use any ros2 async API calls under the hood.

As an example I want to program, a generic helper library, that uses service calls under the hood.

void doSomeCall();

As this should be a generic library, we can expect it to be called in 4 relevant scenarios

I managed to get a somewhat usable solution for the first and second case, which is to check,

node.get_node_base_interface()->get_associated_with_executor_atomic()

and depending on this either wait for the future, or call rclcpp::spinuntilfuture_complete.

But for the other cases I am basically dead in the water. I considered passing in a bool, weather to spin or not, but I don't like this solution a bit, as it breaks abstraction of the helper class, and is super error prone.

Any suggestions, or mystical thread local API calls that can return if you are called from a spinner ?

Asked by JM_ROS on 2023-07-24 10:12:11 UTC

Comments

Answers