Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
are_error_codes_present_condition.hpp
1 // Copyright (c) 2022 Joshua Wallace
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 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__ARE_ERROR_CODES_PRESENT_CONDITION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__ARE_ERROR_CODES_PRESENT_CONDITION_HPP_
17 
18 #include <string>
19 #include <memory>
20 #include <vector>
21 #include <set>
22 
23 #include "nav2_ros_common/lifecycle_node.hpp"
24 #include "behaviortree_cpp/condition_node.h"
25 
26 namespace nav2_behavior_tree
27 {
28 
39 class AreErrorCodesPresent : public BT::ConditionNode
40 {
41 public:
43  const std::string & condition_name,
44  const BT::NodeConfiguration & conf)
45  : BT::ConditionNode(condition_name, conf)
46  {
47  std::vector<int> error_codes_to_check_vector;
48  getInput("error_codes_to_check", error_codes_to_check_vector); //NOLINT
49 
50  error_codes_to_check_ = std::set<uint16_t>(
51  error_codes_to_check_vector.begin(),
52  error_codes_to_check_vector.end());
53  }
54 
55  AreErrorCodesPresent() = delete;
56 
57  BT::NodeStatus tick()
58  {
59  getInput<uint16_t>("error_code", error_code_); //NOLINT
60 
61  if (error_codes_to_check_.find(error_code_) != error_codes_to_check_.end()) {
62  return BT::NodeStatus::SUCCESS;
63  }
64 
65  return BT::NodeStatus::FAILURE;
66  }
67 
68  static BT::PortsList providedPorts()
69  {
70  return
71  {
72  BT::InputPort<uint16_t>("error_code", "The active error codes"), //NOLINT
73  BT::InputPort<std::vector<int>>("error_codes_to_check", "Error codes to check")//NOLINT
74  };
75  }
76 
77 protected:
78  uint16_t error_code_; //NOLINT
79  std::set<uint16_t> error_codes_to_check_; //NOLINT
80 };
81 
82 } // namespace nav2_behavior_tree
83 
84 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__ARE_ERROR_CODES_PRESENT_CONDITION_HPP_