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:
583
test/lane_route_planner_test.cpp
Normal file
583
test/lane_route_planner_test.cpp
Normal file
@@ -0,0 +1,583 @@
|
||||
#include <lane_route_planner/lane_route_session.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <lane_route_core/costmap_backend.h>
|
||||
|
||||
using namespace lane_route_planner;
|
||||
using namespace lane_route_core;
|
||||
using namespace robot_costmap_2d;
|
||||
|
||||
namespace
|
||||
{
|
||||
robot_geometry_msgs::PoseStamped pose(double x, double y, double yaw = 0)
|
||||
{
|
||||
robot_geometry_msgs::PoseStamped p;
|
||||
p.header.frame_id = "map";
|
||||
p.pose.position.x = x;
|
||||
p.pose.position.y = y;
|
||||
p.pose.orientation.z = std::sin(yaw / 2);
|
||||
p.pose.orientation.w = std::cos(yaw / 2);
|
||||
return p;
|
||||
}
|
||||
|
||||
SessionRequest validRequest(std::vector<uint8_t>& cost)
|
||||
{
|
||||
SessionRequest r;
|
||||
r.initialized = true;
|
||||
r.frame = "map";
|
||||
r.live.width = 40;
|
||||
r.live.height = 40;
|
||||
r.live.resolution = 0.05;
|
||||
r.live.cost = cost.data();
|
||||
auto graph = std::make_shared<ReferenceGraph>();
|
||||
graph->geometry = { 40, 40, 0.05, 0, 0, "map" };
|
||||
graph->static_cost = cost;
|
||||
graph->clearance_mm.assign(cost.size(), 1000);
|
||||
r.graph = { ReferenceGraphState::kReady, graph, 1 };
|
||||
r.footprint = rectangleFootprint(0.30, 0.30);
|
||||
r.inscribed_radius_m = 0.30;
|
||||
r.start = pose(0.6, 0.6);
|
||||
r.goal = pose(1.2, 1.2);
|
||||
return r;
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, NotInitialized)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.initialized = false;
|
||||
EXPECT_EQ(validateRequest(r), "not_initialized");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, InvalidStart)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.start.pose.orientation.w = std::numeric_limits<double>::quiet_NaN();
|
||||
EXPECT_EQ(validateRequest(r), "invalid_start_pose");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, InvalidGoal)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.goal.pose.position.x = std::numeric_limits<double>::infinity();
|
||||
EXPECT_EQ(validateRequest(r), "invalid_goal_pose");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, Frame)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.goal.header.frame_id = "odom";
|
||||
EXPECT_EQ(validateRequest(r), "frame_mismatch");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, DisabledGraph)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.graph.state = ReferenceGraphState::kDisabled;
|
||||
EXPECT_EQ(validateRequest(r), "graph_disabled");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, PendingGraph)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.graph.state = ReferenceGraphState::kPending;
|
||||
EXPECT_EQ(validateRequest(r), "graph_pending");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, PendingDirection)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.direction.state = DirectionFieldState::kPending;
|
||||
EXPECT_EQ(validateRequest(r), "direction_pending");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, MissingReadyGraph)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.graph.graph.reset();
|
||||
EXPECT_EQ(validateRequest(r), "graph_pending");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, MissingReadyDirection)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.direction.state = DirectionFieldState::kReady;
|
||||
EXPECT_EQ(validateRequest(r), "direction_pending");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, DirectionGeneration)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.direction.generation = 2;
|
||||
EXPECT_EQ(validateRequest(r), "direction_generation_mismatch");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, Geometry)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.live.origin_x = 1;
|
||||
EXPECT_EQ(validateRequest(r), "graph_geometry_mismatch");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, Footprint)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.footprint.resize(2);
|
||||
EXPECT_EQ(validateRequest(r), "invalid_footprint");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, InvalidSnapshotData)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
auto g = std::make_shared<ReferenceGraph>(*r.graph.graph);
|
||||
g->clearance_mm.clear();
|
||||
r.graph.graph = g;
|
||||
EXPECT_EQ(validateRequest(r), "graph_data_invalid");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, InvalidRadius)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.inscribed_radius_m = -1;
|
||||
EXPECT_EQ(validateRequest(r), "invalid_inscribed_radius");
|
||||
}
|
||||
|
||||
TEST(AdapterGuard, StateDoesNotRequireGrid)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
r.live = {};
|
||||
EXPECT_TRUE(validateState(r).empty());
|
||||
EXPECT_EQ(validateGrid(r), "graph_geometry_mismatch");
|
||||
EXPECT_EQ(validateRequest(r), "graph_geometry_mismatch");
|
||||
r.initialized = false;
|
||||
EXPECT_EQ(validateRequest(r), "not_initialized");
|
||||
}
|
||||
|
||||
TEST(AdapterConfig, RejectsInvalidParameters)
|
||||
{
|
||||
SessionConfig c;
|
||||
c.clearance_min_margin_m = -1;
|
||||
const std::string invalid_margin = c.validate();
|
||||
EXPECT_NE(invalid_margin.find("clearance_min_margin_m"), std::string::npos);
|
||||
EXPECT_NE(invalid_margin.find("-1"), std::string::npos);
|
||||
|
||||
c = SessionConfig();
|
||||
c.clearance_min_margin_m = 0.2;
|
||||
c.clearance_preferred_margin_m = 0.1;
|
||||
const std::string inverted_margins = c.validate();
|
||||
EXPECT_NE(inverted_margins.find("clearance_preferred_margin_m"), std::string::npos);
|
||||
EXPECT_NE(inverted_margins.find("0.1"), std::string::npos);
|
||||
EXPECT_NE(inverted_margins.find("clearance_min_margin_m"), std::string::npos);
|
||||
EXPECT_NE(inverted_margins.find("0.2"), std::string::npos);
|
||||
|
||||
c = SessionConfig();
|
||||
c.clearance_preferred_margin_m = -0.5;
|
||||
const std::string invalid_preferred = c.validate();
|
||||
EXPECT_NE(invalid_preferred.find("clearance_preferred_margin_m"), std::string::npos);
|
||||
EXPECT_NE(invalid_preferred.find("-0.5"), std::string::npos);
|
||||
|
||||
c = SessionConfig();
|
||||
c.collision_check_margin_m = -0.25;
|
||||
const std::string invalid_collision = c.validate();
|
||||
EXPECT_NE(invalid_collision.find("collision_check_margin_m"), std::string::npos);
|
||||
EXPECT_NE(invalid_collision.find("-0.25"), std::string::npos);
|
||||
|
||||
c = SessionConfig();
|
||||
c.planner.min_turn_radius_m = 0;
|
||||
EXPECT_FALSE(c.validate().empty());
|
||||
c = SessionConfig();
|
||||
c.planner.max_route_attempts = 0;
|
||||
EXPECT_FALSE(c.validate().empty());
|
||||
c = SessionConfig();
|
||||
c.planner.time_limit_s = std::numeric_limits<double>::infinity();
|
||||
EXPECT_FALSE(c.validate().empty());
|
||||
}
|
||||
|
||||
TEST(AdapterConfig, FootprintBoundsAndCollisionDistances)
|
||||
{
|
||||
double x, y;
|
||||
bool rectangle;
|
||||
auto points = rectangleFootprint(0.30, 0.30);
|
||||
ASSERT_TRUE(footprintRectangle(points, &x, &y, &rectangle));
|
||||
EXPECT_TRUE(rectangle);
|
||||
EXPECT_NEAR(std::hypot(x, y) + 0.056, 0.48, 0.001);
|
||||
points = rectangleFootprint(0.325, 0.345);
|
||||
ASSERT_TRUE(footprintRectangle(points, &x, &y, &rectangle));
|
||||
EXPECT_NEAR(std::hypot(x, y) + 0.056, 0.53, 0.001);
|
||||
points[0].x = 0.1;
|
||||
ASSERT_TRUE(footprintRectangle(points, &x, &y, &rectangle));
|
||||
EXPECT_FALSE(rectangle);
|
||||
}
|
||||
|
||||
TEST(AdapterSession, ZeroDeviationUsesOneRung)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
robot_nav_msgs::OccupancyGrid msg;
|
||||
msg.header.frame_id = "map";
|
||||
msg.info.width = 40;
|
||||
msg.info.height = 40;
|
||||
msg.info.resolution = 0.05;
|
||||
msg.data.assign(1600, 1);
|
||||
r.direction = { DirectionFieldState::kReady, DirectionField::create(msg, r.graph.graph->geometry, 0.0), 1 };
|
||||
ASSERT_TRUE(r.direction.field);
|
||||
auto graph = std::make_shared<ReferenceGraph>(*r.graph.graph);
|
||||
graph->direction_generation = 1;
|
||||
r.graph.graph = graph;
|
||||
r.goal = pose(1.2, 0.6);
|
||||
LaneRouteSession session;
|
||||
const auto result = session.plan(r);
|
||||
EXPECT_LE(result.info.rung_reasons.size(), 1u);
|
||||
if (result.ok)
|
||||
EXPECT_DOUBLE_EQ(result.info.rung_used_deg, 0.0);
|
||||
}
|
||||
|
||||
TEST(AdapterSession, CacheDroppedOnGenerationChange)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
LaneRouteSession session;
|
||||
session.plan(r);
|
||||
ASSERT_GT(session.cachedGraphCount(), 0u);
|
||||
const auto compiled = session.compileCount();
|
||||
EXPECT_EQ(session.cachedGeneration(), 1u);
|
||||
r.graph.generation++;
|
||||
std::atomic<bool> cancel{ true };
|
||||
r.cancel = &cancel;
|
||||
// A cancelled request is refused before mutating the cache; the next real request drops it.
|
||||
EXPECT_EQ(session.plan(r).info.reason, "cancelled");
|
||||
cancel = false;
|
||||
r.live.cost = c.data();
|
||||
session.plan(r);
|
||||
EXPECT_GT(session.cachedGraphCount(), 0u);
|
||||
EXPECT_EQ(session.cachedGeneration(), 2u);
|
||||
EXPECT_GT(session.compileCount(), compiled);
|
||||
}
|
||||
|
||||
TEST(AdapterSession, PreferredChangesInvalidateCache)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
LaneRouteSession session;
|
||||
session.plan(r);
|
||||
const auto n = session.compileCount();
|
||||
ASSERT_GT(n, 0u);
|
||||
session.plan(r);
|
||||
EXPECT_EQ(session.compileCount(), n);
|
||||
c[0] = 100;
|
||||
session.plan(r);
|
||||
EXPECT_EQ(session.compileCount(), n);
|
||||
c[0] = 20;
|
||||
session.plan(r);
|
||||
const auto preferred_count = session.compileCount();
|
||||
EXPECT_GT(preferred_count, n);
|
||||
session.plan(r);
|
||||
EXPECT_EQ(session.compileCount(), preferred_count);
|
||||
c[0] = 60;
|
||||
c[1] = 20;
|
||||
session.plan(r);
|
||||
const auto moved_count = session.compileCount();
|
||||
EXPECT_GT(moved_count, preferred_count);
|
||||
c[1] = 60;
|
||||
session.plan(r);
|
||||
const auto cleared_count = session.compileCount();
|
||||
EXPECT_GT(cleared_count, moved_count);
|
||||
session.plan(r);
|
||||
EXPECT_EQ(session.compileCount(), cleared_count);
|
||||
}
|
||||
|
||||
TEST(AdapterSession, PreemptAndNextCall)
|
||||
{
|
||||
std::vector<uint8_t> c(1600, 60);
|
||||
auto r = validRequest(c);
|
||||
auto graph = std::make_shared<ReferenceGraph>(*r.graph.graph);
|
||||
graph->nodes.resize(1000000, ReferencePoint{ 0.5, 0.5 });
|
||||
r.graph.graph = graph;
|
||||
LaneRouteSession session;
|
||||
std::atomic<bool> cancel{ false };
|
||||
r.cancel = &cancel;
|
||||
PlanResult result;
|
||||
std::atomic<bool> started{ false };
|
||||
const auto begin = std::chrono::steady_clock::now();
|
||||
std::thread worker([&]
|
||||
{
|
||||
started = true;
|
||||
result = session.plan(r);
|
||||
});
|
||||
while (!started.load())
|
||||
std::this_thread::yield();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2));
|
||||
cancel = true;
|
||||
worker.join();
|
||||
EXPECT_EQ(result.info.reason, "cancelled");
|
||||
EXPECT_LT(std::chrono::duration<double>(std::chrono::steady_clock::now() - begin).count(), 5.0);
|
||||
cancel = false;
|
||||
r.graph = validRequest(c).graph;
|
||||
r.graph.generation = 2;
|
||||
EXPECT_NE(session.plan(r).info.reason, "cancelled");
|
||||
}
|
||||
|
||||
std::vector<uint8_t> readRuns(std::istream& in, const std::string& expected)
|
||||
{
|
||||
std::string key;
|
||||
std::size_t n;
|
||||
in >> key >> n;
|
||||
if (key != expected)
|
||||
throw std::runtime_error("expected " + expected + ", got " + key);
|
||||
std::vector<uint8_t> values;
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
{
|
||||
int value;
|
||||
std::size_t count;
|
||||
in >> value >> count;
|
||||
values.insert(values.end(), count, static_cast<uint8_t>(value));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
struct Fixture
|
||||
{
|
||||
DirectionGeometry geometry{};
|
||||
ReferenceGraphParams params;
|
||||
std::vector<uint8_t> cost;
|
||||
std::vector<uint8_t> direction;
|
||||
std::shared_ptr<ReferenceGraph> graph;
|
||||
};
|
||||
|
||||
Fixture loadFixture(const std::string& path)
|
||||
{
|
||||
std::ifstream in(path);
|
||||
if (!in)
|
||||
throw std::runtime_error("cannot open fixture " + path);
|
||||
Fixture f;
|
||||
std::string key;
|
||||
int version;
|
||||
double hx, hy;
|
||||
in >> key >> version;
|
||||
if (key != "reference_graph_fixture" || version != 1)
|
||||
throw std::runtime_error("bad fixture");
|
||||
in >> key >> f.geometry.width >> f.geometry.height >> key >> f.geometry.resolution >> key >> f.geometry.origin_x >> f.geometry.origin_y;
|
||||
in >> key >> f.params.min_clearance_m >> f.params.ridge_min_separation_m >> f.params.spur_min_length_m >>
|
||||
f.params.lane_offset_step_m >> hx >> hy;
|
||||
f.geometry.frame_id = "map";
|
||||
f.params.debug_log = false;
|
||||
f.cost = readRuns(in, "cost");
|
||||
f.direction = readRuns(in, "direction");
|
||||
ReferenceGridView view;
|
||||
view.geometry = f.geometry;
|
||||
view.cost = f.cost.data();
|
||||
view.direction_codes = f.direction.data();
|
||||
const auto skeleton = computeVoronoiSkeleton(view, f.params);
|
||||
f.graph = std::make_shared<ReferenceGraph>(buildReferenceGraph(view, skeleton, rectangleFootprint(hx, hy), f.params));
|
||||
return f;
|
||||
}
|
||||
|
||||
struct Scene
|
||||
{
|
||||
std::string id;
|
||||
Pose2 start;
|
||||
Pose2 goal;
|
||||
};
|
||||
|
||||
std::vector<Scene> loadScenes(const std::string& path)
|
||||
{
|
||||
std::ifstream in(path);
|
||||
if (!in)
|
||||
throw std::runtime_error("cannot open scenes " + path);
|
||||
std::vector<Scene> scenes;
|
||||
std::string line;
|
||||
while (std::getline(in, line))
|
||||
{
|
||||
if (line.empty())
|
||||
continue;
|
||||
std::istringstream row(line);
|
||||
Scene s;
|
||||
std::string grid, live;
|
||||
int variant, sy, gy, boxes;
|
||||
row >> s.id >> grid >> variant >> live >> sy >> s.start.x >> s.start.y >> s.start.yaw >> gy >> s.goal.x >>
|
||||
s.goal.y >> s.goal.yaw >> boxes;
|
||||
if (!row || variant != 0 || live != "-" || boxes != 0)
|
||||
throw std::runtime_error("unsupported real scene");
|
||||
s.start.has_yaw = sy != 0;
|
||||
s.goal.has_yaw = gy != 0;
|
||||
scenes.push_back(s);
|
||||
}
|
||||
return scenes;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> loadEvalMaster(const std::string& path)
|
||||
{
|
||||
std::ifstream in(path);
|
||||
if (!in)
|
||||
throw std::runtime_error("cannot open eval grid");
|
||||
std::string key;
|
||||
int version, w, h;
|
||||
double res, ox, oy;
|
||||
in >> key >> version >> key >> w >> h >> key >> res >> key >> ox >> oy;
|
||||
return readRuns(in, "cost");
|
||||
}
|
||||
|
||||
std::vector<uint8_t> inflated(const Fixture& f)
|
||||
{
|
||||
auto cost = f.cost;
|
||||
for (std::size_t i = 0; i < cost.size(); ++i)
|
||||
{
|
||||
if (cost[i] >= kInscribedCost)
|
||||
continue;
|
||||
const double rounded_cells = f.graph->clearance_mm[i] / (1000.0 * f.geometry.resolution);
|
||||
const double d = f.geometry.resolution * std::sqrt(std::round(rounded_cells * rounded_cells));
|
||||
if (d > 0.6)
|
||||
continue;
|
||||
unsigned value = d <= 0.30 ? kInscribedCost : static_cast<unsigned>(252.0 * std::exp(-15.0 * (d - 0.30)));
|
||||
cost[i] = std::max(cost[i], static_cast<uint8_t>(value));
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
DirectionFieldSnapshot direction(const Fixture& f, double degrees, uint64_t generation)
|
||||
{
|
||||
robot_nav_msgs::OccupancyGrid msg;
|
||||
msg.header.frame_id = "map";
|
||||
msg.info.width = f.geometry.width;
|
||||
msg.info.height = f.geometry.height;
|
||||
msg.info.resolution = f.geometry.resolution;
|
||||
msg.info.origin.position.x = f.geometry.origin_x;
|
||||
msg.info.origin.position.y = f.geometry.origin_y;
|
||||
msg.data.assign(f.direction.begin(), f.direction.end());
|
||||
return { DirectionFieldState::kReady, DirectionField::create(msg, f.geometry, degrees * kPi / 180.0), generation };
|
||||
}
|
||||
|
||||
using Json = nlohmann::json;
|
||||
|
||||
std::map<std::pair<std::string, double>, Json> loadReference(const std::string& path)
|
||||
{
|
||||
std::ifstream in(path);
|
||||
if (!in)
|
||||
throw std::runtime_error("cannot open reference " + path);
|
||||
std::map<std::pair<std::string, double>, Json> refs;
|
||||
std::string line;
|
||||
while (std::getline(in, line))
|
||||
{
|
||||
std::size_t pos = 0;
|
||||
while ((pos = line.find(":inf", pos)) != std::string::npos)
|
||||
line.replace(pos, 4, ":null");
|
||||
Json j = Json::parse(line);
|
||||
// In C++17 the right side of an assignment runs first, so the key must be read before j is moved.
|
||||
const std::pair<std::string, double> key(j.at("scene").get<std::string>(), j.at("dev").get<double>());
|
||||
refs[key] = std::move(j);
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
void runParity(bool real_inflation)
|
||||
{
|
||||
const char* env = std::getenv("LANE_ROUTE_FIXTURE_DIR");
|
||||
if (!env)
|
||||
{
|
||||
// The installed gtest predates GTEST_SKIP.
|
||||
std::cout << "[ SKIPPED ] Set LANE_ROUTE_FIXTURE_DIR to oneway_eval/results" << std::endl;
|
||||
return;
|
||||
}
|
||||
const std::string base(env);
|
||||
const auto fixture = loadFixture(base + "/r12_cpp_fixtures/text/sehc.fixture");
|
||||
auto master = real_inflation ? inflated(fixture) : loadEvalMaster(base + "/r12_cpp_eval/sehc.grid");
|
||||
const auto scenes = loadScenes(base + "/r12_cpp_eval/sehc_real.txt");
|
||||
const auto refs = loadReference(base + "/r15_cpp_eval/out_real.jsonl");
|
||||
ASSERT_EQ(scenes.size(), 12u);
|
||||
ASSERT_EQ(refs.size(), 60u);
|
||||
SessionConfig config;
|
||||
config.collision_check_margin_m = 0.48 - std::hypot(0.30, 0.30);
|
||||
LaneRouteSession session(config);
|
||||
const double levels[] = { 90, 45, 22.5, 135, 179 };
|
||||
uint64_t generation = 0;
|
||||
for (double level : levels)
|
||||
{
|
||||
++generation;
|
||||
auto g = std::make_shared<ReferenceGraph>(*fixture.graph);
|
||||
g->direction_generation = generation;
|
||||
const auto field = direction(fixture, level, generation);
|
||||
ASSERT_TRUE(field.field);
|
||||
for (const auto& s : scenes)
|
||||
{
|
||||
SCOPED_TRACE(s.id + " level=" + std::to_string(level));
|
||||
SessionRequest r;
|
||||
r.initialized = true;
|
||||
r.frame = "map";
|
||||
r.graph = { ReferenceGraphState::kReady, g, generation };
|
||||
r.direction = field;
|
||||
r.live.width = fixture.geometry.width;
|
||||
r.live.height = fixture.geometry.height;
|
||||
r.live.resolution = fixture.geometry.resolution;
|
||||
r.live.origin_x = fixture.geometry.origin_x;
|
||||
r.live.origin_y = fixture.geometry.origin_y;
|
||||
r.live.cost = master.data();
|
||||
r.footprint = rectangleFootprint(0.3, 0.3);
|
||||
r.inscribed_radius_m = 0.3;
|
||||
r.start = pose(s.start.x, s.start.y, s.start.yaw);
|
||||
r.goal = pose(s.goal.x, s.goal.y, s.goal.yaw);
|
||||
r.start_has_yaw = s.start.has_yaw;
|
||||
r.goal_has_yaw = s.goal.has_yaw;
|
||||
const auto found = refs.find({ s.id, level });
|
||||
ASSERT_NE(found, refs.end());
|
||||
const PlanResult result = session.plan(r);
|
||||
const Json& ref = found->second;
|
||||
ASSERT_EQ(result.ok, ref.at("ok").get<int>() != 0) << result.info.reason;
|
||||
EXPECT_EQ(result.info.reason, ref.at("reason").get<std::string>());
|
||||
if (!result.ok)
|
||||
continue;
|
||||
EXPECT_TRUE(result.check.valid);
|
||||
const auto& path = ref.at("path");
|
||||
ASSERT_EQ(result.path.size(), path.size());
|
||||
for (std::size_t i = 0; i < result.path.size(); ++i)
|
||||
{
|
||||
EXPECT_NEAR(result.path[i].x, path[i][0].get<double>(), 1e-8);
|
||||
EXPECT_NEAR(result.path[i].y, path[i][1].get<double>(), 1e-8);
|
||||
EXPECT_NEAR(result.path[i].yaw, path[i][2].get<double>(), 1e-8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AdapterParity, RealCalls)
|
||||
{
|
||||
runParity(false);
|
||||
}
|
||||
|
||||
TEST(AdapterParity, Inflation)
|
||||
{
|
||||
runParity(true);
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user