feat(lane_route_core): zone deviation cost and graph/lattice completeness fixes (R2.12)
- Graph tier: add zone_deviation_cost (weight * ds * dev_deg/45) to compiled, query and shortcut edges, so aligned travel is preferred and a diagonal is only used where a straight move is not possible. - Drop the route_too_long rejection; its relaxed standability reference ignored heading continuity and discarded verified long routes. - Graph retries: skip duplicate candidates and block the edge pair nearest the verifier failure location. - Lattice: heading-sector guide field, zone-transition retry, finer-bin refinement before reporting lattice_approx_exhausted, analytic connector best-cost choice. The lattice plans with zone_deviation_weight 0. - lane_route_eval: zone_deviation_weight and time_limit_s keys, zone_dev_len_m / zone_dev_integral output. Sim config: random 300 scenes hook 224 vs 212, kit 199 vs 196; regress7 3416 = R2.11 baseline; independent recheck 0 violations; 128 tests pass.
This commit is contained in:
@@ -599,6 +599,28 @@ TEST_F(PlanRouteTest, WithTheFlowUsesTheStrictRung)
|
||||
EXPECT_EQ(result.info.rung_reasons.size(), 1u);
|
||||
}
|
||||
|
||||
TEST_F(PlanRouteTest, VerifiedPathSurvivesRelaxedReferenceLengthLimit)
|
||||
{
|
||||
// Even an unrealistically short reference is not proof that a verified trajectory is unusable.
|
||||
config_.suspicious_ratio = 0.1;
|
||||
config_.suspicious_margin_m = 0.0;
|
||||
config_.route_too_long_ratio = 0.1;
|
||||
config_.route_too_long_margin_m = 0.0;
|
||||
map_.finish(config_);
|
||||
const RouteRequest request{ pose(1.0, 1.5, 0.0), pose(14.0, 1.5, 0.0), {} };
|
||||
expectLegal(plan(request), request, config_);
|
||||
}
|
||||
|
||||
TEST(GraphRetry, RemembersExactConstructedCandidates)
|
||||
{
|
||||
detail::CandidateHistory history;
|
||||
Path path{{1.0, 2.0, 0.0, 0.0}, {2.0, 2.0, 0.0, 0.0}};
|
||||
EXPECT_FALSE(history.seenOrRemember(path));
|
||||
EXPECT_TRUE(history.seenOrRemember(path));
|
||||
path.back().yaw = 0.1;
|
||||
EXPECT_FALSE(history.seenOrRemember(path));
|
||||
}
|
||||
|
||||
TEST_F(PlanRouteTest, AgainstTheFlowFails)
|
||||
{
|
||||
map_.setDirection(100, 220, 1);
|
||||
@@ -1225,6 +1247,36 @@ TEST(Lattice, RejectsBlockedStartSpin)
|
||||
EXPECT_FALSE(space.spinLegal(request.start.x, request.start.y, 0.0, kPi/4.0));
|
||||
}
|
||||
|
||||
TEST(Lattice, FiniteBinnedSearchDoesNotClaimContinuousExhaustion)
|
||||
{
|
||||
LatticeTestGrid map(40, 40);
|
||||
std::fill(map.cost.begin(), map.cost.end(), kLethalCost);
|
||||
for (int y : {10, 30})
|
||||
for (int x : {10, 30})
|
||||
for (int dy = -5; dy <= 5; ++dy)
|
||||
for (int dx = -5; dx <= 5; ++dx)
|
||||
map.cost[static_cast<std::size_t>(y + dy) * map.width + x + dx] = kFreeSpace;
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.half_x_m = 0.1;
|
||||
config.half_y_m = 0.1;
|
||||
const RouteRequest request = latticeRequest(pose(0.525, 0.525, 0.0), pose(1.525, 1.525, 0.0));
|
||||
const GridRef grid = map.view();
|
||||
PlanInfo info;
|
||||
detail::LatticeMemory memory(32 * 1024 * 1024);
|
||||
detail::LatticeContext context{request, grid, config, 90.0, detail::Clock::now() + std::chrono::seconds(5), info, memory};
|
||||
detail::LatticeCSpace space(context);
|
||||
detail::LatticeField field(&memory);
|
||||
Path path;
|
||||
PathCheck check;
|
||||
bool pruned = false;
|
||||
EXPECT_FALSE(detail::searchLattice(context, space, field, &path, &check, 0.0, &pruned));
|
||||
EXPECT_EQ(info.lattice_reason, "lattice_approx_exhausted");
|
||||
const PlanResult result = map.plan(request, config);
|
||||
EXPECT_FALSE(result.ok);
|
||||
EXPECT_EQ(result.info.lattice_reason, "lattice_approx_exhausted");
|
||||
EXPECT_GE(result.info.lattice_refinement_attempts, 1u);
|
||||
}
|
||||
|
||||
TEST(Lattice, TimeoutAndCancel)
|
||||
{
|
||||
LatticeTestGrid map(120, 120);
|
||||
@@ -1486,6 +1538,165 @@ TEST(Lattice, FieldZoneMarginKeepsDiagonalStepsOffTheLimit)
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
}
|
||||
|
||||
TEST(Lattice, HeadingFieldRespectsSectorDirectionInAZone)
|
||||
{
|
||||
LatticeTestGrid map(24, 16);
|
||||
std::fill(map.direction.begin(), map.direction.end(), 1);
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.half_x_m = 0.03;
|
||||
config.half_y_m = 0.03;
|
||||
config.footprint_min_gap_m = 0.0;
|
||||
config.max_deviation_deg = 45.0;
|
||||
config.zone_transition_m = 0.0;
|
||||
const RouteRequest request = latticeRequest(pose(0.225, 0.425, 0.0), pose(0.925, 0.425, 0.0));
|
||||
const GridRef grid = map.view();
|
||||
PlanInfo info;
|
||||
detail::LatticeMemory memory(32 * 1024 * 1024);
|
||||
const auto deadline = detail::Clock::now() + std::chrono::seconds(5);
|
||||
detail::LatticeContext context{request, grid, config, 45.0, deadline, info, memory};
|
||||
detail::LatticeCSpace space(context);
|
||||
detail::LatticeField field(&memory);
|
||||
ASSERT_TRUE(detail::buildHeadingField(context, space, &field, deadline));
|
||||
const int x = static_cast<int>(request.start.x / grid.resolution) / field.heading_factor;
|
||||
const int y = static_cast<int>(request.start.y / grid.resolution) / field.heading_factor;
|
||||
const std::size_t state = (static_cast<std::size_t>(y) * field.heading_width + x) * 8;
|
||||
EXPECT_NE(field.heading_settled[state], 0u); // East is permitted.
|
||||
EXPECT_EQ(field.heading_settled[state + 4], 0u); // West cannot rotate into east inside this zone.
|
||||
}
|
||||
|
||||
TEST(Lattice, HeadingFieldAvoidsWrongWayFootprintAlongZoneBoundary)
|
||||
{
|
||||
LatticeTestGrid map(40, 30);
|
||||
for (int y = 7; y < 13; ++y)
|
||||
for (int x = 10; x < 30; ++x)
|
||||
map.direction[static_cast<std::size_t>(y) * map.width + x] = 5; // West.
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.half_x_m = 0.1; config.half_y_m = 0.15; config.footprint_min_gap_m = 0.0;
|
||||
config.max_deviation_deg = 45.0; config.zone_transition_m = 1.0;
|
||||
const RouteRequest request = latticeRequest(pose(0.225, 0.775, 0.0), pose(1.775, 0.775, 0.0));
|
||||
const GridRef grid = map.view();
|
||||
PlanInfo info;
|
||||
detail::LatticeMemory memory(32 * 1024 * 1024);
|
||||
const auto deadline = detail::Clock::now() + std::chrono::seconds(5);
|
||||
detail::LatticeContext context{request, grid, config, 45.0, deadline, info, memory};
|
||||
detail::LatticeCSpace space(context);
|
||||
detail::LatticeField field(&memory);
|
||||
ASSERT_TRUE(detail::buildHeadingField(context, space, &field, deadline));
|
||||
const int x = static_cast<int>(request.start.x / grid.resolution) / field.heading_factor;
|
||||
const int y = static_cast<int>(request.start.y / grid.resolution) / field.heading_factor;
|
||||
const std::size_t state = (static_cast<std::size_t>(y) * field.heading_width + x) * 8;
|
||||
ASSERT_NE(field.heading_settled[state], 0u);
|
||||
EXPECT_GT(field.heading_values[state], 1.55f + 0.025f);
|
||||
}
|
||||
|
||||
TEST(ZoneDeviation, SamplesDirectionAndValidatesWeight)
|
||||
{
|
||||
LatticeTestGrid map(120, 120);
|
||||
std::fill(map.direction.begin(), map.direction.end(), 3);
|
||||
const GridRef grid = map.view();
|
||||
const ZoneDeviation diagonal = lineZoneDeviation({1.0, 1.0}, {3.0, 3.0}, grid);
|
||||
EXPECT_NEAR(diagonal.deviated_length_m, std::sqrt(8.0), 1e-10);
|
||||
EXPECT_NEAR(diagonal.integral_deg_m, 45.0 * std::sqrt(8.0), 1e-8);
|
||||
EXPECT_NEAR(lineZoneDeviation({2.0, 1.0}, {2.0, 4.0}, grid).integral_deg_m, 0.0, 1e-10);
|
||||
PlannerConfig config;
|
||||
EXPECT_DOUBLE_EQ(config.zone_deviation_weight, 2.0);
|
||||
config.zone_deviation_weight = -1.0;
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
config.zone_deviation_weight = std::numeric_limits<double>::quiet_NaN();
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
}
|
||||
|
||||
TEST(ZoneDeviation, NorthLanePreferredAcrossZoneInterior)
|
||||
{
|
||||
LatticeTestGrid map(300, 320);
|
||||
for (int y = 80; y < 240; ++y)
|
||||
for (int x = 20; x < 280; ++x)
|
||||
map.direction[static_cast<std::size_t>(y) * map.width + x] = 3;
|
||||
PlannerConfig config = defaultConfig();
|
||||
config.max_deviation_deg = 45.0;
|
||||
config.deviation_ladder_deg.clear();
|
||||
config.zone_deviation_weight = 20.0;
|
||||
CoarseGraph coarse;
|
||||
coarse.lanes.push_back({2, {5.0, 4.0}, {5.0, 12.0}, 8.0, 0.0});
|
||||
const GridRef grid = map.view();
|
||||
const GraphProvider provider = [&](double limit) {
|
||||
return std::make_shared<const CompiledGraph>(compileGraph(coarse, grid, grid.cost, limit, config, RidgeBackend{}));
|
||||
};
|
||||
const RouteRequest request{pose(5.0, 1.5, kPi/2), pose(7.0, 14.5, kPi/2), {}};
|
||||
const PlanResult result = planRoute(provider, request, grid, config, RidgeBackend{});
|
||||
ASSERT_TRUE(result.ok) << result.info.reason;
|
||||
EXPECT_TRUE(result.check.valid);
|
||||
double inside = 0.0, aligned = 0.0;
|
||||
std::vector<std::pair<double, bool>> visit;
|
||||
const auto finish_visit = [&]() {
|
||||
double length = 0.0, position = 0.0;
|
||||
for (const auto& sample : visit) length += sample.first;
|
||||
for (const auto& sample : visit)
|
||||
{
|
||||
const double part = std::max(0.0, std::min(position + sample.first, length - 1.0) - std::max(position, 1.0));
|
||||
inside += part;
|
||||
if (sample.second) aligned += part;
|
||||
position += sample.first;
|
||||
}
|
||||
visit.clear();
|
||||
};
|
||||
for (std::size_t i = 1; i < result.path.size(); ++i)
|
||||
{
|
||||
const auto& a = result.path[i-1];
|
||||
const auto& b = result.path[i];
|
||||
const double ds = std::hypot(b.x-a.x, b.y-a.y);
|
||||
if (ds < 1e-10) continue;
|
||||
const int count = std::max(1, static_cast<int>(std::ceil(ds / (grid.resolution * 0.5))));
|
||||
const bool follows = std::abs(wrapAngle(std::atan2(b.y-a.y, b.x-a.x)-kPi/2)) <= 3.0*kPi/180.0;
|
||||
for (int j = 0; j < count; ++j)
|
||||
{
|
||||
const double t = (j + 0.5) / count;
|
||||
const double x = a.x + (b.x-a.x)*t, y = a.y + (b.y-a.y)*t;
|
||||
if (x >= 1.0 && x < 14.0 && y >= 4.0 && y < 12.0) visit.emplace_back(ds / count, follows);
|
||||
else if (!visit.empty()) finish_visit();
|
||||
}
|
||||
}
|
||||
if (!visit.empty()) finish_visit();
|
||||
ASSERT_GT(inside, 5.0);
|
||||
EXPECT_GE(aligned / inside, 0.9);
|
||||
|
||||
// With the cost disabled the direct, diagonal shortcut is the old shortest-path choice.
|
||||
config.zone_deviation_weight = 0.0;
|
||||
const PlanResult old = planRoute(provider, request, grid, config, RidgeBackend{});
|
||||
ASSERT_TRUE(old.ok) << old.info.reason;
|
||||
double old_deviated = 0.0;
|
||||
for (std::size_t i = 1; i < old.path.size(); ++i)
|
||||
old_deviated += lineZoneDeviation({old.path[i-1].x, old.path[i-1].y}, {old.path[i].x, old.path[i].y}, grid).deviated_length_m;
|
||||
EXPECT_GT(old_deviated, 5.0);
|
||||
}
|
||||
|
||||
TEST(ZoneDeviation, DiagonalRemainsLegalAndZeroMatchesUnsetOnAlignedPath)
|
||||
{
|
||||
LatticeTestGrid map(120, 120);
|
||||
std::fill(map.direction.begin(), map.direction.end(), 1);
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.max_deviation_deg = 45.0;
|
||||
config.deviation_ladder_deg.clear();
|
||||
const RouteRequest diagonal = latticeRequest(pose(1.025, 1.025, kPi/4), pose(3.025, 3.025, kPi/4));
|
||||
const PlanResult positive = map.plan(diagonal, config);
|
||||
ASSERT_TRUE(positive.ok) << positive.info.reason;
|
||||
EXPECT_TRUE(positive.check.valid);
|
||||
const RouteRequest aligned = latticeRequest(pose(1.025, 2.025, 0.0), pose(4.025, 2.025, 0.0));
|
||||
const PlanResult unset = map.plan(aligned, config); // Default 2.0; the aligned path has no deviation cost.
|
||||
config.zone_deviation_weight = 0.0;
|
||||
const PlanResult zero = map.plan(aligned, config);
|
||||
ASSERT_TRUE(unset.ok) << unset.info.reason;
|
||||
ASSERT_EQ(zero.info.reason, unset.info.reason);
|
||||
ASSERT_EQ(zero.path.size(), unset.path.size());
|
||||
for (std::size_t i = 0; i < zero.path.size(); ++i)
|
||||
{
|
||||
EXPECT_DOUBLE_EQ(zero.path[i].x, unset.path[i].x);
|
||||
EXPECT_DOUBLE_EQ(zero.path[i].y, unset.path[i].y);
|
||||
EXPECT_DOUBLE_EQ(zero.path[i].yaw, unset.path[i].yaw);
|
||||
EXPECT_DOUBLE_EQ(zero.path[i].curvature, unset.path[i].curvature);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Lattice, AlternateFieldValidation)
|
||||
{
|
||||
PlannerConfig config = latticeConfig();
|
||||
@@ -2466,6 +2677,9 @@ TEST(FootprintZones, OppositeZoneAcrossNarrowGapIsRejected)
|
||||
const PathCheck check = verifyPath(path, grid, 0.01, config);
|
||||
EXPECT_FALSE(check.valid);
|
||||
EXPECT_GT(check.zone_violations, 0);
|
||||
EXPECT_TRUE(check.has_failure_location);
|
||||
EXPECT_GE(check.failure_location.x, 1.0);
|
||||
EXPECT_LE(check.failure_location.x, 4.0);
|
||||
RouteRequest request = latticeRequest(pose(4.0, 1.0, kPi), pose(1.0, 1.0, kPi));
|
||||
PlanInfo info;
|
||||
const auto deadline = detail::Clock::now() + std::chrono::seconds(10);
|
||||
@@ -2661,10 +2875,11 @@ TEST(FootprintZones, SideEntryUsesPathDistanceAndZeroDisablesTransition)
|
||||
detail::LatticeMemory memory(16 * 1024 * 1024);
|
||||
detail::LatticeContext context{request, grid, config, 10.0, deadline, info, memory};
|
||||
detail::LatticeCSpace space(context);
|
||||
// The lattice keeps the strict per-pose rule (see LatticeCSpace::zonePoseFree): this transition pose is legal on the
|
||||
// whole path above but not as a lattice state, so lattice paths always satisfy the path rule.
|
||||
EXPECT_FALSE(space.poseFree(path[69].x, path[69].y, path[69].yaw));
|
||||
// The retry must retain a state on a legal side entry; the whole-path verifier enforces the transition distance.
|
||||
context.allow_zone_transition = true;
|
||||
EXPECT_TRUE(space.poseFree(path[69].x, path[69].y, path[69].yaw));
|
||||
config.zone_transition_m = 0.0;
|
||||
EXPECT_FALSE(space.poseFree(path[69].x, path[69].y, path[69].yaw));
|
||||
const PathCheck blocked = verifyPath(path, grid, 10.0, config);
|
||||
EXPECT_FALSE(blocked.valid);
|
||||
EXPECT_GT(blocked.zone_violations, 0);
|
||||
|
||||
Reference in New Issue
Block a user