Skip to content

Commit c22085e

Browse files
committed
merged with origin
2 parents 3118e91 + c280e3c commit c22085e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

‎nav2_rotation_shim_controller/include/nav2_rotation_shim_controller/nav2_rotation_shim_controller.hpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ class RotationShimController : public nav2_core::Controller
172172
nav2_core::Controller::Ptr primary_controller_;
173173
bool path_updated_;
174174
nav_msgs::msg::Path current_path_;
175-
double forward_sampling_distance_, angular_dist_threshold_, angular_dist_threshold_param_;
176-
double angular_disengage_threshold_;
175+
double forward_sampling_distance_, angular_dist_threshold_, angular_disengage_threshold_;
177176
double rotate_to_heading_angular_vel_, max_angular_accel_;
178177
double control_duration_, simulate_ahead_time_;
179-
bool rotate_to_goal_heading_;
178+
bool rotate_to_goal_heading_, in_rotation_;
180179

181180
// Dynamic parameters handler
182181
std::mutex mutex_;

‎nav2_rotation_shim_controller/src/nav2_rotation_shim_controller.cpp‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ namespace nav2_rotation_shim_controller
3030
RotationShimController::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

Comments
 (0)