Skip to content

Commit d370ca3

Browse files
authored
Conserve curvature with LIMIT action (#5255)
* Conserve curvature with LIMIT action Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com> * fix format Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com> * fix test Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com> --------- Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
1 parent 792bcac commit d370ca3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

‎nav2_collision_monitor/src/collision_monitor_node.cpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,17 @@ bool CollisionMonitor::processStopSlowdownLimit(
548548
const double linear_vel = std::hypot(velocity.x, velocity.y); // absolute
549549
Velocity safe_vel;
550550
double ratio = 1.0;
551+
552+
// Calculate the most restrictive ratio to preserve curvature
551553
if (linear_vel != 0.0) {
552-
ratio = std::clamp(polygon->getLinearLimit() / linear_vel, 0.0, 1.0);
554+
ratio = std::min(ratio, polygon->getLinearLimit() / linear_vel);
555+
}
556+
if (velocity.tw != 0.0) {
557+
ratio = std::min(ratio, polygon->getAngularLimit() / std::abs(velocity.tw));
553558
}
554-
safe_vel.x = velocity.x * ratio;
555-
safe_vel.y = velocity.y * ratio;
556-
safe_vel.tw = std::clamp(
557-
velocity.tw, -polygon->getAngularLimit(), polygon->getAngularLimit());
559+
ratio = std::clamp(ratio, 0.0, 1.0);
560+
// Apply the same ratio to all components to preserve curvature
561+
safe_vel = velocity * ratio;
558562
// Check that currently calculated velocity is safer than
559563
// chosen for previous shapes one
560564
if (safe_vel < robot_action.req_vel) {

‎nav2_collision_monitor/test/collision_monitor_node_test.cpp‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,12 @@ TEST_F(Tester, testProcessStopSlowdownLimit)
821821
publishCmdVel(0.5, 0.2, 0.1);
822822
ASSERT_TRUE(waitCmdVel(500ms));
823823
const double speed = std::sqrt(0.5 * 0.5 + 0.2 * 0.2);
824-
const double ratio = LINEAR_LIMIT / speed;
824+
const double linear_ratio = LINEAR_LIMIT / speed;
825+
const double angular_ratio = ANGULAR_LIMIT / 0.1;
826+
const double ratio = std::min(linear_ratio, angular_ratio);
825827
ASSERT_NEAR(cmd_vel_out_->linear.x, 0.5 * ratio, EPSILON);
826828
ASSERT_NEAR(cmd_vel_out_->linear.y, 0.2 * ratio, EPSILON);
827-
ASSERT_NEAR(cmd_vel_out_->angular.z, 0.09, EPSILON);
829+
ASSERT_NEAR(cmd_vel_out_->angular.z, 0.1 * ratio, EPSILON);
828830
ASSERT_TRUE(waitActionState(500ms));
829831
ASSERT_EQ(action_state_->action_type, LIMIT);
830832
ASSERT_EQ(action_state_->polygon_name, "Limit");
@@ -906,10 +908,12 @@ TEST_F(Tester, testPolygonSource)
906908
publishCmdVel(0.5, 0.2, 0.1);
907909
EXPECT_TRUE(waitCmdVel(500ms));
908910
const double speed = std::sqrt(0.5 * 0.5 + 0.2 * 0.2);
909-
const double ratio = LINEAR_LIMIT / speed;
911+
const double linear_ratio = LINEAR_LIMIT / speed;
912+
const double angular_ratio = ANGULAR_LIMIT / 0.1;
913+
const double ratio = std::min(linear_ratio, angular_ratio);
910914
EXPECT_NEAR(cmd_vel_out_->linear.x, 0.5 * ratio, EPSILON);
911915
EXPECT_NEAR(cmd_vel_out_->linear.y, 0.2 * ratio, EPSILON);
912-
EXPECT_NEAR(cmd_vel_out_->angular.z, 0.09, EPSILON);
916+
EXPECT_NEAR(cmd_vel_out_->angular.z, 0.1 * ratio, EPSILON);
913917
EXPECT_TRUE(waitActionState(500ms));
914918
EXPECT_EQ(action_state_->action_type, LIMIT);
915919
EXPECT_EQ(action_state_->polygon_name, "Limit");

0 commit comments

Comments
 (0)