@@ -30,7 +30,8 @@ namespace nav2_rotation_shim_controller
3030RotationShimController::RotationShimController ()
3131: lp_loader_(" nav2_core" , " nav2_core::Controller" ),
3232 primary_controller_ (nullptr ),
33- path_updated_(false )
33+ path_updated_(false ),
34+ in_rotation_(false )
3435{
3536}
3637
@@ -53,7 +54,7 @@ void RotationShimController::configure(
5354 nav2_util::declare_parameter_if_not_declared (
5455 node, plugin_name_ + " .angular_dist_threshold" , rclcpp::ParameterValue (0.785 )); // 45 deg
5556 nav2_util::declare_parameter_if_not_declared (
56- node, plugin_name_ + " .angular_disengage_threshold" , rclcpp::ParameterValue (0.785 / 3.0 )); // 15 deg
57+ node, plugin_name_ + " .angular_disengage_threshold" , rclcpp::ParameterValue (0.785 ));
5758 nav2_util::declare_parameter_if_not_declared (
5859 node, plugin_name_ + " .forward_sampling_distance" , rclcpp::ParameterValue (0.5 ));
5960 nav2_util::declare_parameter_if_not_declared (
@@ -68,9 +69,7 @@ void RotationShimController::configure(
6869 node, plugin_name_ + " .rotate_to_goal_heading" , rclcpp::ParameterValue (false ));
6970
7071 node->get_parameter (plugin_name_ + " .angular_dist_threshold" , angular_dist_threshold_);
71- angular_dist_threshold_param_ = angular_dist_threshold_;
72- node->get_parameter (
73- plugin_name_ + " .angular_disengage_threshold" , angular_disengage_threshold_);
72+ node->get_parameter (plugin_name_ + " .angular_disengage_threshold" , angular_disengage_threshold_);
7473 node->get_parameter (plugin_name_ + " .forward_sampling_distance" , forward_sampling_distance_);
7574 node->get_parameter (
7675 plugin_name_ + " .rotate_to_heading_angular_vel" ,
@@ -112,6 +111,7 @@ void RotationShimController::activate()
112111 plugin_name_.c_str ());
113112
114113 primary_controller_->activate ();
114+ in_rotation_ = false ;
115115
116116 auto node = node_.lock ();
117117 dyn_params_handler_ = node->add_on_set_parameters_callback (
@@ -195,11 +195,14 @@ geometry_msgs::msg::TwistStamped RotationShimController::computeVelocityCommands
195195
196196 double angular_distance_to_heading =
197197 std::atan2 (sampled_pt_base.position .y , sampled_pt_base.position .x );
198- if (fabs (angular_distance_to_heading) > angular_dist_threshold_) {
199- angular_dist_threshold_ = angular_disengage_threshold_;
198+
199+ double angular_thresh =
200+ in_rotation_ ? angular_disengage_threshold_ : angular_dist_threshold_;
201+ if (abs (angular_distance_to_heading) > angular_thresh) {
200202 RCLCPP_DEBUG (
201203 logger_,
202204 " Robot is not within the new path's rough heading, rotating to heading..." );
205+ in_rotation_ = true ;
203206 return computeRotateToHeadingCommand (angular_distance_to_heading, pose, velocity);
204207 } else {
205208 angular_dist_threshold_ = angular_dist_threshold_param_;
@@ -219,6 +222,7 @@ geometry_msgs::msg::TwistStamped RotationShimController::computeVelocityCommands
219222 }
220223
221224 // If at this point, use the primary controller to path track
225+ in_rotation_ = false ;
222226 return primary_controller_->computeVelocityCommands (pose, velocity, goal_checker);
223227}
224228
0 commit comments