Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
is_goal_nearby_condition.hpp
1 // Copyright (c) 2026 Jakub ChudziƄski
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__IS_GOAL_NEARBY_CONDITION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_GOAL_NEARBY_CONDITION_HPP_
17 
18 #include <limits>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "behaviortree_cpp/condition_node.h"
24 #include "geometry_msgs/msg/pose_stamped.hpp"
25 #include "nav2_behavior_tree/bt_utils.hpp"
26 #include "nav2_ros_common/lifecycle_node.hpp"
27 #include "nav_msgs/msg/path.hpp"
28 #include "rclcpp/rclcpp.hpp"
29 #include "nav2_ros_common/tf2_factories.hpp"
30 
31 namespace nav2_behavior_tree
32 {
33 
47 class IsGoalNearbyCondition : public BT::ConditionNode
48 {
49 public:
55  IsGoalNearbyCondition(const std::string & condition_name, const BT::NodeConfiguration & conf);
56 
57  IsGoalNearbyCondition() = delete;
58 
63  BT::NodeStatus tick() override;
64 
69  static BT::PortsList providedPorts()
70  {
71  return {
72  BT::InputPort<nav_msgs::msg::Path>("path", "Planned path"),
73  BT::InputPort<double>(
74  "proximity_threshold", 1.0,
75  "Proximity length (m) of the remaining path considered as a nearby"),
76  BT::InputPort<double>(
77  "max_robot_pose_search_dist", -1.0,
78  "Maximum forward integrated distance along the path "
79  "(starting from the last detected pose) to bound the search for the closest pose "
80  "to the robot. When set to negative value (default), whole path is searched every time"),
81  BT::InputPort<std::string>("global_frame", "Global frame"),
82  BT::InputPort<std::string>("robot_base_frame", "Robot base frame"),
83  };
84  }
85 
86 private:
87  nav2::LifecycleNode::SharedPtr node_;
88  nav2::TransformBuffer::SharedPtr tf_buffer_;
89  nav_msgs::msg::Path path_;
90  std::vector<geometry_msgs::msg::PoseStamped>::iterator closest_pose_detection_begin_;
91  double transform_tolerance_;
92  std::string global_frame_;
93  std::string robot_base_frame_;
94 };
95 
96 } // namespace nav2_behavior_tree
97 
98 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_GOAL_NEARBY_CONDITION_HPP_
A BT::ConditionNode that returns SUCCESS when remaining length of the current planned path is less th...
static BT::PortsList providedPorts()
Creates list of BT ports.
BT::NodeStatus tick() override
The main override required by a BT action.