feat(lane_route): radius ladder and failure dumps (R2.6)
Radius ladder: the first graph pass, the lattice and the smoother use only radii at or above regular_turn_radius_m (1.06 m), as before. When min_turn_radius_m is lower, the graph runs a second pass with all corner_radii_m if the first fails or returns a long detour, and keeps it only when at least 20% shorter. Optional lattice tight arcs exist behind lattice_tight_arcs (off: they cost many queries to timeouts). C++ defaults keep the old 1.06 m floor; regress7 output is identical. With a 0.4 m floor: graph-only coverage +5 (hook_150) and +8 (kit), none lost; with fallback, coverage unchanged and 27/29 queries move from lattice to graph; tight corners used 0.9 m. Failure dumps: with debug/dump_dir set, the plugin writes each failed query as lane_route_eval input (static cost, master cost, direction codes, poses, settings), at most debug/dump_max_files per session.
This commit is contained in:
@@ -108,6 +108,10 @@ std::string PlannerConfig::validate() const
|
||||
error << "live ridge limits must be >= 0";
|
||||
else if (lattice_enabled && (lattice_heading_bins < 8 || lattice_heading_bins > 1024 || lattice_heading_bins % 2 != 0))
|
||||
error << "lattice_heading_bins must be even and in [8, 1024]";
|
||||
else if (!positive(regular_turn_radius_m))
|
||||
error << "regular_turn_radius_m must be finite and > 0";
|
||||
else if (lattice_enabled && !not_negative(lattice_tight_turn_cost_m))
|
||||
error << "lattice_tight_turn_cost_m must be finite and >= 0";
|
||||
else if (lattice_enabled && (!not_negative(lattice_preferred_gap_m) ||
|
||||
!positive(lattice_preferred_time_fraction) || lattice_preferred_time_fraction > 1.0))
|
||||
error << "lattice_preferred_gap_m must be >= 0; lattice_preferred_time_fraction must be in (0, 1]";
|
||||
|
||||
@@ -323,7 +323,12 @@ bool searchLattice(LatticeContext& context, LatticeCSpace& space, const LatticeF
|
||||
const PlannerConfig& c = context.config;
|
||||
const GridRef& grid = context.grid;
|
||||
const double angle = 2.0 * kPi / c.lattice_heading_bins;
|
||||
const double basic = c.min_turn_radius_m * angle;
|
||||
// Regular arcs keep the radius the hand-drawn paths were graded at. Tight arcs at min_turn_radius_m exist only with
|
||||
// lattice_tight_arcs and a lower floor; each tight heading bin pays lattice_tight_turn_cost_m.
|
||||
const double regular_radius = std::max(c.regular_turn_radius_m, c.min_turn_radius_m);
|
||||
const double basic = regular_radius * angle;
|
||||
const double tight_basic = c.min_turn_radius_m * angle;
|
||||
const bool tight_arcs = c.lattice_tight_arcs && c.min_turn_radius_m < regular_radius - 1e-9;
|
||||
const std::size_t grid_cells = static_cast<std::size_t>(grid.width) * static_cast<std::size_t>(grid.height);
|
||||
const double bin_resolution = grid_cells > 2000000u ? c.lattice_closed_resolution_m :
|
||||
std::min(c.lattice_closed_resolution_m, grid.resolution);
|
||||
@@ -485,11 +490,15 @@ bool searchLattice(LatticeContext& context, LatticeCSpace& space, const LatticeF
|
||||
}
|
||||
const int multiples[] = { c.lattice_primitive_multiple_1, c.lattice_primitive_multiple_2, c.lattice_primitive_multiple_3 };
|
||||
for (int multi : multiples)
|
||||
for (int steer : { 0, 1, -1 })
|
||||
for (int choice : { 0, 1, -1, 2, -2 })
|
||||
{
|
||||
if (context.expired()) return false;
|
||||
const double length = basic * multi;
|
||||
const double curvature = steer / c.min_turn_radius_m;
|
||||
const bool tight = choice == 2 || choice == -2;
|
||||
// A tight step shorter than a closed bin would stay in its parent's bin; the longer multiples cover those turns.
|
||||
if (tight && (!tight_arcs || tight_basic * multi < bin_resolution)) continue;
|
||||
const int steer = choice > 0 ? 1 : choice < 0 ? -1 : 0;
|
||||
const double length = (tight ? tight_basic : basic) * multi;
|
||||
const double curvature = steer / (tight ? c.min_turn_radius_m : regular_radius);
|
||||
if (multi > 1)
|
||||
{
|
||||
const int32_t x = static_cast<int32_t>(std::floor((current.pose.x-grid.origin_x)/grid.resolution));
|
||||
@@ -514,7 +523,8 @@ bool searchLattice(LatticeContext& context, LatticeCSpace& space, const LatticeF
|
||||
const int32_t y = static_cast<int32_t>(std::floor((next.y-grid.origin_y)/grid.resolution));
|
||||
if (x < 0 || y < 0 || x >= grid.width || y >= grid.height) continue;
|
||||
const double clear = std::max(0.05, grid.clearance_mm[static_cast<std::size_t>(y)*grid.width+x]/1000.0);
|
||||
const double cost = latticeMotionCost(length, clear, steer, current.last_steer, multi, c);
|
||||
const double cost = latticeMotionCost(length, clear, steer, current.last_steer, multi, c) +
|
||||
(tight ? c.lattice_tight_turn_cost_m * multi : 0.0);
|
||||
offer({ next, current.g+cost, static_cast<int64_t>(entry.node), curvature, length, heading, last });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,14 @@ class Smoother
|
||||
{
|
||||
public:
|
||||
Smoother(LatticeContext& context, LatticeCSpace& space, Path* output, PathCheck* check)
|
||||
: context_(context), space_(space), output_(output), check_(check), witness_(*output), best_(score(*output)) {}
|
||||
: context_(context), space_(space), output_(output), check_(check), witness_(*output), best_(score(*output))
|
||||
{
|
||||
// Connectors use the regular radii only: a tight turn stays where the lattice needed it and is never introduced by smoothing.
|
||||
const double regular = std::max(context.config.regular_turn_radius_m, context.config.min_turn_radius_m);
|
||||
for (double radius : context.config.corner_radii_m)
|
||||
if (radius >= regular - 1e-9) regular_radii_.push_back(radius);
|
||||
if (regular_radii_.empty()) regular_radii_.push_back(regular);
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
@@ -119,6 +126,7 @@ public:
|
||||
|
||||
private:
|
||||
static double distance(const PathPoint& a, const PathPoint& b) { return std::hypot(b.x-a.x, b.y-a.y); }
|
||||
const std::vector<double>& regularRadii() const { return regular_radii_; }
|
||||
|
||||
bool chordBlocked(const PathPoint& a, const PathPoint& b) const
|
||||
{
|
||||
@@ -201,7 +209,7 @@ private:
|
||||
bool connector(const PathPoint& start, const PathPoint& goal, Path* piece, double* edge_score = nullptr)
|
||||
{
|
||||
std::pmr::vector<WordChoice> choices(&context_.memory);
|
||||
const auto& configured = context_.config.corner_radii_m;
|
||||
const std::vector<double>& configured = regularRadii();
|
||||
const std::array<double, 3> radii{{configured.front(), configured[2*(configured.size()-1)/3], configured.back()}};
|
||||
const double chord = distance(start, goal);
|
||||
const double heading_change = std::abs(wrapAngle(goal.yaw-start.yaw));
|
||||
@@ -383,6 +391,7 @@ private:
|
||||
std::vector<double> unwrapped_;
|
||||
std::vector<double> filter_;
|
||||
std::vector<Anchor> anchor_;
|
||||
std::vector<double> regular_radii_; // [m] corner_radii_m at or above the regular lattice radius, largest first.
|
||||
};
|
||||
|
||||
bool Smoother::runGreedy()
|
||||
@@ -446,7 +455,7 @@ void Smoother::runGraph(bool improve_smoothed, uint64_t check_limit)
|
||||
if (j + 1 != anchor_.size() || context_.request.goal.has_yaw)
|
||||
{
|
||||
const std::array<double, 2> end_yaws{{anchor_[j].low_yaw, target.yaw}};
|
||||
const auto& radii = context_.config.corner_radii_m;
|
||||
const std::vector<double>& radii = regularRadii();
|
||||
for (double end_yaw : end_yaws)
|
||||
for (double radius : {radii.front(), radii.back()})
|
||||
for (int side : {1, -1})
|
||||
|
||||
@@ -27,6 +27,21 @@ using detail::Clock;
|
||||
using detail::TimePoint;
|
||||
using detail::msSince;
|
||||
|
||||
namespace
|
||||
{
|
||||
// A tight-corner graph path replaces a large-radius one only when it is at least this much shorter, so a large radius stays the
|
||||
// default shape and a tight corner appears where it removes a real detour.
|
||||
constexpr double kTightMinSaving = 0.2;
|
||||
|
||||
double polylineLength(const Path& path)
|
||||
{
|
||||
double length = 0.0;
|
||||
for (std::size_t i = 1; i < path.size(); ++i)
|
||||
length += std::hypot(path[i].x - path[i - 1].x, path[i].y - path[i - 1].y);
|
||||
return length;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
PlanResult planRoute(const GraphProvider& graphs, const RouteRequest& request, const GridRef& live, const PlannerConfig& config,
|
||||
const RidgeBackend& backend)
|
||||
{
|
||||
@@ -100,6 +115,22 @@ PlanResult planRoute(const GraphProvider& graphs, const RouteRequest& request, c
|
||||
}
|
||||
rungs.push_back(config.max_deviation_deg);
|
||||
|
||||
// Radius ladder. The first graph pass and the lattice use only radii at or above regular_turn_radius_m, which is how every
|
||||
// tier planned before the floor could be lowered. A lower min_turn_radius_m only adds a second graph pass with all corner
|
||||
// radii, for a failed first pass or a long detour (measured 9/11: letting the route search and the lattice use the low floor
|
||||
// from the start lost 25 to 84 regress7 queries).
|
||||
PlannerConfig regular = config;
|
||||
regular.min_turn_radius_m = std::max(config.regular_turn_radius_m, config.min_turn_radius_m);
|
||||
regular.corner_radii_m.clear();
|
||||
for (double radius : config.corner_radii_m)
|
||||
if (radius >= regular.min_turn_radius_m - 1e-9)
|
||||
regular.corner_radii_m.push_back(radius);
|
||||
if (regular.corner_radii_m.empty())
|
||||
regular.corner_radii_m.push_back(regular.min_turn_radius_m);
|
||||
const bool tight_corners = config.min_turn_radius_m < regular.min_turn_radius_m - 1e-9;
|
||||
const PlannerConfig& lattice_config = config.lattice_tight_arcs ? config : regular;
|
||||
const double chord = std::hypot(request.goal.x - request.start.x, request.goal.y - request.start.y);
|
||||
|
||||
// R2 smoothing must share this fallback deadline instead of starting a new budget.
|
||||
TimePoint fallback_deadline = deadline;
|
||||
bool fallback_started = false;
|
||||
@@ -123,8 +154,35 @@ PlanResult planRoute(const GraphProvider& graphs, const RouteRequest& request, c
|
||||
else
|
||||
{
|
||||
result.info.live_ridge.clear();
|
||||
graph_ok = detail::planGraphTier({ *graph, request, live, deadline, config, backend },
|
||||
graph_ok = detail::planGraphTier({ *graph, request, live, deadline, tight_corners ? regular : config, backend },
|
||||
{ result.path, result.check, result.info });
|
||||
const bool detour = graph_ok && polylineLength(result.path) > config.suspicious_ratio * chord + config.suspicious_margin_m;
|
||||
const bool stopped = (request.cancel && request.cancel->load(std::memory_order_relaxed)) || Clock::now() >= deadline ||
|
||||
result.info.reason == "timeout" || result.info.reason == "no_route_enclosed";
|
||||
if (tight_corners && (!graph_ok || detour) && !stopped)
|
||||
{
|
||||
Path tight_path;
|
||||
PathCheck tight_check;
|
||||
PlanInfo tight_info = result.info;
|
||||
tight_info.live_ridge.clear();
|
||||
const bool tight_ok = detail::planGraphTier({ *graph, request, live, deadline, config, backend },
|
||||
{ tight_path, tight_check, tight_info });
|
||||
// A tight corner must buy a clearly shorter path; otherwise the large-radius shape stays.
|
||||
if (tight_ok && (!graph_ok || polylineLength(tight_path) < (1.0 - kTightMinSaving) * polylineLength(result.path)))
|
||||
{
|
||||
result.path = std::move(tight_path);
|
||||
result.check = tight_check;
|
||||
result.info = tight_info;
|
||||
result.info.graph_radius_pass = "tight";
|
||||
graph_ok = true;
|
||||
}
|
||||
else if (!graph_ok)
|
||||
{
|
||||
result.info = tight_info;
|
||||
}
|
||||
}
|
||||
if (graph_ok && result.info.graph_radius_pass.empty())
|
||||
result.info.graph_radius_pass = "regular";
|
||||
}
|
||||
result.info.graph_reason = result.info.reason;
|
||||
result.info.graph_rung_reasons.push_back(result.info.graph_reason);
|
||||
@@ -168,7 +226,7 @@ PlanResult planRoute(const GraphProvider& graphs, const RouteRequest& request, c
|
||||
break;
|
||||
}
|
||||
const TimePoint rung_deadline = now + (fallback_deadline - now) / static_cast<Clock::duration::rep>(rungs.size() - rung);
|
||||
if (detail::planLatticeTier({ request, live, config, deviation, rung_deadline, fallback_deadline },
|
||||
if (detail::planLatticeTier({ request, live, lattice_config, deviation, rung_deadline, fallback_deadline },
|
||||
{ result.path, result.check, result.info }))
|
||||
{
|
||||
result.ok = true;
|
||||
|
||||
Reference in New Issue
Block a user