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:
@@ -2,13 +2,16 @@
|
||||
* with the Python prototype. Usage:
|
||||
* lane_route_eval <scenes.txt> <out.jsonl> <profile sehc|kit|hook_150> <deviations, e.g. 90,45> <ladder, e.g. 0.01 or none> [graph|fallback|lattice]
|
||||
* Each scenes.txt line: id grid_file variant live_file|- has_start_yaw sx sy syaw has_goal_yaw gx gy gyaw box_count {x0 y0 x1 y1}
|
||||
* Grid files are kept in memory, so scenes that share one map also share its graphs, as on the robot. */
|
||||
* Grid files are kept in memory, so scenes that share one map also share its graphs, as on the robot.
|
||||
* Set LANE_ROUTE_EVAL_DUMP_GRAPH to a directory for per-query graph, Dijkstra attempts and final-path JSON. */
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -32,6 +35,122 @@ using Clock = std::chrono::steady_clock;
|
||||
|
||||
double msSince(Clock::time_point begin) { return std::chrono::duration<double, std::milli>(Clock::now() - begin).count(); }
|
||||
|
||||
void jsonString(std::ostream& out, const std::string& value)
|
||||
{
|
||||
out << '"';
|
||||
for (unsigned char c : value)
|
||||
{
|
||||
if (c == '"' || c == '\\') out << '\\' << static_cast<char>(c);
|
||||
else if (c < 0x20) out << "\\u00" << "0123456789abcdef"[c >> 4] << "0123456789abcdef"[c & 15];
|
||||
else out << static_cast<char>(c);
|
||||
}
|
||||
out << '"';
|
||||
}
|
||||
|
||||
const char* edgeKind(EdgeKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EdgeKind::kVoronoi: return "kVoronoi";
|
||||
case EdgeKind::kLane: return "kLane";
|
||||
case EdgeKind::kJunction: return "kJunction";
|
||||
case EdgeKind::kPreferredRidge: return "kPreferredRidge";
|
||||
case EdgeKind::kPreferredAttach: return "kPreferredAttach";
|
||||
case EdgeKind::kAttach: return "kAttach";
|
||||
case EdgeKind::kDirect: return "kDirect";
|
||||
case EdgeKind::kTemporaryLane: return "kTemporaryLane";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
void writeFinite(std::ostream& out, double value)
|
||||
{
|
||||
if (std::isfinite(value)) out << value;
|
||||
else out << "null";
|
||||
}
|
||||
|
||||
void writeGraphDump(const std::string& directory, std::size_t ordinal, const std::string& id, double deviation,
|
||||
const RouteRequest& request, const GraphTrace& trace, const PlanResult& result)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::filesystem::create_directories(directory);
|
||||
std::ostringstream name;
|
||||
name << "query_" << std::setw(5) << std::setfill('0') << ordinal << ".json";
|
||||
std::ofstream out(std::filesystem::path(directory) / name.str());
|
||||
if (!out) { std::cerr << "cannot write graph dump " << name.str() << std::endl; return; }
|
||||
out.precision(17);
|
||||
out << "{\"scene\":"; jsonString(out, id);
|
||||
out << ",\"requested_deviation_deg\":"; writeFinite(out, deviation);
|
||||
out << ",\"start\":["; writeFinite(out, request.start.x); out << ','; writeFinite(out, request.start.y); out << ',';
|
||||
writeFinite(out, request.start.yaw); out << "],\"goal\":["; writeFinite(out, request.goal.x); out << ',';
|
||||
writeFinite(out, request.goal.y); out << ','; writeFinite(out, request.goal.yaw);
|
||||
out << "],\"ok\":" << (result.ok ? "true" : "false") << ",\"reason\":"; jsonString(out, result.info.reason);
|
||||
out << ",\"graph_reason\":"; jsonString(out, result.info.graph_reason);
|
||||
out << ",\"runs\":[";
|
||||
for (std::size_t ri = 0; ri < trace.runs.size(); ++ri)
|
||||
{
|
||||
const GraphTraceRun& run = trace.runs[ri];
|
||||
if (ri) out << ',';
|
||||
out << "{\"source\":"; jsonString(out, run.source);
|
||||
out << ",\"deviation_deg\":" << run.deviation_deg << ",\"min_turn_radius_m\":" << run.min_turn_radius_m
|
||||
<< ",\"max_kink_deg\":" << run.max_kink_deg << ",\"corner_radii_m\":[";
|
||||
for (std::size_t i = 0; i < run.corner_radii_m.size(); ++i) { if (i) out << ','; out << run.corner_radii_m[i]; }
|
||||
out << "],\"base_nodes\":" << run.base_nodes << ",\"base_edges\":" << run.base_edges
|
||||
<< ",\"start_node\":" << run.start_node << ",\"goal_node\":" << run.goal_node << ",\"nodes\":[";
|
||||
for (std::size_t i = 0; i < run.nodes.size(); ++i)
|
||||
{ if (i) out << ','; out << '['; writeFinite(out, run.nodes[i].x); out << ','; writeFinite(out, run.nodes[i].y); out << ']'; }
|
||||
out << "],\"edges\":[";
|
||||
for (std::size_t i = 0; i < run.edges.size(); ++i)
|
||||
{
|
||||
if (i) out << ',';
|
||||
const GraphEdge& edge = run.edges[i];
|
||||
double length = 0.0;
|
||||
for (std::size_t j = 1; j < edge.points.size(); ++j) length += distanceOf(edge.points[j - 1], edge.points[j]);
|
||||
out << "{\"id\":" << i << ",\"from\":" << edge.from << ",\"to\":" << edge.to << ",\"kind\":";
|
||||
jsonString(out, edgeKind(edge.kind));
|
||||
out << ",\"query_edge\":" << (i >= static_cast<std::size_t>(run.base_edges) ? "true" : "false")
|
||||
<< ",\"length_m\":"; writeFinite(out, length); out << ",\"cost\":"; writeFinite(out, edge.cost);
|
||||
out << ",\"kind_weight\":" << (edge.kind == EdgeKind::kVoronoi ? run.voronoi_weight : 1.0);
|
||||
out << ",\"factor\":"; if (i < run.factors.size()) writeFinite(out, run.factors[i]); else out << "null";
|
||||
out << ",\"neutral_factor\":"; if (i < run.neutral_factors.size()) writeFinite(out, run.neutral_factors[i]); else out << "null";
|
||||
out << ",\"polyline\":[";
|
||||
for (std::size_t j = 0; j < edge.points.size(); ++j)
|
||||
{ if (j) out << ','; out << '['; writeFinite(out, edge.points[j].x); out << ','; writeFinite(out, edge.points[j].y); out << ']'; }
|
||||
out << "]}";
|
||||
}
|
||||
out << "],\"initially_blocked_edges\":[";
|
||||
for (std::size_t i = 0; i < run.initially_blocked_edges.size(); ++i)
|
||||
{ if (i) out << ','; out << run.initially_blocked_edges[i]; }
|
||||
out << "],\"attempts\":[";
|
||||
for (std::size_t i = 0; i < run.attempts.size(); ++i)
|
||||
{
|
||||
if (i) out << ',';
|
||||
const GraphTraceAttempt& attempt = run.attempts[i];
|
||||
out << "{\"pass\":" << attempt.pass << ",\"attempt\":" << attempt.attempt << ",\"reason\":";
|
||||
jsonString(out, attempt.reason);
|
||||
out << ",\"rejected_edge\":" << attempt.rejected_edge << ",\"candidate_length_m\":" << attempt.candidate_length_m
|
||||
<< ",\"reference_length_m\":" << attempt.reference_length_m << ",\"zone_violations\":" << attempt.zone_violations
|
||||
<< ",\"footprint_collisions\":" << attempt.footprint_collisions << ",\"blocked_pairs_added\":[";
|
||||
for (std::size_t j = 0; j < attempt.blocked_pairs_added.size(); ++j)
|
||||
{ if (j) out << ','; out << '[' << attempt.blocked_pairs_added[j].first << ',' << attempt.blocked_pairs_added[j].second << ']'; }
|
||||
out << ']';
|
||||
out << ",\"route\":[";
|
||||
for (std::size_t j = 0; j < attempt.route.size(); ++j) { if (j) out << ','; out << attempt.route[j]; }
|
||||
out << "]}";
|
||||
}
|
||||
out << "]}";
|
||||
}
|
||||
out << "],\"path\":[";
|
||||
for (std::size_t i = 0; i < result.path.size(); ++i)
|
||||
{ if (i) out << ','; const PathPoint& p = result.path[i]; out << '['; writeFinite(out, p.x); out << ','; writeFinite(out, p.y);
|
||||
out << ','; writeFinite(out, p.yaw); out << ','; writeFinite(out, p.curvature); out << ']'; }
|
||||
out << "]}\n";
|
||||
if (!out) std::cerr << "failed to finish graph dump " << name.str() << std::endl;
|
||||
}
|
||||
catch (const std::exception& ex) { std::cerr << "graph dump: " << ex.what() << std::endl; }
|
||||
}
|
||||
|
||||
std::vector<uint8_t> readRuns(std::istream& in, const std::string& name)
|
||||
{
|
||||
std::string key;
|
||||
@@ -127,6 +246,7 @@ void applyOverrides(PlannerConfig* config)
|
||||
return;
|
||||
const std::map<std::string, double*> doubles{
|
||||
{ "lattice_closed_resolution_m", &config->lattice_closed_resolution_m },
|
||||
{ "zone_transition_m", &config->zone_transition_m },
|
||||
{ "lattice_preferred_gap_m", &config->lattice_preferred_gap_m },
|
||||
{ "lattice_preferred_time_fraction", &config->lattice_preferred_time_fraction },
|
||||
{ "lattice_heuristic_weight", &config->lattice_heuristic_weight },
|
||||
@@ -268,6 +388,9 @@ int main(int argc, char** argv)
|
||||
out.precision(17);
|
||||
|
||||
std::map<std::string, std::shared_ptr<MapData>> maps;
|
||||
const char* graph_dump_dir = std::getenv("LANE_ROUTE_EVAL_DUMP_GRAPH");
|
||||
const bool graph_dump_enabled = graph_dump_dir != nullptr && *graph_dump_dir != '\0';
|
||||
std::size_t graph_dump_ordinal = 0;
|
||||
std::string line;
|
||||
while (std::getline(scenes, line))
|
||||
{
|
||||
@@ -343,6 +466,7 @@ int main(int argc, char** argv)
|
||||
for (double deviation : deviations)
|
||||
{
|
||||
config.max_deviation_deg = deviation;
|
||||
GraphTrace graph_trace;
|
||||
const GraphProvider provider = [&](double limit) -> std::shared_ptr<const CompiledGraph> {
|
||||
if (coarse == nullptr) return {};
|
||||
auto& slot = live_preferred ? row_graphs[limit] : map->graphs[std::make_pair(variant, limit)];
|
||||
@@ -351,7 +475,8 @@ int main(int argc, char** argv)
|
||||
compileGraph(*coarse, compile_grid, live_preferred ? live_cost.data() : compile_grid.cost, limit, config, backend));
|
||||
return slot;
|
||||
};
|
||||
const PlanResult result = planRoute(provider, request, live_grid, config, backend);
|
||||
const PlanResult result = planRoute(provider, request, live_grid, config, backend, graph_dump_enabled ? &graph_trace : nullptr);
|
||||
if (graph_dump_enabled) writeGraphDump(graph_dump_dir, graph_dump_ordinal++, id, deviation, request, graph_trace, result);
|
||||
const PlanInfo& info = result.info;
|
||||
out << "{\"scene\":\"" << id << "\",\"dev\":" << deviation << ",\"ok\":" << (result.ok ? 1 : 0) << ",\"reason\":\"" << info.reason
|
||||
<< "\",\"query_ms\":" << info.query_ms << ",\"compile_ms\":" << info.compile_ms << ",\"coarse_ms\":" << coarse_ms
|
||||
|
||||
Reference in New Issue
Block a user