Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
goal_reached_condition.hpp
1 // Copyright (c) 2019 Intel Corporation
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__GOAL_REACHED_CONDITION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__GOAL_REACHED_CONDITION_HPP_
17 
18 #include <string>
19 #include <memory>
20 
21 #include "nav2_ros_common/lifecycle_node.hpp"
22 #include "behaviortree_cpp/condition_node.h"
23 #include "behaviortree_cpp/json_export.h"
24 #include "nav2_behavior_tree/bt_utils.hpp"
25 #include "nav2_behavior_tree/json_utils.hpp"
26 #include "nav2_ros_common/tf2_factories.hpp"
27 #include "rclcpp/clock.hpp"
28 
29 
30 namespace nav2_behavior_tree
31 {
32 
43 class GoalReachedCondition : public BT::ConditionNode
44 {
45 public:
52  const std::string & condition_name,
53  const BT::NodeConfiguration & conf);
54 
55  GoalReachedCondition() = delete;
56 
60  ~GoalReachedCondition() override;
61 
66  BT::NodeStatus tick() override;
67 
71  void initialize();
72 
77  bool isGoalReached();
78 
83  static BT::PortsList providedPorts()
84  {
85  // Register JSON definitions for the types used in the ports
86  BT::RegisterJsonDefinition<geometry_msgs::msg::PoseStamped>();
87 
88  return {
89  BT::InputPort<geometry_msgs::msg::PoseStamped>("goal", "Destination"),
90  BT::InputPort<std::string>("robot_base_frame", "Robot base frame")
91  };
92  }
93 
94 protected:
98  void cleanup()
99  {}
100 
101 private:
102  nav2::LifecycleNode::SharedPtr node_;
103  nav2::TransformBuffer::SharedPtr tf_;
104 
105  double goal_reached_tol_;
106  double transform_tolerance_;
107  std::string robot_base_frame_;
108 };
109 
110 } // namespace nav2_behavior_tree
111 
112 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__GOAL_REACHED_CONDITION_HPP_
A BT::ConditionNode that returns SUCCESS when a specified goal is reached and FAILURE otherwise.
static BT::PortsList providedPorts()
Creates list of BT ports.
void initialize()
Function to read parameters and initialize class variables.
BT::NodeStatus tick() override
The main override required by a BT action.
~GoalReachedCondition() override
A destructor for nav2_behavior_tree::GoalReachedCondition.
bool isGoalReached()
Checks if the current robot pose lies within a given distance from the goal.