|
| 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 "perception/enable_detect_by_identity.hpp" |
| 16 | + |
| 17 | +#include <string> |
| 18 | + |
| 19 | +namespace perception |
| 20 | +{ |
| 21 | + |
| 22 | +using namespace std::chrono_literals; |
| 23 | +using namespace std::placeholders; |
| 24 | + |
| 25 | +EnableDetectByIdentity::EnableDetectByIdentity( |
| 26 | + const std::string & xml_tag_name, const std::string & action_name, |
| 27 | + const BT::NodeConfiguration & conf) |
| 28 | +: perception::BtServiceNode<std_srvs::srv::SetBool, |
| 29 | + rclcpp_cascade_lifecycle::CascadeLifecycleNode>( |
| 30 | + xml_tag_name, action_name, conf) |
| 31 | +{ |
| 32 | +} |
| 33 | + |
| 34 | +void EnableDetectByIdentity::on_tick() |
| 35 | +{ |
| 36 | + RCLCPP_DEBUG(node_->get_logger(), "EnableDetectByIdentity ticked"); |
| 37 | + |
| 38 | + getInput("enable", enable_); |
| 39 | + request_->data = enable_; |
| 40 | +} |
| 41 | + |
| 42 | +void EnableDetectByIdentity::on_result() |
| 43 | +{ |
| 44 | + if (result_.success) { |
| 45 | + std::cout << "Success EnableDetectByIdentity" << std::endl; |
| 46 | + setStatus(BT::NodeStatus::SUCCESS); |
| 47 | + |
| 48 | + } else { |
| 49 | + std::cout << "Failure EnableDetectByIdentity" << std::endl; |
| 50 | + setStatus(BT::NodeStatus::FAILURE); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +} // namespace perception |
| 55 | + |
| 56 | +#include "behaviortree_cpp_v3/bt_factory.h" |
| 57 | +BT_REGISTER_NODES(factory) |
| 58 | +{ |
| 59 | + BT::NodeBuilder builder = [](const std::string & name, const BT::NodeConfiguration & config) { |
| 60 | + return std::make_unique<perception::EnableDetectByIdentity>( |
| 61 | + name, "/detect_person_by_identity", config); |
| 62 | + }; |
| 63 | + |
| 64 | + factory.registerBuilder<perception::EnableDetectByIdentity>("EnableDetectByIdentity", builder); |
| 65 | +} |
0 commit comments