Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
dwb_local_planner.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef DWB_CORE__DWB_LOCAL_PLANNER_HPP_
36 #define DWB_CORE__DWB_LOCAL_PLANNER_HPP_
37 
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 #include "nav2_core/controller.hpp"
43 #include "nav2_core/goal_checker.hpp"
44 #include "dwb_core/publisher.hpp"
45 #include "dwb_core/trajectory_critic.hpp"
46 #include "dwb_core/trajectory_generator.hpp"
47 #include "geometry_msgs/msg/pose_stamped.hpp"
48 #include "nav_2d_msgs/msg/twist2_d_stamped.hpp"
49 #include "rclcpp/rclcpp.hpp"
50 #include "rclcpp_lifecycle/lifecycle_node.hpp"
51 #include "pluginlib/class_loader.hpp"
52 #include "pluginlib/class_list_macros.hpp"
53 #include "nav2_ros_common/tf2_factories.hpp"
54 
55 namespace dwb_core
56 {
57 
63 {
64 public:
69 
70  void configure(
71  const nav2::LifecycleNode::WeakPtr & parent,
72  std::string name, nav2::TransformBuffer::SharedPtr tf,
73  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) override;
74 
75  virtual ~DWBLocalPlanner() {}
76 
80  void activate() override;
81 
85  void deactivate() override;
86 
90  void cleanup() override;
91 
96  void newPathReceived(const nav_msgs::msg::Path & raw_global_path) override;
97 
113  geometry_msgs::msg::TwistStamped computeVelocityCommands(
114  const geometry_msgs::msg::PoseStamped & pose,
115  const geometry_msgs::msg::Twist & velocity,
116  nav2_core::GoalChecker * /*goal_checker*/,
117  const nav_msgs::msg::Path & transformed_global_plan,
118  const geometry_msgs::msg::PoseStamped & global_goal) override;
119 
131  virtual dwb_msgs::msg::TrajectoryScore scoreTrajectory(
132  const dwb_msgs::msg::Trajectory2D & traj,
133  double best_score = -1);
134 
149  virtual nav_2d_msgs::msg::Twist2DStamped computeVelocityCommands(
150  const geometry_msgs::msg::PoseStamped & pose,
151  const nav_2d_msgs::msg::Twist2D & velocity,
152  std::shared_ptr<dwb_msgs::msg::LocalPlanEvaluation> & results,
153  const nav_msgs::msg::Path & transformed_global_plan,
154  const geometry_msgs::msg::PoseStamped & global_goal);
155 
163  void setSpeedLimit(const double & speed_limit, const bool & percentage) override
164  {
165  if (traj_generator_) {
166  traj_generator_->setSpeedLimit(speed_limit, percentage);
167  }
168  }
169 
170 protected:
174  virtual dwb_msgs::msg::TrajectoryScore coreScoringAlgorithm(
175  const geometry_msgs::msg::Pose & pose,
176  const nav_2d_msgs::msg::Twist2D velocity,
177  std::shared_ptr<dwb_msgs::msg::LocalPlanEvaluation> & results);
178 
179  bool debug_trajectory_details_;
180 
187  std::string resolveCriticClassName(std::string base_name);
188 
193  virtual void loadCritics();
194 
195  nav2::LifecycleNode::WeakPtr node_;
196  rclcpp::Clock::SharedPtr clock_;
197  rclcpp::Logger logger_{rclcpp::get_logger("DWBLocalPlanner")};
198 
199  nav2::TransformBuffer::SharedPtr tf_;
200  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
201 
202  std::unique_ptr<DWBPublisher> pub_;
203  std::vector<std::string> default_critic_namespaces_;
204 
205  // Plugin handling
206  pluginlib::ClassLoader<TrajectoryGenerator> traj_gen_loader_;
207  TrajectoryGenerator::Ptr traj_generator_;
208 
209  pluginlib::ClassLoader<TrajectoryCritic> critic_loader_;
210  std::vector<TrajectoryCritic::Ptr> critics_;
211 
212  std::string dwb_plugin_name_;
213 
214  bool short_circuit_trajectory_evaluation_;
215 };
216 
217 } // namespace dwb_core
218 
219 #endif // DWB_CORE__DWB_LOCAL_PLANNER_HPP_
Plugin-based flexible controller.
void newPathReceived(const nav_msgs::msg::Path &raw_global_path) override
nav2_core newPathReceived - Receives a new plan from the Planner Server
geometry_msgs::msg::TwistStamped computeVelocityCommands(const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::Twist &velocity, nav2_core::GoalChecker *, const nav_msgs::msg::Path &transformed_global_plan, const geometry_msgs::msg::PoseStamped &global_goal) override
nav2_core computeVelocityCommands - calculates the best command given the current pose and velocity
virtual dwb_msgs::msg::TrajectoryScore coreScoringAlgorithm(const geometry_msgs::msg::Pose &pose, const nav_2d_msgs::msg::Twist2D velocity, std::shared_ptr< dwb_msgs::msg::LocalPlanEvaluation > &results)
Iterate through all the twists and find the best one.
void cleanup() override
Cleanup lifecycle node.
std::string resolveCriticClassName(std::string base_name)
try to resolve a possibly shortened critic name with the default namespaces and the suffix "Critic"
void deactivate() override
Deactivate lifecycle node.
void configure(const nav2::LifecycleNode::WeakPtr &parent, std::string name, nav2::TransformBuffer::SharedPtr tf, std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros) override
DWBLocalPlanner()
Constructor that brings up pluginlib loaders.
void setSpeedLimit(const double &speed_limit, const bool &percentage) override
Limits the maximum linear speed of the robot.
virtual dwb_msgs::msg::TrajectoryScore scoreTrajectory(const dwb_msgs::msg::Trajectory2D &traj, double best_score=-1)
Score a given command. Can be used for testing.
virtual void loadCritics()
Load the critic parameters from the namespace.
void activate() override
Activate lifecycle node.
controller interface that acts as a virtual base class for all controller plugins
Definition: controller.hpp:60
Function-object for checking whether a goal has been reached.