15 #ifndef NAV2_GRACEFUL_CONTROLLER__GRACEFUL_CONTROLLER_HPP_
16 #define NAV2_GRACEFUL_CONTROLLER__GRACEFUL_CONTROLLER_HPP_
25 #include "nav2_core/controller.hpp"
26 #include "nav2_costmap_2d/footprint_collision_checker.hpp"
27 #include "rclcpp/rclcpp.hpp"
28 #include "pluginlib/class_loader.hpp"
29 #include "pluginlib/class_list_macros.hpp"
30 #include "nav2_graceful_controller/parameter_handler.hpp"
31 #include "nav2_graceful_controller/smooth_control_law.hpp"
32 #include "nav2_graceful_controller/utils.hpp"
33 #include "nav2_ros_common/tf2_factories.hpp"
35 namespace nav2_graceful_controller
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;
92 const geometry_msgs::msg::PoseStamped & pose,
93 const geometry_msgs::msg::Twist & velocity,
95 const nav_msgs::msg::Path & transformed_global_plan,
96 const geometry_msgs::msg::PoseStamped & global_goal)
override;
102 void newPathReceived(
const nav_msgs::msg::Path & raw_global_path)
override;
111 void setSpeedLimit(
const double & speed_limit,
const bool & percentage)
override;
124 geometry_msgs::msg::PoseStamped & target_pose,
125 double dist_to_target,
126 nav_msgs::msg::Path & trajectory,
127 geometry_msgs::msg::TransformStamped & costmap_transform,
128 geometry_msgs::msg::TwistStamped & cmd_vel);
141 geometry_msgs::msg::PoseStamped & target_pose,
142 double dist_to_target,
144 nav_msgs::msg::Path & trajectory,
145 geometry_msgs::msg::TransformStamped & costmap_transform,
146 geometry_msgs::msg::TwistStamped & cmd_vel);
159 geometry_msgs::msg::PoseStamped & target_pose,
160 double dist_to_target,
161 geometry_msgs::msg::TransformStamped & costmap_transform,
163 nav_msgs::msg::Path & best_trajectory,
164 geometry_msgs::msg::TwistStamped & best_cmd_vel);
178 const geometry_msgs::msg::PoseStamped & motion_target,
179 const geometry_msgs::msg::TransformStamped & costmap_transform,
180 nav_msgs::msg::Path & trajectory,
181 geometry_msgs::msg::TwistStamped & cmd_vel,
201 const double & x,
const double & y,
const double & theta,
202 double inflation_scale = 1.0);
211 const nav_msgs::msg::Path & path,
212 geometry_msgs::msg::TransformStamped & costmap_transform);
220 const std::vector<geometry_msgs::msg::PoseStamped> & poses,
221 std::vector<double> & distances);
229 nav2::TransformBuffer::SharedPtr tf_buffer_;
230 std::string plugin_name_;
231 std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
232 std::unique_ptr<nav2_costmap_2d::FootprintCollisionChecker<nav2_costmap_2d::Costmap2D *>>
234 rclcpp::Logger logger_{rclcpp::get_logger(
"GracefulController")};
239 bool do_initial_rotation_;
241 std::optional<double> safe_approach_angle_;
243 nav2::Publisher<nav_msgs::msg::Path>::SharedPtr local_plan_pub_;
244 nav2::Publisher<geometry_msgs::msg::PoseStamped>::SharedPtr motion_target_pub_;
245 nav2::Publisher<visualization_msgs::msg::Marker>::SharedPtr slowdown_pub_;
246 std::unique_ptr<nav2_graceful_controller::ParameterHandler> param_handler_;
247 std::unique_ptr<nav2_graceful_controller::SmoothControlLaw> control_law_;
controller interface that acts as a virtual base class for all controller plugins
Function-object for checking whether a goal has been reached.
Graceful controller plugin.
void activate() override
Activate controller state machine.
~GracefulController() override=default
Destructor for nav2_graceful_controller::GracefulController.
void computeDistanceAlongPath(const std::vector< geometry_msgs::msg::PoseStamped > &poses, std::vector< double > &distances)
Compute the distance to each pose in a path.
bool validateTargetPose(geometry_msgs::msg::PoseStamped &target_pose, double dist_to_target, nav_msgs::msg::Path &trajectory, geometry_msgs::msg::TransformStamped &costmap_transform, geometry_msgs::msg::TwistStamped &cmd_vel)
Validate a given target pose for calculating command velocity.
bool validateTargetPoseOnApproach(geometry_msgs::msg::PoseStamped &target_pose, double dist_to_target, double dist_to_goal, nav_msgs::msg::Path &trajectory, geometry_msgs::msg::TransformStamped &costmap_transform, geometry_msgs::msg::TwistStamped &cmd_vel)
Validate a given target pose for calculating command velocity on approach to goal.
void deactivate() override
Deactivate controller state machine.
bool inCollision(const double &x, const double &y, const double &theta, double inflation_scale=1.0)
Checks if the robot is in collision.
bool findBestApproachTrajectory(geometry_msgs::msg::PoseStamped &target_pose, double dist_to_target, geometry_msgs::msg::TransformStamped &costmap_transform, double safety_cost, nav_msgs::msg::Path &best_trajectory, geometry_msgs::msg::TwistStamped &best_cmd_vel)
Find the best approach trajectory by searching multiple orientations.
bool simulateTrajectory(const geometry_msgs::msg::PoseStamped &motion_target, const geometry_msgs::msg::TransformStamped &costmap_transform, nav_msgs::msg::Path &trajectory, geometry_msgs::msg::TwistStamped &cmd_vel, bool backward)
Simulate trajectory calculating in every step the new velocity command based on a new curvature value...
GracefulController()=default
Constructor for nav2_graceful_controller::GracefulController.
geometry_msgs::msg::TwistStamped computeVelocityCommands(const geometry_msgs::msg::PoseStamped &pose, const geometry_msgs::msg::Twist &velocity, nav2_core::GoalChecker *goal_checker, 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 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 cleanup() override
Cleanup controller state machine.
geometry_msgs::msg::Twist rotateToTarget(double angle_to_target)
Rotate the robot to face the motion target with maximum angular velocity.
void newPathReceived(const nav_msgs::msg::Path &raw_global_path) override
nav2_core newPathReceived - Receives a new plan from the Planner Server
void setSpeedLimit(const double &speed_limit, const bool &percentage) override
Limits the maximum linear speed of the robot.
void validateOrientations(std::vector< geometry_msgs::msg::PoseStamped > &path)
Control law requires proper orientations, not all planners provide them.
double getMaxCost(const nav_msgs::msg::Path &path, geometry_msgs::msg::TransformStamped &costmap_transform)
Get the maximum cost of a path.