feat(lane_route): add lane_route_core and lane_route_planner (R0 + R1)
lane_route_core plans on a precomputed coarse graph (Voronoi ridges and direction-zone lanes) and, when enabled, falls back to a weighted A* search over an SE(2) lattice that enforces forward motion, the minimum turn radius, end-only spins, the footprint gap and direction zones. - R0: route_planner.cpp split into graph search, path building and the graph tier; regress7 output identical to the previous build. - R1: lattice tier (lazy packed C-space tiles, direction-aware heuristic field, analytic Dubins and point connectors, end-gap floors counting unknown cells). Off by default (lattice_enabled = false). - lane_route_eval takes an optional tier mode and LANE_ROUTE_EVAL_SET overrides for offline tuning. Local snapshot for history only; not pushed.
This commit is contained in:
154
src/lattice_internal.h
Normal file
154
src/lattice_internal.h
Normal file
@@ -0,0 +1,154 @@
|
||||
#ifndef LANE_ROUTE_CORE_LATTICE_INTERNAL_H_
|
||||
#define LANE_ROUTE_CORE_LATTICE_INTERNAL_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory_resource>
|
||||
#include <new>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "route_planner_internal.h"
|
||||
|
||||
namespace lane_route_core
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// All persistent search containers use this resource, including temporary growth during reallocation.
|
||||
class LatticeMemory final : public std::pmr::memory_resource
|
||||
{
|
||||
public:
|
||||
explicit LatticeMemory(std::size_t limit) : limit_(limit) {}
|
||||
std::size_t peak() const { return peak_; }
|
||||
|
||||
private:
|
||||
void* do_allocate(std::size_t bytes, std::size_t alignment) override
|
||||
{
|
||||
if (bytes > limit_ - used_)
|
||||
throw std::bad_alloc();
|
||||
void* p = std::pmr::new_delete_resource()->allocate(bytes, alignment);
|
||||
used_ += bytes;
|
||||
if (used_ > peak_)
|
||||
peak_ = used_;
|
||||
return p;
|
||||
}
|
||||
void do_deallocate(void* p, std::size_t bytes, std::size_t alignment) override
|
||||
{
|
||||
std::pmr::new_delete_resource()->deallocate(p, bytes, alignment);
|
||||
used_ -= bytes;
|
||||
}
|
||||
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; }
|
||||
std::size_t limit_, used_ = 0, peak_ = 0;
|
||||
};
|
||||
|
||||
struct LatticeContext
|
||||
{
|
||||
const RouteRequest& request;
|
||||
const GridRef& grid;
|
||||
const PlannerConfig& config;
|
||||
double deviation_deg;
|
||||
TimePoint deadline;
|
||||
PlanInfo& info;
|
||||
LatticeMemory& memory;
|
||||
|
||||
bool cancelled() const { return request.cancel && request.cancel->load(std::memory_order_relaxed); }
|
||||
bool expired() const { return cancelled() || Clock::now() >= deadline; }
|
||||
};
|
||||
|
||||
struct LatticeTierInput
|
||||
{
|
||||
const RouteRequest& request;
|
||||
const GridRef& grid;
|
||||
const PlannerConfig& config;
|
||||
double deviation_deg;
|
||||
TimePoint deadline;
|
||||
};
|
||||
|
||||
struct LatticeStateKey
|
||||
{
|
||||
int32_t x, y, heading;
|
||||
bool operator==(const LatticeStateKey& other) const { return x == other.x && y == other.y && heading == other.heading; }
|
||||
};
|
||||
|
||||
struct LatticeOpenEntry
|
||||
{
|
||||
long double priority;
|
||||
uint64_t serial;
|
||||
std::size_t node;
|
||||
};
|
||||
|
||||
inline long double latticeBucketPriority(double f, double width_m)
|
||||
{
|
||||
return width_m > 0.0 ? std::floor(static_cast<long double>(f) / width_m) : static_cast<long double>(f);
|
||||
}
|
||||
|
||||
struct LatticeOpenOrder
|
||||
{
|
||||
bool operator()(const LatticeOpenEntry& a, const LatticeOpenEntry& b) const
|
||||
{
|
||||
return a.priority != b.priority ? a.priority > b.priority : a.serial > b.serial;
|
||||
}
|
||||
};
|
||||
|
||||
double latticeMotionCost(double length, double clearance, int steer, int last_steer, int multiple, const PlannerConfig& config);
|
||||
|
||||
struct LatticePointConnector
|
||||
{
|
||||
double curvature, arc_length_m, straight_length_m, arrival_yaw;
|
||||
};
|
||||
|
||||
bool latticePointConnector(const PathPoint& start, const Point2& goal, double radius, int turn,
|
||||
LatticePointConnector* connector);
|
||||
|
||||
// One tile stores lazy C-space samples, not a cropped search window. A zero entry is unknown,
|
||||
// one is conservatively free and two requires an exact check at the actual pose.
|
||||
class LatticeCSpace
|
||||
{
|
||||
public:
|
||||
explicit LatticeCSpace(LatticeContext& context);
|
||||
bool poseFree(double x, double y, double yaw, double sweep_margin = 0.0, double centre_sweep = 0.0);
|
||||
bool segmentLegal(const PathPoint& a, const PathPoint& b);
|
||||
bool spinLegal(double x, double y, double from, double to);
|
||||
|
||||
private:
|
||||
struct Tile
|
||||
{
|
||||
Tile(std::pmr::memory_resource* resource, std::size_t size) : samples(resource) { samples.resize((size + 3) / 4, 0); }
|
||||
std::pmr::vector<uint8_t> samples;
|
||||
};
|
||||
LatticeContext& context_;
|
||||
std::pmr::unordered_map<uint64_t, Tile> tiles_;
|
||||
std::pmr::vector<uint32_t> blocked_prefix_;
|
||||
bool prefix_ready_ = false;
|
||||
double start_floor_ = 0.0; // [m] Gap margin allowed near the start, see endFloor().
|
||||
double goal_floor_ = 0.0; // [m] Same near the goal.
|
||||
double endFloor(const Pose2& pose) const;
|
||||
bool buildBlockedPrefix();
|
||||
uint32_t blockedCount(int32_t x0, int32_t y0, int32_t x1, int32_t y1) const;
|
||||
};
|
||||
|
||||
struct LatticeField
|
||||
{
|
||||
explicit LatticeField(std::pmr::memory_resource* resource) : values(resource), settled(resource) {}
|
||||
std::pmr::vector<float> values;
|
||||
std::pmr::vector<uint8_t> settled;
|
||||
int32_t width = 0, height = 0;
|
||||
int factor = 1;
|
||||
double frontier = 0.0;
|
||||
bool complete = false;
|
||||
double at(double x, double y, const LatticeContext& context) const;
|
||||
};
|
||||
|
||||
bool rejectLatticeCrossing(LatticeContext& context, const Path& path);
|
||||
bool verifyLatticeCandidate(LatticeContext& context, const Path& path, PathCheck* check);
|
||||
bool buildLatticeField(LatticeContext& context, LatticeField* field, TimePoint field_deadline);
|
||||
bool searchLattice(LatticeContext& context, LatticeCSpace& space, const LatticeField& field, Path* path, PathCheck* check);
|
||||
bool planLatticeTier(const LatticeTierInput& input, GraphTierOutput output);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace lane_route_core
|
||||
|
||||
#endif // LANE_ROUTE_CORE_LATTICE_INTERNAL_H_
|
||||
Reference in New Issue
Block a user