feat(lane_route): sharp corners as the last radius rung, heuristic field margin (R2.7)

max_kink_deg (default 45): in the graph's second pass, a corner where no
radius fits may become a sharp corner (two straight lines meeting at one
vertex pose, no turn in place) when the footprint can rotate at the
vertex; the verifier counts it in PathCheck::corners. The verifier's
bend limit now follows min_turn_radius_m (it blocked radii below ~0.72 m).

lattice_field_extra_clearance_m (default 0): extra clearance for a cell
to be passable in the lattice heuristic field only, with a rebuild of
the plain field when the margin field never reaches the start.

regress7 with the sim settings (0.4 m floor, margin 0.1): hook_150
1717/1757, kit 1716/1757 (R2.5: 1718, 1709); Python recheck finds no
curvature, corner, spin, zone or crossing errors. The graph tier's
30 mm gap still ignores unknown cells, as since R0.
This commit is contained in:
2026-11-09 23:30:46 +07:00
parent 907fa0c4dc
commit 527071827f
11 changed files with 112 additions and 15 deletions

View File

@@ -72,7 +72,7 @@ int zoneViolations(const PathPoint& a, const PathPoint& b, const GridRef& grid,
return count;
}
bool kinkMetrics(const Path& path, int* kinks, double* max_bend_deg,
bool kinkMetrics(const Path& path, double bend_limit_deg, int* kinks, double* max_bend_deg,
const std::atomic<bool>* cancel, const std::chrono::steady_clock::time_point* deadline)
{
std::vector<double> along(path.size(), 0.0);
@@ -118,7 +118,7 @@ bool kinkMetrics(const Path& path, int* kinks, double* max_bend_deg,
const PathPoint& c = path[keep[k + 2]];
const double bend = std::abs(wrapAngle(std::atan2(c.y - b.y, c.x - b.x) - std::atan2(b.y - a.y, b.x - a.x))) * kRadToDeg;
largest = std::max(largest, bend);
if (bend > kBendLimitDeg)
if (bend > bend_limit_deg)
++over;
}
*kinks = spins + over;
@@ -215,7 +215,16 @@ PathCheck verifyPath(const Path& path, const GridRef& grid, double deviation_deg
if (!std::isfinite(point.x) || !std::isfinite(point.y) || !std::isfinite(point.yaw))
return check;
if (!kinkMetrics(path, &check.kinks, &check.max_bend_deg, cancel, deadline)) return check;
// The bend limit follows the tightest legal curve (a 0.4 m floor turns 14.3 deg over 0.1 m), and a sharp corner may bend up
// to max_kink_deg; the curvature test below still tells a sharp corner from a too-tight curve.
const double kink_rad = config.max_kink_deg * kPi / 180.0;
const double bend_limit_deg = std::max({ kBendLimitDeg, 1.1 * kBendSpacingM / config.min_turn_radius_m * kRadToDeg,
config.max_kink_deg > 0.0 ? config.max_kink_deg + 1e-6 : 0.0 });
if (!kinkMetrics(path, bend_limit_deg, &check.kinks, &check.max_bend_deg, cancel, deadline)) return check;
const auto straightStep = [&path](std::size_t i) {
return i + 1 < path.size() && std::hypot(path[i + 1].x - path[i].x, path[i + 1].y - path[i].y) > 1e-7 &&
std::abs(wrapAngle(path[i + 1].yaw - path[i].yaw)) < 1e-6;
};
for (std::size_t i = 0; i + 1 < path.size(); ++i)
{
if ((cancel && cancel->load(std::memory_order_relaxed)) || (deadline && std::chrono::steady_clock::now() >= *deadline)) return check;
@@ -225,7 +234,12 @@ PathCheck verifyPath(const Path& path, const GridRef& grid, double deviation_deg
const double dy = b.y - a.y;
const double distance = std::hypot(dx, dy);
const double turn = wrapAngle(b.yaw - a.yaw);
if (distance > 1e-7)
// A sharp corner is one turning step between two straight steps; it is counted, not measured as a curve.
const bool corner = kink_rad > 0.0 && distance > 1e-7 && std::abs(turn) > 1e-6 && std::abs(turn) <= kink_rad + 1e-9 &&
i > 0 && straightStep(i - 1) && straightStep(i + 1);
if (corner)
++check.corners;
else if (distance > 1e-7)
{
// The displacement is a chord: recover arc length before estimating curvature.
const double arc = std::abs(turn) < 1e-9 ? distance : distance * std::abs(turn) / (2.0 * std::abs(std::sin(turn / 2.0)));