feat(lane_route): footprint standability, unknown cells in graph gap (R2.8)
- Standability: a cell is passable for the graph length reference and the lattice heuristic field only when the footprint plus the minimum gap fits at one of 16 headings; memoised per 32x32 tile, open space skips the test. - Graph reference no longer cuts diagonal corners; route_too_long reports the reference length. - Lattice field: coarse block passability decided lazily on first touch. - ReferenceMemo: one route_too_long reference search per core pass instead of one per candidate. - Graph tier counts unknown cells as obstacles for the footprint gap, like the lattice (user ruling 10/11). - PlanInfo and eval JSON: standability counters, graph reference length.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <queue>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -20,6 +21,7 @@
|
||||
#include <lane_route_core/costmap_backend.h>
|
||||
|
||||
#include "../src/lattice_internal.h"
|
||||
#include "../src/standability.h"
|
||||
|
||||
using namespace lane_route_core;
|
||||
|
||||
@@ -644,6 +646,35 @@ TEST_F(PlanRouteTest, WallAcrossTheCorridorIsNoRoute)
|
||||
EXPECT_EQ(result.info.reason, "no_route_enclosed");
|
||||
}
|
||||
|
||||
TEST_F(PlanRouteTest, GraphFootprintGapCountsUnknownCells)
|
||||
{
|
||||
map_.finish(config_);
|
||||
// Unknown cells in row 37 (y 1.85-1.90) for x 6-8 m: 20 mm above the footprint of a straight path at y = 1.53.
|
||||
std::vector<uint8_t> live = map_.cost();
|
||||
for (int x = 120; x < 160; ++x)
|
||||
live[static_cast<std::size_t>(37 * 320 + x)] = kNoInformation;
|
||||
const RouteRequest request{ pose(1.0, 1.53, 0.0), pose(14.0, 1.53, 0.0), {} };
|
||||
GridRef grid = map_.compileGrid();
|
||||
grid.cost = live.data();
|
||||
const Path direct{ { 1.0, 1.53, 0.0, 0.0 }, { 14.0, 1.53, 0.0, 0.0 } };
|
||||
ASSERT_TRUE(checkFootprintGap(direct, grid, config_.footprint_min_gap_m, config_.half_x_m, config_.half_y_m).valid);
|
||||
ASSERT_FALSE(checkFootprintGap(direct, grid, config_.footprint_min_gap_m, config_.half_x_m, config_.half_y_m, nullptr,
|
||||
nullptr, true).valid);
|
||||
// Graph only: the candidate along the direct line is rejected. Its shortcut raise uses the lethal clearance field, so the
|
||||
// graph cannot move the line away from unknown cells by itself; it fails instead of returning the 20 mm path.
|
||||
const PlanResult graph_only = planWithObstacle(request, live);
|
||||
EXPECT_FALSE(graph_only.ok);
|
||||
EXPECT_EQ(graph_only.info.reason, "footprint_gap_below_minimum");
|
||||
// With the fallback the lattice, which already counted unknown cells, returns a path that keeps the gap.
|
||||
config_.lattice_enabled = true;
|
||||
config_.lattice_preferred_gap_m = 0.0;
|
||||
const PlanResult result = planWithObstacle(request, live);
|
||||
expectLegal(result, request, config_);
|
||||
EXPECT_EQ(result.info.tier_used, "lattice");
|
||||
EXPECT_TRUE(checkFootprintGap(result.path, grid, config_.footprint_min_gap_m, config_.half_x_m, config_.half_y_m, nullptr,
|
||||
nullptr, true).valid);
|
||||
}
|
||||
|
||||
TEST_F(PlanRouteTest, GoesAroundAPartialObstacle)
|
||||
{
|
||||
map_.finish(config_);
|
||||
@@ -1581,6 +1612,10 @@ TEST(LatticeField, BlocksUseAnyFreeLargestClearanceAndCentreDirection)
|
||||
map.clearance[map.width + 3] = 5000; // Largest clearance is selected even in a blocked cell.
|
||||
map.direction[map.width + 3] = 5; // Centre cell points west; other cells are unconstrained.
|
||||
PlannerConfig config = latticeConfig();
|
||||
// This synthetic two-row grid tests block aggregation, not a full-size robot at the map boundary.
|
||||
config.half_x_m = 0.005;
|
||||
config.half_y_m = 0.005;
|
||||
config.footprint_min_gap_m = 0.0;
|
||||
config.lattice_field_cell_factor = 2;
|
||||
config.lattice_field_clearance_weight_m = 0.5; // The expected 0.26 below uses this weight.
|
||||
RouteRequest request = latticeRequest(pose(0.225, 0.025, 0.0), pose(0.025, 0.025, 0.0));
|
||||
@@ -2086,3 +2121,170 @@ TEST(LatticeFieldMargin, MarginThatClosesTheOnlyWayFallsBackToThePlainField)
|
||||
ASSERT_TRUE(result.ok) << result.info.reason;
|
||||
EXPECT_EQ(result.info.tier_used, "lattice");
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void exactTestClearance(LatticeTestGrid* map)
|
||||
{
|
||||
std::vector<std::pair<int, int>> lethal;
|
||||
for (int y = 0; y < map->height; ++y)
|
||||
for (int x = 0; x < map->width; ++x)
|
||||
if (map->cost[static_cast<std::size_t>(y) * map->width + x] == kLethalCost)
|
||||
lethal.emplace_back(x, y);
|
||||
for (int y = 0; y < map->height; ++y)
|
||||
for (int x = 0; x < map->width; ++x)
|
||||
{
|
||||
double d = 10.0;
|
||||
for (const auto& obstacle : lethal)
|
||||
d = std::min(d, std::hypot(x - obstacle.first, y - obstacle.second) * kResolution);
|
||||
map->clearance[static_cast<std::size_t>(y) * map->width + x] = static_cast<uint16_t>(std::floor(d * 1000.0));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(Standability, PostsRejectEverySampledHeadingAndReferenceDetours)
|
||||
{
|
||||
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 config = latticeConfig();
|
||||
config.half_x_m = 0.5; config.half_y_m = 0.15; config.footprint_min_gap_m = 0.03;
|
||||
GridRef grid = map.view();
|
||||
uint64_t tests = 0, rejected = 0;
|
||||
detail::LatticeMemory memory(16 * 1024 * 1024);
|
||||
detail::Standability standability(grid, config, &memory, &tests, &rejected, nullptr, nullptr);
|
||||
EXPECT_FALSE(standability.fits(cy * map.width + cx));
|
||||
EXPECT_EQ(tests, 1u);
|
||||
EXPECT_FALSE(standability.fits(cy * map.width + cx));
|
||||
EXPECT_EQ(tests, 1u); // Memoised even for a rejected cell.
|
||||
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));
|
||||
EXPECT_GT(reference, 3.2); // The point-grid route through the four posts is about 3.04 m.
|
||||
double bounded_reference = 0.0;
|
||||
EXPECT_FALSE(detail::shortestStandableReference(grid, start, goal, 90.0, 3.2, &bounded_reference, standability));
|
||||
RouteRequest request = latticeRequest(pose(start.x, start.y, 0.0), pose(goal.x, goal.y, 0.0));
|
||||
PlanInfo info;
|
||||
const auto deadline = detail::Clock::now() + std::chrono::seconds(10);
|
||||
detail::LatticeContext context{request, grid, config, 90.0, deadline, info, memory};
|
||||
detail::LatticeField field(&memory);
|
||||
ASSERT_TRUE(detail::buildLatticeField(context, &field, deadline));
|
||||
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);
|
||||
}
|
||||
|
||||
TEST(Standability, NarrowCorridorFitsLengthwise)
|
||||
{
|
||||
LatticeTestGrid map(100, 100);
|
||||
for (int x = 25; x <= 75; ++x)
|
||||
{
|
||||
map.cost[static_cast<std::size_t>(45) * map.width + x] = kLethalCost;
|
||||
map.cost[static_cast<std::size_t>(55) * 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;
|
||||
GridRef grid = map.view();
|
||||
uint64_t tests = 0, rejected = 0;
|
||||
detail::Standability standability(grid, config, std::pmr::get_default_resource(), &tests, &rejected, nullptr, nullptr);
|
||||
const int cell = 50 * map.width + 50;
|
||||
EXPECT_TRUE(standability.fits(cell));
|
||||
EXPECT_GT(tests, 0u);
|
||||
EXPECT_FALSE(footprintCollides(grid, 2.525, 2.525, 0.0, 0.53, 0.18));
|
||||
EXPECT_TRUE(footprintCollides(grid, 2.525, 2.525, kPi / 2.0, 0.53, 0.18));
|
||||
}
|
||||
|
||||
TEST(Standability, ReferenceDoesNotCutDiagonalBetweenObstacles)
|
||||
{
|
||||
LatticeTestGrid map(5, 5);
|
||||
std::fill(map.cost.begin(), map.cost.end(), kLethalCost);
|
||||
map.cost[1 * map.width + 1] = kFreeSpace;
|
||||
map.cost[2 * map.width + 2] = kFreeSpace;
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.half_x_m = config.half_y_m = 0.005; config.footprint_min_gap_m = 0.0;
|
||||
GridRef grid = map.view();
|
||||
detail::Standability standability(grid, config, std::pmr::get_default_resource(), nullptr, nullptr, nullptr, nullptr);
|
||||
double reference = 0.0;
|
||||
EXPECT_FALSE(detail::shortestStandableReference(grid, {0.075, 0.075}, {0.125, 0.125}, 90.0, 10.0,
|
||||
&reference, standability));
|
||||
}
|
||||
|
||||
TEST(Standability, ReferenceMemoMatchesDirectSearchForEveryBound)
|
||||
{
|
||||
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 config = latticeConfig();
|
||||
config.half_x_m = 0.5; config.half_y_m = 0.15; config.footprint_min_gap_m = 0.03;
|
||||
GridRef grid = map.view();
|
||||
detail::Standability standability(grid, config, std::pmr::get_default_resource(), nullptr, nullptr, nullptr, nullptr);
|
||||
const Point2 start{1.025, 2.525}, goal{4.025, 2.525};
|
||||
double exact = 0.0;
|
||||
ASSERT_TRUE(detail::shortestStandableReference(grid, start, goal, 90.0, 100.0, &exact, standability));
|
||||
|
||||
// Empty bound first: the memo keeps it, a smaller bound stays empty, a larger one searches again.
|
||||
detail::ReferenceMemo memo;
|
||||
double reference = 0.0;
|
||||
EXPECT_FALSE(detail::cachedStandableReference(grid, start, goal, 90.0, 3.2, &reference, standability, memo, nullptr, nullptr));
|
||||
EXPECT_DOUBLE_EQ(memo.empty_bound_m, 3.2);
|
||||
EXPECT_FALSE(detail::cachedStandableReference(grid, start, goal, 90.0, 3.1, &reference, standability, memo, nullptr, nullptr));
|
||||
ASSERT_TRUE(detail::cachedStandableReference(grid, start, goal, 90.0, 100.0, &reference, standability, memo, nullptr, nullptr));
|
||||
EXPECT_DOUBLE_EQ(reference, exact);
|
||||
EXPECT_DOUBLE_EQ(memo.length_m, exact);
|
||||
// Exact length known: any bound is answered from it, with the same result as a direct search.
|
||||
reference = 0.0;
|
||||
ASSERT_TRUE(detail::cachedStandableReference(grid, start, goal, 90.0, exact + 0.01, &reference, standability, memo, nullptr, nullptr));
|
||||
EXPECT_DOUBLE_EQ(reference, exact);
|
||||
EXPECT_FALSE(detail::cachedStandableReference(grid, start, goal, 90.0, exact - 0.01, &reference, standability, memo, nullptr, nullptr));
|
||||
|
||||
// A cancelled search proves nothing and is not memoised.
|
||||
std::atomic<bool> cancel{true};
|
||||
detail::ReferenceMemo cancelled;
|
||||
EXPECT_FALSE(detail::cachedStandableReference(grid, start, goal, 90.0, 100.0, &reference, standability, cancelled, &cancel, nullptr));
|
||||
EXPECT_LT(cancelled.empty_bound_m, 0.0);
|
||||
EXPECT_LT(cancelled.length_m, 0.0);
|
||||
}
|
||||
|
||||
TEST(Standability, OpenSpaceUsesNoSampledFootprintTests)
|
||||
{
|
||||
LatticeTestGrid map(200, 200);
|
||||
PlannerConfig config = latticeConfig();
|
||||
GridRef grid = map.view();
|
||||
uint64_t tests = 0, rejected = 0;
|
||||
detail::LatticeMemory memory(16 * 1024 * 1024);
|
||||
detail::Standability standability(grid, config, &memory, &tests, &rejected, nullptr, nullptr);
|
||||
double reference = 0.0;
|
||||
ASSERT_TRUE(detail::shortestStandableReference(grid, {4.025, 5.025}, {6.025, 5.025}, 90.0, 10.0,
|
||||
&reference, standability));
|
||||
EXPECT_EQ(tests, 0u);
|
||||
EXPECT_EQ(rejected, 0u);
|
||||
RouteRequest request = latticeRequest(pose(4.025, 5.025, 0.0), pose(6.025, 5.025, 0.0));
|
||||
PlanInfo info;
|
||||
const auto deadline = detail::Clock::now() + std::chrono::seconds(10);
|
||||
detail::LatticeContext context{request, grid, config, 90.0, deadline, info, memory};
|
||||
detail::LatticeField field(&memory);
|
||||
ASSERT_TRUE(detail::buildLatticeField(context, &field, deadline));
|
||||
EXPECT_EQ(info.lattice_standability_tests, 0u);
|
||||
}
|
||||
|
||||
TEST(Standability, UnknownCellsAreCheckedDespiteHighLethalClearance)
|
||||
{
|
||||
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] = kNoInformation;
|
||||
PlannerConfig config = latticeConfig();
|
||||
config.half_x_m = 0.5; config.half_y_m = 0.15; config.footprint_min_gap_m = 0.03;
|
||||
GridRef grid = map.view();
|
||||
uint64_t tests = 0, rejected = 0;
|
||||
detail::Standability standability(grid, config, std::pmr::get_default_resource(), &tests, &rejected, nullptr, nullptr);
|
||||
EXPECT_FALSE(standability.fits(cy * map.width + cx));
|
||||
EXPECT_EQ(tests, 1u);
|
||||
EXPECT_EQ(rejected, 1u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user