feat(lane_route): second heuristic field and diagonal zone margin (R2.10)

- lattice_alt_field_enabled (default false), lattice_alt_field_relax_m,
  lattice_alt_field_switch_fraction: when the search on the first field
  has not finished at the switch point, it restarts once on a field with
  no extra clearance and the alternate relax. Exhausted searches do not
  switch. PlanInfo/eval/debug line report field_pass.
- lattice_field_zone_margin_deg (default 0): diagonal field steps through
  a direction zone must stay that far inside the deviation limit; at
  exactly 45 deg the field otherwise follows a diagonal a turning robot
  cannot hold (sim M4, M7, 4a timed out even with 10 s).
- lane_route_eval compiles the graph with the live master when it holds
  preferred cells, as the plugin does.
- Measured 10/11 (sim settings, 10 s, margin 15, alternate on): regress7
  hook_150 1719, kit 1718, no query lost, independent recheck 0 bad.
This commit is contained in:
2026-11-10 13:42:23 +07:00
parent 1d26e29899
commit a4b655b74b
8 changed files with 160 additions and 10 deletions

View File

@@ -1457,6 +1457,80 @@ TEST(Lattice, GraphUnavailableFallsBackOnSameRung)
EXPECT_DOUBLE_EQ(result.info.rung_used_deg, 90.0);
}
TEST(Lattice, FieldZoneMarginKeepsDiagonalStepsOffTheLimit)
{
LatticeTestGrid map(100, 100);
std::fill(map.direction.begin(), map.direction.end(), 1); // One zone along +x everywhere.
PlannerConfig config = latticeConfig();
// The goal lies 45 deg off the zone direction: only diagonal steps reach it from the start.
const RouteRequest request = latticeRequest(pose(1.025, 1.025, kPi / 4.0), pose(2.025, 2.025, kPi / 4.0));
const GridRef grid = map.view();
const std::size_t start_cell = static_cast<std::size_t>(20) * map.width + 20;
const auto settled = [&](double margin_deg) {
config.lattice_field_zone_margin_deg = margin_deg;
PlanInfo info;
detail::LatticeMemory memory(16 * 1024 * 1024);
const auto deadline = detail::Clock::now() + std::chrono::seconds(10);
detail::LatticeContext context{ request, grid, config, 45.0, deadline, info, memory };
detail::LatticeField field(&memory);
EXPECT_TRUE(detail::buildLatticeField(context, &field, deadline));
EXPECT_EQ(field.factor, 1);
return field.settled[start_cell] != 0;
};
EXPECT_TRUE(settled(0.0)); // At 45 deg the plain field steps diagonally at the limit of the rule.
EXPECT_FALSE(settled(15.0)); // With the margin it may not.
config.lattice_field_zone_margin_deg = 45.0;
EXPECT_FALSE(config.validate().empty());
config.lattice_field_zone_margin_deg = -1.0;
EXPECT_FALSE(config.validate().empty());
}
TEST(Lattice, AlternateFieldValidation)
{
PlannerConfig config = latticeConfig();
config.lattice_alt_field_enabled = true;
EXPECT_TRUE(config.validate().empty());
config.lattice_alt_field_switch_fraction = 0.0;
EXPECT_FALSE(config.validate().empty());
config.lattice_alt_field_switch_fraction = 1.0;
EXPECT_FALSE(config.validate().empty());
config.lattice_alt_field_switch_fraction = 0.35;
config.lattice_alt_field_relax_m = -0.01;
EXPECT_FALSE(config.validate().empty());
config.lattice_alt_field_enabled = false; // Unused values are not checked.
EXPECT_TRUE(config.validate().empty());
}
TEST(Lattice, AlternateFieldTakesOverAfterTheSwitchPoint)
{
LatticeTestGrid map(120, 120);
PlannerConfig config = latticeConfig();
config.lattice_field_extra_clearance_m = 0.1; // The first field differs from the alternate one.
const RouteRequest request = latticeRequest(pose(1.0, 3.0, 0.0), pose(4.0, 3.0, 0.0));
const PlanResult primary = map.plan(request, config);
ASSERT_TRUE(primary.ok) << primary.info.reason;
EXPECT_EQ(primary.info.lattice_field_pass, "primary");
// A switch point in the first microseconds stops the first search at once; the second field must still find the path.
config.lattice_alt_field_enabled = true;
config.lattice_alt_field_switch_fraction = 1e-6;
const PlanResult alternate = map.plan(request, config);
ASSERT_TRUE(alternate.ok) << alternate.info.reason;
EXPECT_EQ(alternate.info.tier_used, "lattice");
EXPECT_EQ(alternate.info.lattice_field_pass, "alternate");
EXPECT_TRUE(alternate.check.valid);
EXPECT_GE(alternate.info.min_gap_m, config.footprint_min_gap_m);
// Same field twice is pointless: no extra clearance and the same relax keep the first field to the end.
config.lattice_field_extra_clearance_m = 0.0;
config.lattice_field_standability_relax_m = config.lattice_alt_field_relax_m;
config.lattice_alt_field_switch_fraction = 0.35;
const PlanResult same = map.plan(request, config);
ASSERT_TRUE(same.ok) << same.info.reason;
EXPECT_EQ(same.info.lattice_field_pass, "primary");
}
TEST(Lattice, SameStartAndGoal)
{
LatticeTestGrid map(100, 100);