Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
feasible_path_handler.hpp
1 // Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov
2 // Copyright (c) 2023 Dexory
3 // Copyright (c) 2023 Open Navigation LLC
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef NAV2_CONTROLLER__PLUGINS__FEASIBLE_PATH_HANDLER_HPP_
18 #define NAV2_CONTROLLER__PLUGINS__FEASIBLE_PATH_HANDLER_HPP_
19 
20 #include <string>
21 #include <vector>
22 #include <memory>
23 #include <utility>
24 #include "nav2_core/path_handler.hpp"
25 #include "nav2_ros_common/lifecycle_node.hpp"
26 #include "nav2_ros_common/tf2_factories.hpp"
27 
28 namespace nav2_controller
29 {
38 {
39 public:
43  FeasiblePathHandler() = default;
44 
49 
58  void initialize(
59  const nav2::LifecycleNode::WeakPtr & parent,
60  const rclcpp::Logger & logger,
61  const std::string & plugin_name,
62  const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros,
63  nav2::TransformBuffer::SharedPtr tf) override;
64 
69  void setPlan(const nav_msgs::msg::Path & path) override;
70 
79  nav2_core::PathSegment findPlanSegment(
80  const geometry_msgs::msg::PoseStamped & pose) override;
81 
88  nav_msgs::msg::Path transformLocalPlan(
89  const nav2_core::PathIterator & closest_point,
90  const nav2_core::PathIterator & pruned_plan_end) override;
91 
97  geometry_msgs::msg::PoseStamped getTransformedGoal(
98  const builtin_interfaces::msg::Time & stamp) override;
99 
104  nav_msgs::msg::Path getPlan() {return global_plan_;}
105 
106 protected:
112  geometry_msgs::msg::PoseStamped transformToGlobalPlanFrame(
113  const geometry_msgs::msg::PoseStamped & pose);
114 
119  double getCostmapMaxExtent() const;
120 
126  bool isWithinInversionTolerances(const geometry_msgs::msg::PoseStamped & robot_pose);
127 
133  void prunePlan(nav_msgs::msg::Path & plan, const nav2_core::PathIterator end);
134 
135  // Dynamic parameters handler
136  std::mutex mutex_;
137  rclcpp::node_interfaces::PostSetParametersCallbackHandle::SharedPtr post_set_params_handler_;
138  rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr on_set_params_handler_;
139  nav2::LifecycleNode::WeakPtr node_;
140  rclcpp::Logger logger_ {rclcpp::get_logger("FeasiblePathHandler")};
141  std::string plugin_name_;
142  nav2::TransformBuffer::SharedPtr tf_;
143  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
144  nav_msgs::msg::Path global_plan_;
145  nav_msgs::msg::Path global_plan_up_to_constraint_;
146  geometry_msgs::msg::PoseStamped global_pose_;
147  unsigned int constraint_locale_{0u};
148  bool reject_unit_path_, enforce_path_inversion_, enforce_path_rotation_;
149  double max_robot_pose_search_dist_, transform_tolerance_, prune_distance_;
150  float inversion_xy_tolerance_, inversion_yaw_tolerance_, minimum_rotation_angle_;
151 
160  rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback(
161  const std::vector<rclcpp::Parameter> & parameters);
162 
169  void updateParametersCallback(const std::vector<rclcpp::Parameter> & parameters);
170 };
171 } // namespace nav2_controller
172 
173 #endif // NAV2_CONTROLLER__PLUGINS__FEASIBLE_PATH_HANDLER_HPP_
This plugin manages the global plan by clipping it to the local segment, typically bounded by the loc...
~FeasiblePathHandler()
Destroy the Feasible Path Handler object.
void prunePlan(nav_msgs::msg::Path &plan, const nav2_core::PathIterator end)
Prune a path to only interesting portions.
nav_msgs::msg::Path transformLocalPlan(const nav2_core::PathIterator &closest_point, const nav2_core::PathIterator &pruned_plan_end) override
Transforms a predefined segment of the global plan into the costmap global frame.
bool isWithinInversionTolerances(const geometry_msgs::msg::PoseStamped &robot_pose)
Check if the robot pose is within the set inversion tolerances.
geometry_msgs::msg::PoseStamped transformToGlobalPlanFrame(const geometry_msgs::msg::PoseStamped &pose)
Transform a pose to the global reference frame.
nav_msgs::msg::Path getPlan()
Gets the global plan.
FeasiblePathHandler()=default
Construct a new Feasible Path Handler object.
void setPlan(const nav_msgs::msg::Path &path) override
Set new reference plan.
void updateParametersCallback(const std::vector< rclcpp::Parameter > &parameters)
Apply parameter updates after validation This callback is executed when parameters have been successf...
geometry_msgs::msg::PoseStamped getTransformedGoal(const builtin_interfaces::msg::Time &stamp) override
Get the global goal pose transformed to the costmap global frame.
rcl_interfaces::msg::SetParametersResult validateParameterUpdatesCallback(const std::vector< rclcpp::Parameter > &parameters)
Validate incoming parameter updates before applying them. This callback is triggered when one or more...
nav2_core::PathSegment findPlanSegment(const geometry_msgs::msg::PoseStamped &pose) override
Determines the portion of the global plan to be used for local control. This function locates the sta...
void initialize(const nav2::LifecycleNode::WeakPtr &parent, const rclcpp::Logger &logger, const std::string &plugin_name, const std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros, nav2::TransformBuffer::SharedPtr tf) override
Initialize parameters.
Function-object for handling the path from Planner Server.