18 #include "nav2_util/geometry_utils.hpp"
19 #include "nav2_util/path_utils.hpp"
21 #include "nav2_behavior_tree/plugins/decorator/path_longer_on_approach.hpp"
23 namespace nav2_behavior_tree
27 const std::string & name,
28 const BT::NodeConfiguration & conf)
29 : BT::DecoratorNode(name, conf)
31 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
34 bool PathLongerOnApproach::isRobotInGoalProximity(
35 nav_msgs::msg::Path & old_path,
38 return nav2_util::geometry_utils::calculate_path_length(old_path, 0) < prox_leng;
41 bool PathLongerOnApproach::isNewPathLonger(
42 nav_msgs::msg::Path & new_path,
43 nav_msgs::msg::Path & old_path,
44 double & length_factor)
46 return nav2_util::geometry_utils::calculate_path_length(new_path, 0) >
47 length_factor * nav2_util::geometry_utils::calculate_path_length(
53 getInput(
"path", new_path_);
54 getInput(
"prox_len", prox_len_);
55 getInput(
"length_factor", length_factor_);
57 if (first_time_ ==
false) {
58 if (old_path_.poses.empty() || new_path_.poses.empty() ||
59 old_path_.poses.back().pose != new_path_.poses.back().pose)
64 setStatus(BT::NodeStatus::RUNNING);
68 if (nav2_util::isPathUpdated(new_path_, old_path_) && isRobotInGoalProximity(old_path_,
70 isNewPathLonger(new_path_, old_path_, length_factor_) && !first_time_)
72 const BT::NodeStatus child_state = child_node_->executeTick();
73 switch (child_state) {
74 case BT::NodeStatus::SKIPPED:
75 case BT::NodeStatus::RUNNING:
77 case BT::NodeStatus::SUCCESS:
78 case BT::NodeStatus::FAILURE:
79 old_path_ = new_path_;
83 old_path_ = new_path_;
84 return BT::NodeStatus::FAILURE;
87 old_path_ = new_path_;
89 return BT::NodeStatus::SUCCESS;
94 #include "behaviortree_cpp/bt_factory.h"
95 BT_REGISTER_NODES(factory)
A BT::DecoratorNode that ticks its child every time when the length of the new path is smaller than t...
PathLongerOnApproach(const std::string &name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::PathLongerOnApproach.
BT::NodeStatus tick() override
The main override required by a BT action.