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 5317b9136ea..e557c559ce4 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 @@ -142,6 +142,16 @@ class BtServiceNode : public BT::ActionNodeBase { } + /** + * @brief Function to perform some user-defined operation upon successful + * completion of the service. Could put a value on the blackboard. + * @return BT::NodeStatus Returns SUCCESS by default, user may override to return another value + */ + virtual BT::NodeStatus on_completion() + { + return BT::NodeStatus::SUCCESS; + } + /** * @brief Check the future and decide the status of BT * @return BT::NodeStatus SUCCESS if future complete before timeout, FAILURE otherwise @@ -158,7 +168,8 @@ class BtServiceNode : public BT::ActionNodeBase rc = callback_group_executor_.spin_until_future_complete(future_result_, server_timeout_); if (rc == rclcpp::FutureReturnCode::SUCCESS) { request_sent_ = false; - return BT::NodeStatus::SUCCESS; + BT::NodeStatus status = on_completion(); + return status; } if (rc == rclcpp::FutureReturnCode::TIMEOUT) {