Nav2 Navigation Stack - jazzy  jazzy
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/decorator_node.h"
25 #include "behaviortree_cpp/json_export.h"
26 #include "nav2_behavior_tree/json_utils.hpp"
27 #include "rclcpp/rclcpp.hpp"
28 
29 namespace nav2_behavior_tree
30 {
31 
43 class PathLongerOnApproach : public BT::DecoratorNode
44 {
45 public:
52  const std::string & name,
53  const BT::NodeConfiguration & conf);
54 
59  static BT::PortsList providedPorts()
60  {
61  // Register JSON definitions for the types used in the ports
62  BT::RegisterJsonDefinition<nav_msgs::msg::Path>();
63 
64  return {
65  BT::InputPort<nav_msgs::msg::Path>("path", "Planned Path"),
66  BT::InputPort<double>(
67  "prox_len", 3.0,
68  "Proximity length (m) for the path to be longer on approach"),
69  BT::InputPort<double>(
70  "length_factor", 2.0,
71  "Length multiplication factor to check if the path is significantly longer"),
72  };
73  }
74 
79  BT::NodeStatus tick() override;
80 
81 private:
88  bool isPathUpdated(
89  nav_msgs::msg::Path & new_path,
90  nav_msgs::msg::Path & old_path);
91 
98  bool isRobotInGoalProximity(
99  nav_msgs::msg::Path & old_path,
100  double & prox_leng);
101 
109  bool isNewPathLonger(
110  nav_msgs::msg::Path & new_path,
111  nav_msgs::msg::Path & old_path,
112  double & length_factor);
113 
114 private:
115  nav_msgs::msg::Path new_path_;
116  nav_msgs::msg::Path old_path_;
117  double prox_len_ = std::numeric_limits<double>::max();
118  double length_factor_ = std::numeric_limits<double>::max();
119  rclcpp::Node::SharedPtr node_;
120  bool first_time_ = true;
121 };
122 
123 } // namespace nav2_behavior_tree
124 
125 #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.