feat(lane_route): footprint-zone rule with entry/exit transition, longer lane-end links (R2.11)

- A footprint may overlap a direction zone against its heading only within
  zone_transition_m (default 1.0 m) of path where the centre is inside that
  same zone, or at a parked endpoint. Checked on whole paths by the verifier.
- The lattice C-space keeps the strict per-pose rule so its paths always pass.
- Lane-end junction links reach 8 m with up to 24 links (was 6 m / 12 tries).
- lane_route_eval can dump the graph, attempts and routes per query.
This commit is contained in:
2026-11-10 16:32:02 +07:00
parent a4b655b74b
commit 447ce46c29
15 changed files with 1074 additions and 27 deletions

View File

@@ -37,7 +37,7 @@ bool hasSoftCost(const uint8_t* master, std::size_t count)
/** Route graph, then the same without soft cost values. Hard rules hold in both passes. */
bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal, const GridRef& grid, const std::vector<WorldBox>* changed,
TimePoint deadline, bool allow_soft_fallback, const GridRef& verify_grid, const PlannerConfig& config, Path* path,
PathCheck* check, PlanInfo* info, const std::atomic<bool>* cancel)
PathCheck* check, PlanInfo* info, const std::atomic<bool>* cancel, GraphTrace* trace, const char* trace_source)
{
QueryContext context{ grid, verify_grid, config, graph.deviation_deg, deadline, clearanceThresholdMm(config.clearance_hard_m),
clearanceThresholdMm(config.clearance_min_m), clearanceThresholdMm(config.clearance_preferred_m),
@@ -92,6 +92,30 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
}
}
GraphTraceRun* trace_run = nullptr;
if (trace != nullptr)
{
trace->runs.emplace_back();
trace_run = &trace->runs.back();
trace_run->deviation_deg = dev;
trace_run->min_turn_radius_m = config.min_turn_radius_m;
trace_run->max_kink_deg = config.max_kink_deg;
trace_run->voronoi_weight = kVoronoiWeight;
trace_run->corner_radii_m = config.corner_radii_m;
trace_run->source = trace_source;
trace_run->base_nodes = query.baseNodes();
trace_run->base_edges = query.baseEdges();
trace_run->start_node = s;
trace_run->goal_node = g;
trace_run->nodes.reserve(static_cast<std::size_t>(query.nodeCount()));
trace_run->edges.reserve(static_cast<std::size_t>(query.edgeCount()));
for (int32_t i = 0; i < query.nodeCount(); ++i) trace_run->nodes.push_back(query.node(i));
for (int32_t i = 0; i < query.edgeCount(); ++i) trace_run->edges.push_back(query.edge(i));
trace_run->factors = factors;
for (int32_t i = 0; i < query.edgeCount(); ++i)
if (blocked[static_cast<std::size_t>(i)] != 0) trace_run->initially_blocked_edges.push_back(i);
}
std::string reason;
std::vector<int32_t> route;
for (int pass = 0; pass < 2; ++pass)
@@ -116,28 +140,48 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
compiledEdgeFactors(graph, master, &factors);
for (const GraphEdge& edge : query.extraEdges())
factors.push_back(edgeFactor(edge.points, master, grid));
if (trace_run != nullptr) trace_run->neutral_factors = factors;
reason.clear();
}
std::set<std::pair<int32_t, int32_t>> blocked_pairs;
for (int attempt = 0; attempt < config.max_route_attempts; ++attempt)
{
GraphTraceAttempt* trace_attempt = nullptr;
if (trace_run != nullptr)
{
trace_run->attempts.emplace_back();
trace_attempt = &trace_run->attempts.back();
trace_attempt->pass = pass;
trace_attempt->attempt = attempt;
}
const auto trace_reason = [&](const auto& value) {
if (trace_attempt != nullptr)
{
trace_attempt->reason = value;
if (trace_attempt->reason.empty()) trace_attempt->reason = "unspecified_rejection";
}
};
if (context.expired())
{
reason = "timeout";
if (trace_attempt != nullptr)
trace_reason(context.cancel && context.cancel->load(std::memory_order_relaxed) ? "cancelled" : reason);
break;
}
timer = Clock::now();
const bool found = searchRoute(query, s, g, blocked, blocked_pairs, max_straight_m, config.min_turn_radius_m, factors, &route, context.cancel);
info->search_ms += msSince(timer);
if (trace_attempt != nullptr && found) trace_attempt->route = route;
if (!found)
{
if (context.cancel && context.cancel->load(std::memory_order_relaxed)) break;
if (context.cancel && context.cancel->load(std::memory_order_relaxed)) { trace_reason("cancelled"); break; }
// The graph is not complete, so only a component test on the grid may call this no-route.
if (enclosedByObstacles(grid, start_point, goal_point, context.cancel))
reason = "no_route_enclosed";
else if (attempt == 0)
reason = "graph_disconnected";
if (trace_attempt != nullptr) trace_reason(reason.empty() ? "search_exhausted" : "search_exhausted: " + reason);
break;
}
@@ -153,9 +197,11 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
}
if (bad >= 0)
{
if (trace_attempt != nullptr) trace_attempt->rejected_edge = bad;
blocked[static_cast<std::size_t>(bad)] = 1;
++info->retries;
reason = "edge_blocked";
trace_reason(reason);
continue;
}
@@ -165,6 +211,7 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
if (context.expired())
{
reason = "timeout";
trace_reason(reason);
break;
}
@@ -173,8 +220,14 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
const Point2 corner = candidate.why.corner;
if (candidate.ok)
{
if (trace_attempt != nullptr) trace_attempt->candidate_length_m = pathLength(candidate.path);
timer = Clock::now();
PathCheck path_check = verifyPath(candidate.path, verify_grid, dev, config, context.cancel);
PathCheck path_check = verifyPath(candidate.path, verify_grid, dev, config, context.cancel, &deadline);
if (trace_attempt != nullptr)
{
trace_attempt->zone_violations = path_check.zone_violations;
trace_attempt->footprint_collisions = path_check.footprint_collisions;
}
bool ends_ok = endpointOk(candidate.path, start, goal);
bool clear_ok = freeClearanceOk(candidate.path, verify_grid, context.min_mm);
const char* turn_blocked = blockedEndpointTurn(candidate.path, verify_grid, config.half_x_m, config.half_y_m);
@@ -182,6 +235,7 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
if (turn_blocked != nullptr)
{
reason = turn_blocked;
trace_reason(reason);
break;
}
@@ -210,7 +264,7 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
if (!alternative.ok)
continue;
timer = Clock::now();
const PathCheck alternative_check = verifyPath(alternative.path, verify_grid, dev, config, context.cancel);
const PathCheck alternative_check = verifyPath(alternative.path, verify_grid, dev, config, context.cancel, &deadline);
const bool usable = alternative_check.valid && endpointOk(alternative.path, start, goal) &&
freeClearanceOk(alternative.path, verify_grid, context.min_mm) &&
blockedEndpointTurn(alternative.path, verify_grid, config.half_x_m, config.half_y_m) == nullptr;
@@ -238,7 +292,13 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
reference_checked = true;
}
candidate = std::move(alternative);
if (trace_attempt != nullptr) trace_attempt->candidate_length_m = length;
path_check = alternative_check;
if (trace_attempt != nullptr)
{
trace_attempt->zone_violations = path_check.zone_violations;
trace_attempt->footprint_collisions = path_check.footprint_collisions;
}
gap = alternative_gap;
ends_ok = true;
clear_ok = true;
@@ -248,6 +308,7 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
if (context.expired())
{
reason = "timeout";
trace_reason(reason);
break;
}
}
@@ -263,11 +324,13 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
double reference = 0.0;
const bool known = cachedStandableReference(verify_grid, start_point, goal_point, dev, bound, &reference, standability,
reference_memo, context.cancel, &deadline);
if (trace_attempt != nullptr && known) trace_attempt->reference_length_m = reference;
info->verify_ms += msSince(timer);
if (known && length > config.route_too_long_ratio * reference + config.route_too_long_margin_m)
{
info->graph_reference_length_m = reference;
reason = "route_too_long";
trace_reason(reason);
break;
}
}
@@ -282,6 +345,7 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
info->gap_shortcut_raise_m = raise_used;
info->min_gap_m = gap.min_gap_m;
info->gap_exemption_used = gap.exemption_used;
trace_reason("verified");
return true;
}
why = gap_checked && !gap.valid ? "footprint_gap_below_minimum" :
@@ -292,6 +356,7 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
if (candidate.vertices.empty())
{
reason = why;
trace_reason(reason);
break;
}
std::vector<std::pair<int32_t, int32_t>> pairs;
@@ -324,11 +389,14 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
if (pairs.empty())
{
reason = why;
trace_reason(reason);
break;
}
blocked_pairs.insert(pairs.begin(), pairs.end());
if (trace_attempt != nullptr) trace_attempt->blocked_pairs_added = pairs;
++info->retries;
reason = why;
trace_reason(reason);
}
}
info->reason = reason.empty() ? "fallback" : reason;
@@ -337,10 +405,11 @@ bool planCore(const CompiledGraph& graph, const Pose2& start, const Pose2& goal,
/** One rung: the normal core, then a ridge rebuilt from the live grid around start and goal when the map changed. */
bool planRung(const CompiledGraph& graph, const RouteRequest& request, const GridRef& live, TimePoint deadline, const PlannerConfig& config,
const RidgeBackend& backend, Path* path, PathCheck* check, PlanInfo* info)
const RidgeBackend& backend, Path* path, PathCheck* check, PlanInfo* info, GraphTrace* trace)
{
const std::vector<WorldBox>* changed = request.changed_boxes.empty() ? nullptr : &request.changed_boxes;
if (planCore(graph, request.start, request.goal, live, changed, deadline, true, live, config, path, check, info, request.cancel))
if (planCore(graph, request.start, request.goal, live, changed, deadline, true, live, config, path, check, info, request.cancel,
trace, "compiled"))
return true;
if ((request.cancel && request.cancel->load(std::memory_order_relaxed)) || changed == nullptr || !backend.build_coarse || info->reason == "no_route_enclosed" || info->reason == "timeout")
return false;
@@ -398,7 +467,8 @@ bool planRung(const CompiledGraph& graph, const RouteRequest& request, const Gri
{
const CompiledGraph live_graph = compileGraph(coarse, window, window.cost, graph.deviation_deg, config, backend, request.cancel);
if (Clock::now() < deadline)
ok = planCore(live_graph, request.start, request.goal, window, nullptr, deadline, false, live, config, path, check, &live_info, request.cancel);
ok = planCore(live_graph, request.start, request.goal, window, nullptr, deadline, false, live, config, path, check,
&live_info, request.cancel, trace, "live_ridge");
}
info->retries += live_info.retries;
info->gap_failures += live_info.gap_failures;
@@ -431,7 +501,7 @@ bool planRung(const CompiledGraph& graph, const RouteRequest& request, const Gri
bool planGraphTier(const GraphTierInput& input, GraphTierOutput output)
{
return planRung(input.graph, input.request, input.live, input.deadline, input.config, input.backend,
&output.path, &output.check, &output.info);
&output.path, &output.check, &output.info, input.trace);
}
} // namespace detail