feat(lane_route): heuristic-only standability relax for the lattice field (R2.9)
- lattice_field_standability_relax_m (default 0): shrinks the inflated footprint half sizes for the lattice heuristic field only; graph reference, C-space and verification stay strict. - Plugin loads it, prints it on the fallback boot line; README and eval override key. - Measured 10/11: with extra field clearance 0 any relax reopens the sim post gaps (dumps 1, 2, 4 time out); with extra clearance 0.1 a relax of 0.035 keeps them and gains one kit query.
This commit is contained in:
@@ -158,6 +158,8 @@ struct PlannerConfig
|
||||
/// [m] Extra clearance a cell needs to count as passable in the heuristic field only; the search itself is unchanged.
|
||||
/// 0 keeps the half-width rule. Higher keeps the field out of gaps barely wider than the robot.
|
||||
double lattice_field_extra_clearance_m = 0.0;
|
||||
/// [m] Shrink inflated footprint half sizes for heuristic-field standability only; 0 is strict.
|
||||
double lattice_field_standability_relax_m = 0.0;
|
||||
double lattice_field_time_fraction = 0.4; ///< Fraction of a rung's fallback slice for the field.
|
||||
int lattice_field_cell_factor = 0; ///< 0 selects automatically, 1 uses the original grid resolution.
|
||||
int64_t lattice_field_max_cells = 1000000; ///< Maximum cells for automatic field sizing.
|
||||
|
||||
@@ -114,8 +114,9 @@ std::string PlannerConfig::validate() const
|
||||
error << "regular_turn_radius_m must be finite and > 0";
|
||||
else if (!not_negative(max_kink_deg) || max_kink_deg > 90.0)
|
||||
error << "max_kink_deg must be in [0, 90]";
|
||||
else if (lattice_enabled && (!not_negative(lattice_tight_turn_cost_m) || !not_negative(lattice_field_extra_clearance_m)))
|
||||
error << "lattice_tight_turn_cost_m and lattice_field_extra_clearance_m must be finite and >= 0";
|
||||
else if (lattice_enabled && (!not_negative(lattice_tight_turn_cost_m) || !not_negative(lattice_field_extra_clearance_m) ||
|
||||
!not_negative(lattice_field_standability_relax_m)))
|
||||
error << "lattice_tight_turn_cost_m, lattice_field_extra_clearance_m and lattice_field_standability_relax_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]";
|
||||
|
||||
@@ -83,13 +83,18 @@ bool buildLatticeField(LatticeContext& context, LatticeField* field, TimePoint f
|
||||
if (cells64 > std::numeric_limits<int32_t>::max()) return true;
|
||||
const std::size_t cells = static_cast<std::size_t>(cells64);
|
||||
|
||||
// The extra field margin remains a separate heuristic filter; standability always uses the hard minimum gap.
|
||||
// The extra field clearance remains a separate heuristic filter, independent of standability relaxation.
|
||||
const PlannerConfig& config = context.config;
|
||||
const double fit_m = std::min(config.half_x_m, config.half_y_m) + config.footprint_min_gap_m - g.resolution +
|
||||
std::max(0.0, extra_clearance_m);
|
||||
const uint16_t fit_mm = static_cast<uint16_t>(std::max(0.0, std::min(65535.0, std::floor(fit_m * 1000.0))));
|
||||
// res/sqrt(2) covers translation from any position in a cell to its centre; an additional
|
||||
// 2*R*sin(pi/64), where R is the inflated footprint circumradius, covers headings between
|
||||
// the 16 samples. Larger relaxations can reopen gaps where no heading fits (closed in R2.8).
|
||||
// This changes only the heuristic; search and verification use the full footprint and gap.
|
||||
Standability standability(g, config, &context.memory, &context.info.lattice_standability_tests,
|
||||
&context.info.lattice_standability_rejected, context.request.cancel, &field_deadline);
|
||||
&context.info.lattice_standability_rejected, context.request.cancel, &field_deadline,
|
||||
config.lattice_field_standability_relax_m);
|
||||
const auto fits = [&](std::size_t cell) {
|
||||
return (extra_clearance_m <= 0.0 || g.clearance_mm[cell] >= fit_mm) &&
|
||||
standability.fits(cell);
|
||||
|
||||
@@ -11,8 +11,10 @@ namespace detail
|
||||
{
|
||||
Standability::Standability(const GridRef& grid, const PlannerConfig& config, std::pmr::memory_resource* memory,
|
||||
uint64_t* tests, uint64_t* rejected, const std::atomic<bool>* cancel,
|
||||
const std::chrono::steady_clock::time_point* deadline)
|
||||
: grid_(grid), config_(config), tiles_(memory), tests_(tests), rejected_(rejected), cancel_(cancel), deadline_(deadline)
|
||||
const std::chrono::steady_clock::time_point* deadline, double relax_m)
|
||||
: grid_(grid), half_x_m_(std::max(0.0, config.half_x_m + config.footprint_min_gap_m - relax_m)),
|
||||
half_y_m_(std::max(0.0, config.half_y_m + config.footprint_min_gap_m - relax_m)),
|
||||
tiles_(memory), tests_(tests), rejected_(rejected), cancel_(cancel), deadline_(deadline)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,8 +26,7 @@ bool Standability::stopped() const
|
||||
|
||||
bool Standability::tileHasBlocked(int32_t tx, int32_t ty) const
|
||||
{
|
||||
const double radius = std::hypot(config_.half_x_m + config_.footprint_min_gap_m,
|
||||
config_.half_y_m + config_.footprint_min_gap_m);
|
||||
const double radius = std::hypot(half_x_m_, half_y_m_);
|
||||
const double max_pad = static_cast<double>(std::max(grid_.width, grid_.height)) + 2.0;
|
||||
const int64_t pad = static_cast<int64_t>(std::min(max_pad, std::ceil(radius / grid_.resolution) + 2.0));
|
||||
const int32_t x0 = static_cast<int32_t>(std::max<int64_t>(0, static_cast<int64_t>(tx) * 32 - pad));
|
||||
@@ -57,8 +58,8 @@ bool Standability::fits(std::size_t cell)
|
||||
if (rejected_) ++*rejected_;
|
||||
return false;
|
||||
}
|
||||
const double hx = config_.half_x_m + config_.footprint_min_gap_m;
|
||||
const double hy = config_.half_y_m + config_.footprint_min_gap_m;
|
||||
const double hx = half_x_m_;
|
||||
const double hy = half_y_m_;
|
||||
const double radius = std::hypot(hx, hy);
|
||||
const double wx = grid_.origin_x + (x + 0.5) * grid_.resolution;
|
||||
const double wy = grid_.origin_y + (y + 0.5) * grid_.resolution;
|
||||
|
||||
@@ -22,7 +22,7 @@ class Standability
|
||||
public:
|
||||
Standability(const GridRef& grid, const PlannerConfig& config, std::pmr::memory_resource* memory,
|
||||
uint64_t* tests, uint64_t* rejected, const std::atomic<bool>* cancel,
|
||||
const std::chrono::steady_clock::time_point* deadline);
|
||||
const std::chrono::steady_clock::time_point* deadline, double relax_m = 0.0);
|
||||
bool fits(std::size_t cell);
|
||||
|
||||
private:
|
||||
@@ -35,7 +35,8 @@ private:
|
||||
bool stopped() const;
|
||||
bool tileHasBlocked(int32_t tx, int32_t ty) const;
|
||||
const GridRef& grid_;
|
||||
const PlannerConfig& config_;
|
||||
const double half_x_m_;
|
||||
const double half_y_m_;
|
||||
std::pmr::unordered_map<int64_t, Tile> tiles_;
|
||||
uint64_t* tests_;
|
||||
uint64_t* rejected_;
|
||||
|
||||
@@ -1493,6 +1493,14 @@ TEST(Lattice, InvalidParametersAreRejected)
|
||||
config.lattice_field_cell_factor = -1;
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
config = latticeConfig();
|
||||
config.lattice_field_standability_relax_m = -0.001;
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
config.lattice_field_standability_relax_m = std::numeric_limits<double>::infinity();
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
config.lattice_field_standability_relax_m = -0.001;
|
||||
config.lattice_enabled = false;
|
||||
EXPECT_TRUE(config.validate().empty());
|
||||
config = latticeConfig();
|
||||
config.lattice_field_max_cells = 0;
|
||||
EXPECT_FALSE(config.validate().empty());
|
||||
config = latticeConfig();
|
||||
@@ -2160,6 +2168,8 @@ TEST(Standability, PostsRejectEverySampledHeadingAndReferenceDetours)
|
||||
EXPECT_EQ(tests, 1u);
|
||||
EXPECT_FALSE(standability.fits(cy * map.width + cx));
|
||||
EXPECT_EQ(tests, 1u); // Memoised even for a rejected cell.
|
||||
detail::Standability relaxed_posts(grid, config, &memory, nullptr, nullptr, nullptr, nullptr, 0.035);
|
||||
EXPECT_FALSE(relaxed_posts.fits(cy * map.width + cx));
|
||||
const Point2 start{1.025, 2.525}, goal{4.025, 2.525};
|
||||
double reference = 0.0;
|
||||
ASSERT_TRUE(detail::shortestStandableReference(grid, start, goal, 90.0, 100.0, &reference, standability));
|
||||
@@ -2175,6 +2185,77 @@ TEST(Standability, PostsRejectEverySampledHeadingAndReferenceDetours)
|
||||
ASSERT_EQ(field.factor, 1);
|
||||
EXPECT_EQ(field.settled[static_cast<std::size_t>(cy) * map.width + cx], 0);
|
||||
EXPECT_GT(info.lattice_standability_rejected, 0u);
|
||||
config.lattice_field_standability_relax_m = 0.035;
|
||||
PlanInfo relaxed_info;
|
||||
detail::LatticeContext relaxed_context{request, grid, config, 90.0, deadline, relaxed_info, memory};
|
||||
detail::LatticeField relaxed_field(&memory);
|
||||
ASSERT_TRUE(detail::buildLatticeField(relaxed_context, &relaxed_field, deadline));
|
||||
EXPECT_EQ(relaxed_field.settled[static_cast<std::size_t>(cy) * map.width + cx], 0);
|
||||
}
|
||||
|
||||
TEST(Standability, FieldRelaxationReopensAnOffCentrePose)
|
||||
{
|
||||
LatticeTestGrid map(100, 100);
|
||||
for (int x = 20; x <= 80; ++x)
|
||||
{
|
||||
map.cost[static_cast<std::size_t>(45) * map.width + x] = kLethalCost;
|
||||
map.cost[static_cast<std::size_t>(54) * map.width + x] = kLethalCost;
|
||||
}
|
||||
exactTestClearance(&map);
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.half_x_m = 0.5; config.half_y_m = 0.15; config.footprint_min_gap_m = 0.03;
|
||||
config.lattice_field_cell_factor = 1;
|
||||
config.lattice_field_clearance_weight_m = 0.0;
|
||||
GridRef grid = map.view();
|
||||
const std::size_t cell = static_cast<std::size_t>(50) * map.width + 50;
|
||||
detail::Standability strict(grid, config, std::pmr::get_default_resource(), nullptr, nullptr, nullptr, nullptr);
|
||||
detail::Standability relaxed(grid, config, std::pmr::get_default_resource(), nullptr, nullptr, nullptr, nullptr, 0.035);
|
||||
EXPECT_FALSE(strict.fits(cell));
|
||||
EXPECT_TRUE(relaxed.fits(cell));
|
||||
// The centre is 5 mm short of the 30 mm gap; moving within the same cell clears both walls.
|
||||
EXPECT_TRUE(footprintCollides(grid, 2.525, 2.525, 0.0, 0.53, 0.18));
|
||||
EXPECT_FALSE(footprintCollides(grid, 2.525, 2.510, 0.0, 0.53, 0.18));
|
||||
|
||||
const RouteRequest request = latticeRequest(pose(1.525, 2.525, 0.0), pose(3.525, 2.525, 0.0));
|
||||
const auto deadline = detail::Clock::now() + std::chrono::seconds(10);
|
||||
detail::LatticeMemory memory(16 * 1024 * 1024);
|
||||
PlanInfo strict_info;
|
||||
detail::LatticeContext strict_context{request, grid, config, 90.0, deadline, strict_info, memory};
|
||||
detail::LatticeField strict_field(&memory);
|
||||
ASSERT_TRUE(detail::buildLatticeField(strict_context, &strict_field, deadline));
|
||||
ASSERT_EQ(strict_field.factor, 1);
|
||||
EXPECT_EQ(strict_field.settled[cell], 0);
|
||||
config.lattice_field_standability_relax_m = 0.035;
|
||||
PlanInfo relaxed_info;
|
||||
detail::LatticeContext relaxed_context{request, grid, config, 90.0, deadline, relaxed_info, memory};
|
||||
detail::LatticeField relaxed_field(&memory);
|
||||
ASSERT_TRUE(detail::buildLatticeField(relaxed_context, &relaxed_field, deadline));
|
||||
ASSERT_EQ(relaxed_field.factor, 1);
|
||||
EXPECT_NE(relaxed_field.settled[cell], 0);
|
||||
}
|
||||
|
||||
TEST(Standability, GraphReferenceIgnoresFieldRelaxation)
|
||||
{
|
||||
LatticeTestGrid map(100, 100);
|
||||
const int cx = 50, cy = 50;
|
||||
for (const auto& offset : std::vector<std::pair<int, int>>{{-5, 0}, {5, 0}, {0, -5}, {0, 5}})
|
||||
map.cost[static_cast<std::size_t>(cy + offset.second) * map.width + cx + offset.first] = kLethalCost;
|
||||
exactTestClearance(&map);
|
||||
PlannerConfig strict_config = latticeConfig();
|
||||
strict_config.half_x_m = 0.5; strict_config.half_y_m = 0.15; strict_config.footprint_min_gap_m = 0.03;
|
||||
PlannerConfig field_config = strict_config;
|
||||
field_config.lattice_field_standability_relax_m = 0.035;
|
||||
GridRef grid = map.view();
|
||||
detail::Standability strict(grid, strict_config, std::pmr::get_default_resource(), nullptr, nullptr, nullptr, nullptr);
|
||||
detail::Standability graph_with_field_relax(grid, field_config, std::pmr::get_default_resource(), nullptr, nullptr, nullptr, nullptr);
|
||||
EXPECT_FALSE(strict.fits(cy * map.width + cx));
|
||||
EXPECT_FALSE(graph_with_field_relax.fits(cy * map.width + cx));
|
||||
const Point2 start{1.025, 2.525}, goal{4.025, 2.525};
|
||||
double first = 0.0, second = 0.0;
|
||||
ASSERT_TRUE(detail::shortestStandableReference(grid, start, goal, 90.0, 100.0, &first, strict));
|
||||
ASSERT_TRUE(detail::shortestStandableReference(grid, start, goal, 90.0, 100.0, &second, graph_with_field_relax));
|
||||
EXPECT_DOUBLE_EQ(first, second);
|
||||
EXPECT_GT(first, 3.2);
|
||||
}
|
||||
|
||||
TEST(Standability, NarrowCorridorFitsLengthwise)
|
||||
|
||||
@@ -145,6 +145,7 @@ void applyOverrides(PlannerConfig* config)
|
||||
{ "regular_turn_radius_m", &config->regular_turn_radius_m },
|
||||
{ "lattice_tight_turn_cost_m", &config->lattice_tight_turn_cost_m },
|
||||
{ "lattice_field_extra_clearance_m", &config->lattice_field_extra_clearance_m },
|
||||
{ "lattice_field_standability_relax_m", &config->lattice_field_standability_relax_m },
|
||||
};
|
||||
const std::map<std::string, int*> ints{
|
||||
{ "lattice_heading_bins", &config->lattice_heading_bins },
|
||||
|
||||
Reference in New Issue
Block a user