feat(env_monitor): snap điểm thoát sang ô free trước khi kết luận mất liên thông; bật lại kUnreachable

- CostToGoParams::target_snap / geometry/target_snap 0,5 m: T (2 m dọc plan) không free và lùi dọc
  plan không thoát thì dịch ngang sang ô free gần nhất (Target::kSnapped), arc_rest vẫn theo index;
  chỉ khi snap thất bại mới kBlockedExit. Run 6/9 10:15: mọi "unreachable" đều là T nằm trong vành
  0,48 m vì SBPL vẽ plan ôm mép vật cản giữa hành lang rộng 1,55 m — không phải mất liên thông.
- unreachable/action: recover, static_on 1,5 s.
- Test: grid_analysis +2 (plan ôm tường snap ra và có đường; cụm chắn ngang vẫn bịt với snap 0,5).

Sim 6/9 10:38: 0 cờ unreachable, 0 cờ oan, 2 mission tới goal, 2 detour đều của PRIEST.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xXjFjr2DQ6rhmhHSW4fk4
This commit is contained in:
2026-09-06 10:45:52 +07:00
parent 261cc20ad4
commit 62692838d6
8 changed files with 90 additions and 11 deletions

View File

@@ -348,6 +348,57 @@ TEST(GridAnalysisCostToGo, BlockedExitBacksOffAlongThePlanOrReportsBlocked)
EXPECT_NEAR(3.0, r.cost_to_go, 0.2);
}
TEST(GridAnalysisCostToGo, TargetHuggingAWallSnapsSidewaysInsteadOfBlocking)
{
// Run 6/9 10:15: SBPL vẽ plan ôm mép vật cản trong hành lang rộng — T (2 m phía trước) nằm trong vành 0,48 m dù
// hành lang thừa chỗ. Lùi dọc plan không thoát (cả đoạn ôm tường); snap ngang 0,5 m là ra ô free -> có đường.
nav_test_harness::FakeCostmap grid = makeGrid();
lethalLine(grid, 0.5, 0.45, 4.5, 0.45); // tường song song plan, cách 0,45 m < inscribed 0,48
GridScratch s;
ASSERT_TRUE(analyzeGrid(*grid.costmap(), kLethal, kInscribed, s));
const auto plan = linePlan(0.0, 4.0, 0.1);
CostToGoParams params;
params.exit_ahead = 2.0;
params.target_backoff = 0.5;
params.target_snap = 0.0;
CostToGoResult r = costToGo(plan, 0, 0.0, -0.3, params, PlanarTransform(), s);
ASSERT_TRUE(r.conclusive);
EXPECT_FALSE(r.reachable);
EXPECT_EQ(CostToGoResult::Target::kBlockedExit, r.target) << "bản cũ: ôm tường = 'đích bị bịt'";
params.target_snap = 0.5;
r = costToGo(plan, 0, 0.0, -0.3, params, PlanarTransform(), s);
ASSERT_TRUE(r.conclusive);
EXPECT_TRUE(r.reachable);
EXPECT_EQ(CostToGoResult::Target::kSnapped, r.target);
EXPECT_EQ(20u, r.target_index); // vẫn là pose plan ở 2 m
EXPECT_NEAR(2.0, r.arc_rest, 0.05); // arc_rest theo index, không theo ô snap
EXPECT_NEAR(4.0, r.cost_to_go, 0.3); // geo ~2 m tới ô snap + arc 2 m
}
TEST(GridAnalysisCostToGo, BlockerAcrossTheCorridorStaysBlockedWhenSnapCannotEscape)
{
// Cụm trụ chắn ngang: ô free gần nhất quanh T cách 0,78 m > target_snap 0,5 -> vẫn là đích bị bịt (unreachable
// thật, nổ sớm từ đất sạch). Snap rộng hơn (1,0) thì ra ô bên cạnh và có đường vòng.
nav_test_harness::FakeCostmap grid = makeGrid();
grid.setLethalCircle(2.0, 0.0, 0.3);
GridScratch s;
ASSERT_TRUE(analyzeGrid(*grid.costmap(), kLethal, kInscribed, s));
const auto plan = linePlan(0.0, 4.0, 0.1);
CostToGoParams params;
params.exit_ahead = 2.0;
params.target_backoff = 0.5;
params.target_snap = 0.5;
CostToGoResult r = costToGo(plan, 0, 0.0, 0.0, params, PlanarTransform(), s);
ASSERT_TRUE(r.conclusive);
EXPECT_FALSE(r.reachable);
EXPECT_EQ(CostToGoResult::Target::kBlockedExit, r.target);
params.target_snap = 1.0;
r = costToGo(plan, 0, 0.0, 0.0, params, PlanarTransform(), s);
ASSERT_TRUE(r.conclusive);
EXPECT_TRUE(r.reachable);
EXPECT_EQ(CostToGoResult::Target::kSnapped, r.target);
}
TEST(GridAnalysisCostToGo, RobotHuggingAnObstacleSnapsToTheNearestFreeCell)
{
nav_test_harness::FakeCostmap grid = makeGrid();