From 98faef53b6f1b4e53ba7da7a3b1cb561fa0fc82c Mon Sep 17 00:00:00 2001 From: Ashwin Bose <ashwinbose123@gmail.com> Date: Fri, 27 Mar 2020 21:58:36 +0100 Subject: [PATCH] Decide the output of BtServiceNode based on the service-response (#1615) - `BtServiceNode::check_future()` was created, to encapsulate the logic where a the output of the BtServiceNode is computed. - Inherited classes can overload this function according to the requirement of the user --- .../nav2_behavior_tree/bt_service_node.hpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp b/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp index 8fc3ed55..f0cf0f21 100644 --- a/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp +++ b/nav2_behavior_tree/include/nav2_behavior_tree/bt_service_node.hpp @@ -85,7 +85,19 @@ public: { on_tick(); auto future_result = service_client_->async_send_request(request_); + return check_future(future_result); + } + + // Fill in service request with information if necessary + virtual void on_tick() + { + request_ = std::make_shared<typename ServiceT::Request>(); + } + // Check the future and decide the status of Behaviortree + virtual BT::NodeStatus check_future( + std::shared_future<typename ServiceT::Response::SharedPtr> future_result) + { rclcpp::executor::FutureReturnCode rc; rc = rclcpp::spin_until_future_complete( node_, @@ -101,12 +113,6 @@ public: return BT::NodeStatus::FAILURE; } - // Fill in service request with information if necessary - virtual void on_tick() - { - request_ = std::make_shared<typename ServiceT::Request>(); - } - // An opportunity to do something after // a timeout waiting for a result that hasn't been received yet virtual void on_wait_for_result() -- GitLab