Synchronous service client call from C++
Trying to call a service from one node to another in C++ feels very complex. I have this situation:
auto c = create_client<std_srvs::srv::SetBool>("targetService");
auto r = c->async_send_request(
std::make_shared<std_srvs::srv::SetBool::Request>());
while (rclcpp::ok() && !(r.wait_for(std::chrono::seconds(1)) ==
std::future_status::ready)) {
RCLCPP_INFO(get_logger(), "Waiting");
}
This is never done, even if targetService
exists and executes its callback to a finishing state. The problem occurs when the service is hosted by a node in a separate docker container, so frustratingly I can't make it appear in unit testing, where it works totally fine even using different executors in different threads. How do I go forward in a situation like this? Feels kinda basic, I wanna call a service and use the output from one node to another as if I were a user. Hope I'm missing something basic.
If it matters, the service (branded as targetService
) in the minimal example above is a custom planner from the nav2 stack, which is being spun by the planner server node. It executes the callback correctly, but the future in the client is never finished. What can I do?