Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
path_longer_on_approach.hpp
1 // Copyright (c) 2022 Neobotix GmbH
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__DECORATOR__PATH_LONGER_ON_APPROACH_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__PATH_LONGER_ON_APPROACH_HPP_
17 
18 #include <string>
19 #include <memory>
20 #include <limits>
21 
22 #include "geometry_msgs/msg/pose_stamped.hpp"
23 #include "nav_msgs/msg/path.hpp"
24 #include "behaviortree_cpp_v3/decorator_node.h"
25 #include "rclcpp/rclcpp.hpp"
26 
27 namespace nav2_behavior_tree
28 {
29 
34 class PathLongerOnApproach : public BT::DecoratorNode
35 {
36 public:
43  const std::string & name,
44  const BT::NodeConfiguration & conf);
45 
50  static BT::PortsList providedPorts()
51  {
52  return {
53  BT::InputPort<nav_msgs::msg::Path>("path", "Planned Path"),
54  BT::InputPort<double>(
55  "prox_len", 3.0,
56  "Proximity length (m) for the path to be longer on approach"),
57  BT::InputPort<double>(
58  "length_factor", 2.0,
59  "Length multiplication factor to check if the path is significantly longer"),
60  };
61  }
62 
67  BT::NodeStatus tick() override;
68 
69 private:
76  bool isPathUpdated(
77  nav_msgs::msg::Path & new_path,
78  nav_msgs::msg::Path & old_path);
79 
86  bool isRobotInGoalProximity(
87  nav_msgs::msg::Path & old_path,
88  double & prox_leng);
89 
97  bool isNewPathLonger(
98  nav_msgs::msg::Path & new_path,
99  nav_msgs::msg::Path & old_path,
100  double & length_factor);
101 
102 private:
103  nav_msgs::msg::Path new_path_;
104  nav_msgs::msg::Path old_path_;
105  double prox_len_ = std::numeric_limits<double>::max();
106  double length_factor_ = std::numeric_limits<double>::max();
107  rclcpp::Node::SharedPtr node_;
108  bool first_time_ = true;
109 };
110 
111 } // namespace nav2_behavior_tree
112 
113 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__DECORATOR__PATH_LONGER_ON_APPROACH_HPP_
A BT::DecoratorNode that ticks its child everytime when the length of the new path is smaller than th...
static BT::PortsList providedPorts()
Creates list of BT ports.
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.