Nav2 Navigation Stack - rolling  main
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/parameter.hpp"
29 #include "rclcpp/parameter_value.hpp"
30 #include "rclcpp/utilities.hpp"
31 #include "nav2_ros_common/tf2_factories.hpp"
32 #include "rclcpp/clock.hpp"
33 
34 namespace nav2_behavior_tree
35 {
36 
50 class IsGoalNearbyCondition : public BT::ConditionNode
51 {
52 public:
58  IsGoalNearbyCondition(const std::string & condition_name, const BT::NodeConfiguration & conf);
59 
60  IsGoalNearbyCondition() = delete;
61 
66  BT::NodeStatus tick() override;
67 
72  static BT::PortsList providedPorts()
73  {
74  return {
75  BT::InputPort<nav_msgs::msg::Path>("path", "Planned path"),
76  BT::InputPort<double>(
77  "proximity_threshold", 1.0,
78  "Proximity length (m) of the remaining path considered as a nearby"),
79  BT::InputPort<double>(
80  "max_robot_pose_search_dist", -1.0,
81  "Maximum forward integrated distance along the path "
82  "(starting from the last detected pose) to bound the search for the closest pose "
83  "to the robot. When set to negative value (default), whole path is searched every time"),
84  BT::InputPort<std::string>("global_frame", "Global frame"),
85  BT::InputPort<std::string>("robot_base_frame", "Robot base frame"),
86  };
87  }
88 
89 private:
90  nav2::LifecycleNode::SharedPtr node_;
91  rclcpp::Clock::SharedPtr clock_;
92  nav2::TransformBuffer::SharedPtr tf_buffer_;
93  nav_msgs::msg::Path path_;
94  std::vector<geometry_msgs::msg::PoseStamped>::iterator closest_pose_detection_begin_;
95  double transform_tolerance_;
96  double transform_staleness_threshold_;
97  std::string global_frame_;
98  std::string robot_base_frame_;
99 };
100 
101 } // namespace nav2_behavior_tree
102 
103 #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.