Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
nav2_rotation_shim_controller.hpp
1 // Copyright (c) 2021 Samsung Research America
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_ROTATION_SHIM_CONTROLLER__NAV2_ROTATION_SHIM_CONTROLLER_HPP_
16 #define NAV2_ROTATION_SHIM_CONTROLLER__NAV2_ROTATION_SHIM_CONTROLLER_HPP_
17 
18 #include <string>
19 #include <vector>
20 #include <memory>
21 #include <algorithm>
22 #include <mutex>
23 #include <limits>
24 
25 #include "rclcpp/clock.hpp"
26 #include "rclcpp/logger.hpp"
27 #include "pluginlib/class_loader.hpp"
28 #include "pluginlib/class_list_macros.hpp"
29 #include "nav2_core/controller.hpp"
30 #include "nav2_core/controller_exceptions.hpp"
31 #include "nav2_costmap_2d/footprint_collision_checker.hpp"
32 #include "nav2_rotation_shim_controller/parameter_handler.hpp"
33 #include "nav2_ros_common/tf2_factories.hpp"
34 
35 namespace nav2_rotation_shim_controller
36 {
37 
43 {
44 public:
49 
53  ~RotationShimController() override = default;
54 
62  void configure(
63  const nav2::LifecycleNode::WeakPtr & parent,
64  std::string name, nav2::TransformBuffer::SharedPtr tf,
65  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros) override;
66 
70  void cleanup() override;
71 
75  void activate() override;
76 
80  void deactivate() override;
81 
91  geometry_msgs::msg::TwistStamped computeVelocityCommands(
92  const geometry_msgs::msg::PoseStamped & pose,
93  const geometry_msgs::msg::Twist & velocity,
94  nav2_core::GoalChecker * /*goal_checker*/,
95  const nav_msgs::msg::Path & transformed_global_plan,
96  const geometry_msgs::msg::PoseStamped & global_goal) override;
97 
102  void newPathReceived(const nav_msgs::msg::Path & raw_global_path) override;
103 
111  void setSpeedLimit(const double & speed_limit, const bool & percentage) override;
112 
116  void reset() override;
117 
118 protected:
125  geometry_msgs::msg::PoseStamped getSampledPathPt(
126  const geometry_msgs::msg::PoseStamped & global_goal);
127 
133  geometry_msgs::msg::Pose transformPoseToBaseFrame(const geometry_msgs::msg::PoseStamped & pt);
134 
142  geometry_msgs::msg::TwistStamped computeRotateToHeadingCommand(
143  const double & angular_distance,
144  const geometry_msgs::msg::PoseStamped & pose,
145  const geometry_msgs::msg::Twist & velocity);
146 
153  void isCollisionFree(
154  const geometry_msgs::msg::TwistStamped & cmd_vel,
155  const double & angular_distance_to_heading,
156  const geometry_msgs::msg::PoseStamped & pose);
157 
163  bool isGoalChanged(const geometry_msgs::msg::PoseStamped & goal);
164 
165  nav2::LifecycleNode::WeakPtr node_;
166  nav2::TransformBuffer::SharedPtr tf_;
167  std::string plugin_name_;
168  rclcpp::Logger logger_ {rclcpp::get_logger("RotationShimController")};
169  rclcpp::Clock::SharedPtr clock_;
170  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
171  std::unique_ptr<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>
172  collision_checker_;
173 
174  pluginlib::ClassLoader<nav2_core::Controller> lp_loader_;
175  nav2_core::Controller::Ptr primary_controller_;
176  bool path_updated_;
177  nav_msgs::msg::Path current_path_;
178  geometry_msgs::msg::PoseStamped current_goal_;
179  Parameters * params_;
180  bool in_rotation_;
181  double last_angular_vel_ = std::numeric_limits<double>::max();
182  std::unique_ptr<nav2_rotation_shim_controller::ParameterHandler> param_handler_;
183 };
184 
185 } // namespace nav2_rotation_shim_controller
186 
187 #endif // NAV2_ROTATION_SHIM_CONTROLLER__NAV2_ROTATION_SHIM_CONTROLLER_HPP_
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.
Rotate to rough path heading controller shim plugin.
void deactivate() override
Deactivate controller state machine.
geometry_msgs::msg::Pose transformPoseToBaseFrame(const geometry_msgs::msg::PoseStamped &pt)
Uses TF to find the location of the sampled path point in base frame.
geometry_msgs::msg::PoseStamped getSampledPathPt(const geometry_msgs::msg::PoseStamped &global_goal)
Finds the point on the path that is roughly the sampling point distance away from the robot for use....
void cleanup() override
Cleanup controller state machine.
geometry_msgs::msg::TwistStamped computeRotateToHeadingCommand(const double &angular_distance, const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::Twist &velocity)
Rotates the robot to the rough heading.
void activate() override
Activate controller state machine.
void setSpeedLimit(const double &speed_limit, const bool &percentage) override
Limits the maximum linear speed of the robot.
~RotationShimController() override=default
Destrructor for nav2_rotation_shim_controller::RotationShimController.
RotationShimController()
Constructor for nav2_rotation_shim_controller::RotationShimController.
bool isGoalChanged(const geometry_msgs::msg::PoseStamped &goal)
Checks if the goal has changed based on the given path.
void configure(const nav2::LifecycleNode::WeakPtr &parent, std::string name, nav2::TransformBuffer::SharedPtr tf, std::shared_ptr< nav2_costmap_2d::Costmap2DROS > costmap_ros) override
Configure controller state machine.
void isCollisionFree(const geometry_msgs::msg::TwistStamped &cmd_vel, const double &angular_distance_to_heading, const geometry_msgs::msg::PoseStamped &pose)
Checks if rotation is safe.
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
Compute the best command given the current pose and velocity.
void newPathReceived(const nav_msgs::msg::Path &raw_global_path) override
nav2_core newPathReceived - Receives a new plan from the Planner Server
void reset() override
Reset the state of the controller.