|
| 1 | +// Copyright 2024 Intelligent Robotics Lab - Gentlebots |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "configuration/ActivationControl.hpp" |
| 16 | + |
| 17 | +namespace configuration |
| 18 | +{ |
| 19 | + |
| 20 | +ActivationControl::ActivationControl(const std::string & xml_tag_name, const BT::NodeConfiguration & conf) |
| 21 | +: BT::ActionNodeBase(xml_tag_name, conf) |
| 22 | +{ |
| 23 | + config().blackboard->get("node", node_); |
| 24 | +} |
| 25 | + |
| 26 | +BT::NodeStatus ActivationControl::tick() |
| 27 | +{ |
| 28 | + RCLCPP_DEBUG(node_->get_logger(), "ActivationControl ticked"); |
| 29 | + |
| 30 | + // Read inputs |
| 31 | + if (!getInput("deactivate", deactivate_)) { |
| 32 | + RCLCPP_WARN(node_->get_logger(), "ActivationControl: missing 'deactivate' input, defaulting to false"); |
| 33 | + deactivate_ = false; |
| 34 | + } |
| 35 | + if (!getInput("node_name", node_name_)) { |
| 36 | + RCLCPP_ERROR(node_->get_logger(), "ActivationControl: missing 'node_name' input"); |
| 37 | + return BT::NodeStatus::FAILURE; |
| 38 | + } |
| 39 | + |
| 40 | + if (deactivate_) { |
| 41 | + RCLCPP_INFO(node_->get_logger(), "ActivationControl: removing activation for %s", node_name_.c_str()); |
| 42 | + node_->remove_activation(node_name_); |
| 43 | + } else { |
| 44 | + RCLCPP_INFO(node_->get_logger(), "ActivationControl: adding activation for %s", node_name_.c_str()); |
| 45 | + node_->add_activation(node_name_); |
| 46 | + } |
| 47 | + |
| 48 | + return BT::NodeStatus::SUCCESS; |
| 49 | +} |
| 50 | + |
| 51 | +void ActivationControl::halt() |
| 52 | +{ |
| 53 | + RCLCPP_DEBUG(node_->get_logger(), "ActivationControl halted"); |
| 54 | +} |
| 55 | + |
| 56 | +} // namespace configuration |
| 57 | + |
| 58 | +BT_REGISTER_NODES(factory) { |
| 59 | + factory.registerNodeType<configuration::ActivationControl>("ActivationControl"); |
| 60 | +} |
0 commit comments