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 
92 protected:
100  bool transformPose(
101  const std::string & frame, const geometry_msgs::msg::PoseStamped & in_pose,
102  geometry_msgs::msg::PoseStamped & out_pose) const;
103 
108  double getMaxCostmapDist();
109 
115  geometry_msgs::msg::PoseStamped
116  transformToGlobalPlanFrame(const geometry_msgs::msg::PoseStamped & pose);
117 
124  std::pair<nav_msgs::msg::Path, PathIterator> getGlobalPlanConsideringBoundsInCostmapFrame(
125  const geometry_msgs::msg::PoseStamped & global_pose);
126 
132  void prunePlan(nav_msgs::msg::Path & plan, const PathIterator end);
133 
139  bool isWithinInversionTolerances(const geometry_msgs::msg::PoseStamped & robot_pose);
140 
141  std::string name_;
142  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_;
143  std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
144  ParametersHandler * parameters_handler_;
145 
146  nav_msgs::msg::Path global_plan_;
147  nav_msgs::msg::Path global_plan_up_to_inversion_;
148  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
149 
150  double max_robot_pose_search_dist_{0};
151  double prune_distance_{0};
152  double transform_tolerance_{0};
153  float inversion_xy_tolerance_{0.2};
154  float inversion_yaw_tolerance{0.4};
155  bool enforce_path_inversion_{false};
156  unsigned int inversion_locale_{0u};
157 };
158 } // namespace mppi
159 
160 #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)
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.