Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
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_MPPI_CONTROLLER__TOOLS__PATH_HANDLER_HPP_
18 #define NAV2_MPPI_CONTROLLER__TOOLS__PATH_HANDLER_HPP_
19 
20 #include <vector>
21 #include <utility>
22 #include <string>
23 #include <memory>
24 
25 #include "rclcpp_lifecycle/lifecycle_node.hpp"
26 #include "tf2_ros/buffer.h"
27 #include "geometry_msgs/msg/pose_stamped.hpp"
28 #include "nav_msgs/msg/path.hpp"
29 #include "builtin_interfaces/msg/time.hpp"
30 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
31 #include "nav2_util/geometry_utils.hpp"
32 
33 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
34 
35 namespace mppi
36 {
37 
38 using PathIterator = std::vector<geometry_msgs::msg::PoseStamped>::iterator;
39 using PathRange = std::pair<PathIterator, PathIterator>;
40 
47 {
48 public:
52  PathHandler() = default;
53 
57  ~PathHandler() = default;
58 
67  void initialize(
68  rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string & name,
69  std::shared_ptr<nav2_costmap_2d::Costmap2DROS>,
70  std::shared_ptr<tf2_ros::Buffer>, ParametersHandler *);
71 
76  void setPath(const nav_msgs::msg::Path & plan);
77 
82  nav_msgs::msg::Path & getPath();
83 
90  nav_msgs::msg::Path transformPath(const geometry_msgs::msg::PoseStamped & robot_pose);
91 
97  geometry_msgs::msg::PoseStamped getTransformedGoal(const builtin_interfaces::msg::Time & stamp);
98 
99 protected:
107  bool transformPose(
108  const std::string & frame, const geometry_msgs::msg::PoseStamped & in_pose,
109  geometry_msgs::msg::PoseStamped & out_pose) const;
110 
115  double getMaxCostmapDist();
116 
122  geometry_msgs::msg::PoseStamped
123  transformToGlobalPlanFrame(const geometry_msgs::msg::PoseStamped & pose);
124 
131  std::pair<nav_msgs::msg::Path, PathIterator> getGlobalPlanConsideringBoundsInCostmapFrame(
132  const geometry_msgs::msg::PoseStamped & global_pose);
133 
139  void prunePlan(nav_msgs::msg::Path & plan, const PathIterator end);
140 
146  bool isWithinInversionTolerances(const geometry_msgs::msg::PoseStamped & robot_pose);
147 
148  std::string name_;
149  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_;
150  std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
151  ParametersHandler * parameters_handler_;
152 
153  nav_msgs::msg::Path global_plan_;
154  nav_msgs::msg::Path global_plan_up_to_inversion_;
155  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
156 
157  double max_robot_pose_search_dist_{0};
158  double prune_distance_{0};
159  double transform_tolerance_{0};
160  float inversion_xy_tolerance_{0.2};
161  float inversion_yaw_tolerance{0.4};
162  bool enforce_path_inversion_{false};
163  unsigned int inversion_locale_{0u};
164 };
165 } // namespace mppi
166 
167 #endif // NAV2_MPPI_CONTROLLER__TOOLS__PATH_HANDLER_HPP_
Handles getting parameters and dynamic parmaeter changes.
Manager of incoming reference paths for transformation and processing.
bool isWithinInversionTolerances(const geometry_msgs::msg::PoseStamped &robot_pose)
Check if the robot pose is within the set inversion tolerances.
std::pair< nav_msgs::msg::Path, PathIterator > getGlobalPlanConsideringBoundsInCostmapFrame(const geometry_msgs::msg::PoseStamped &global_pose)
Get global plan within window of the local costmap size.
nav_msgs::msg::Path & getPath()
Get reference path.
void setPath(const nav_msgs::msg::Path &plan)
Set new reference path.
double getMaxCostmapDist()
Get largest dimension of costmap (radially)
geometry_msgs::msg::PoseStamped getTransformedGoal(const builtin_interfaces::msg::Time &stamp)
Get the global goal pose transformed to the local frame.
PathHandler()=default
Constructor for mppi::PathHandler.
~PathHandler()=default
Destructor for mppi::PathHandler.
void prunePlan(nav_msgs::msg::Path &plan, const PathIterator end)
Prune a path to only interesting portions.
bool transformPose(const std::string &frame, const geometry_msgs::msg::PoseStamped &in_pose, geometry_msgs::msg::PoseStamped &out_pose) const
Transform a pose to another frame.
void initialize(rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string &name, std::shared_ptr< nav2_costmap_2d::Costmap2DROS >, std::shared_ptr< tf2_ros::Buffer >, ParametersHandler *)
Initialize path handler on bringup.
nav_msgs::msg::Path transformPath(const geometry_msgs::msg::PoseStamped &robot_pose)
transform global plan to local applying constraints, then prune global plan
geometry_msgs::msg::PoseStamped transformToGlobalPlanFrame(const geometry_msgs::msg::PoseStamped &pose)
Transform a pose to the global reference frame.