You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
PatrickSowinski
changed the title
Waiting for service response inside an already spinning node is not explained
[Docs] Waiting for service response inside an already spinning node is not explained
Oct 3, 2023
One way is to use an asynchronous spinner. In ROS2, the equivalent to an async spinner in ROS1 is spinning the node in a separate thread (see here). This allows the node to always be spinning without blocking the "main" thread
rclcpp::executors::multi_threaded_executor::MultiThreadedExecutor executor;
// executor.add_node(...);
std::thread executor_thread(std::bind(&MultiThreadedExecutor::spin, &executor));
// Call serviceauto future = service_client->async_send_request(request);
// Do other tasks
...
// Wait for the future to finish and get the response of the service
future.wait();
auto response = future.get();
...
// Once the node is ready to shut down, join the executor thread
executor_thread.join();
The page about how to wait for a service response inside an already spinning node mentions
(see here https://github.com/jdlangs/industrial_training/blob/ros2/gh_pages/_source/session2/ros2/0-Services.md?plain=1#L279C342-L279C342)
But it does link to any of these
ways
. Any idea on where we can find this solution? I've not been able to find anything other than just using callbacks which would not work in every kind of application (e.g. if you want to chain a bunch of service calls after each other).The text was updated successfully, but these errors were encountered: