Skip to content

Commit 600a1d3

Browse files
committed
Use angular acceleration te acelerate / decelerate
Signed-off-by: Alberto Tudela <ajtudela@gmail.com>
1 parent 46264b7 commit 600a1d3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

nav2_docking/opennav_docking/src/controller.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ geometry_msgs::msg::Twist Controller::computeRotateToHeadingCommand(
139139
current_velocity.angular.z + rotate_to_heading_max_angular_accel_ * dt;
140140
cmd_vel.angular.z =
141141
std::clamp(angular_vel, min_feasible_angular_speed, max_feasible_angular_speed);
142+
143+
// Check if we need to slow down to avoid overshooting
144+
double max_vel_to_stop =
145+
std::sqrt(2 * rotate_to_heading_max_angular_accel_ * fabs(angular_distance_to_heading));
146+
if (fabs(cmd_vel.angular.z) > max_vel_to_stop) {
147+
cmd_vel.angular.z = sign * max_vel_to_stop;
148+
}
149+
142150
return cmd_vel;
143151
}
144152

nav2_docking/opennav_docking/test/test_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ TEST(ControllerTests, RotateToHeading) {
603603
cmd_vel =
604604
controller->computeRotateToHeadingCommand(angular_distance_to_heading, current_velocity, dt);
605605
EXPECT_DOUBLE_EQ(cmd_vel.linear.x, 0.0);
606-
EXPECT_DOUBLE_EQ(cmd_vel.angular.z, -rotate_to_heading_max_angular_accel * dt);
606+
EXPECT_DOUBLE_EQ(cmd_vel.angular.z, 0.0);
607607

608608
controller.reset();
609609
}

0 commit comments

Comments
 (0)