feat(lane_route): smooth lattice paths (R2) and expose the lattice tier in the plugin (R3)
- lane_route_core: port of the S3 smoother for lattice paths (direct, greedy and bounded graph improvement over witness anchors, then clothoid corners when budget remains), shape metrics and smoother diagnostics in PlanInfo and lane_route_eval. - lane_route_planner: loads the lattice keys from YAML, logs a config summary at start-up and one debug/fallback line per lattice request. regress7: coverage unchanged from R1, every lattice path smoothed, 0 bad in the independent recheck. Local snapshot for history only; not pushed.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <lane_route_planner/lane_route_session.h>
|
||||
#include <lane_route_planner/lane_route_planner.h>
|
||||
|
||||
#include <robot/node_handle.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
@@ -226,6 +228,130 @@ TEST(AdapterConfig, RejectsInvalidParameters)
|
||||
EXPECT_FALSE(c.validate().empty());
|
||||
}
|
||||
|
||||
TEST(AdapterConfig, LatticeYamlReachesPlannerConfig)
|
||||
{
|
||||
robot::NodeHandle root;
|
||||
root.setParam("LaneRouteLatticeConfigTest", YAML::Load(R"(
|
||||
lattice_enabled: true
|
||||
lattice_heading_bins: 64
|
||||
lattice_closed_resolution_m: 0.2
|
||||
lattice_heuristic_weight: 2.0
|
||||
lattice_bucket_width_m: 0.3
|
||||
lattice_field_clearance_weight_m: 0.4
|
||||
lattice_wall_weight_m: 0.5
|
||||
lattice_switch_cost_m: 0.6
|
||||
lattice_steer_cost_m: 0.02
|
||||
lattice_primitive_multiple_1: 1
|
||||
lattice_primitive_multiple_2: 2
|
||||
lattice_primitive_multiple_3: 4
|
||||
lattice_analytic_radius_m: 1.2
|
||||
lattice_analytic_interval: 123
|
||||
lattice_analytic_near_goal_m: 1.5
|
||||
lattice_analytic_goal_headings: 8
|
||||
lattice_field_time_fraction: 0.3
|
||||
lattice_field_cell_factor: 2
|
||||
lattice_field_max_cells: 123456
|
||||
fallback_time_limit_s: 2.0
|
||||
lattice_end_relax_radius_m: 0.8
|
||||
lattice_max_memory_mb: 256
|
||||
debug: {fallback: false}
|
||||
)"));
|
||||
robot::NodeHandle nh(root, "LaneRouteLatticeConfigTest");
|
||||
const SessionConfig config = loadSessionConfig(nh);
|
||||
const auto& p = config.planner;
|
||||
EXPECT_TRUE(config.validate().empty());
|
||||
EXPECT_TRUE(p.lattice_enabled);
|
||||
EXPECT_EQ(p.lattice_heading_bins, 64);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_closed_resolution_m, 0.2);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_heuristic_weight, 2.0);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_bucket_width_m, 0.3);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_field_clearance_weight_m, 0.4);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_wall_weight_m, 0.5);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_switch_cost_m, 0.6);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_steer_cost_m, 0.02);
|
||||
EXPECT_EQ(p.lattice_primitive_multiple_1, 1);
|
||||
EXPECT_EQ(p.lattice_primitive_multiple_2, 2);
|
||||
EXPECT_EQ(p.lattice_primitive_multiple_3, 4);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_analytic_radius_m, 1.2);
|
||||
EXPECT_EQ(p.lattice_analytic_interval, 123);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_analytic_near_goal_m, 1.5);
|
||||
EXPECT_EQ(p.lattice_analytic_goal_headings, 8);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_field_time_fraction, 0.3);
|
||||
EXPECT_EQ(p.lattice_field_cell_factor, 2);
|
||||
EXPECT_EQ(p.lattice_field_max_cells, 123456);
|
||||
EXPECT_DOUBLE_EQ(p.fallback_time_limit_s, 2.0);
|
||||
EXPECT_DOUBLE_EQ(p.lattice_end_relax_radius_m, 0.8);
|
||||
EXPECT_EQ(p.lattice_max_memory_mb, 256);
|
||||
EXPECT_FALSE(config.debug_fallback);
|
||||
|
||||
root.setParam("LaneRouteLatticeDefaultsTest", YAML::Load("{other: 1}"));
|
||||
const auto defaults = loadSessionConfig(robot::NodeHandle(root, "LaneRouteLatticeDefaultsTest"));
|
||||
const PlannerConfig expected;
|
||||
EXPECT_FALSE(defaults.planner.lattice_enabled);
|
||||
EXPECT_EQ(defaults.planner.lattice_heading_bins, expected.lattice_heading_bins);
|
||||
EXPECT_DOUBLE_EQ(defaults.planner.fallback_time_limit_s, expected.fallback_time_limit_s);
|
||||
EXPECT_EQ(defaults.planner.lattice_field_max_cells, expected.lattice_field_max_cells);
|
||||
EXPECT_EQ(defaults.planner.lattice_max_memory_mb, expected.lattice_max_memory_mb);
|
||||
EXPECT_TRUE(defaults.debug_fallback);
|
||||
|
||||
// A non-default first primitive is invalid, but must still reach core validation.
|
||||
root.setParam("LaneRouteBadPrimitiveTest", YAML::Load("{lattice_enabled: true, lattice_primitive_multiple_1: 2}"));
|
||||
const auto invalid = loadSessionConfig(robot::NodeHandle(root, "LaneRouteBadPrimitiveTest"));
|
||||
EXPECT_EQ(invalid.planner.lattice_primitive_multiple_1, 2);
|
||||
EXPECT_NE(invalid.validate().find("lattice primitive multiples"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(AdapterConfig, InvalidLatticeRejectsPluginInitialization)
|
||||
{
|
||||
robot::NodeHandle root;
|
||||
root.setParam("LaneRouteInvalidLatticeTest", YAML::Load("{lattice_enabled: true, lattice_heading_bins: 7}"));
|
||||
LaneRoutePlanner planner;
|
||||
testing::internal::CaptureStdout();
|
||||
const bool initialized = planner.initialize("LaneRouteInvalidLatticeTest", nullptr);
|
||||
const std::string log = testing::internal::GetCapturedStdout();
|
||||
EXPECT_FALSE(initialized);
|
||||
EXPECT_NE(log.find("invalid configuration: lattice_heading_bins must be even and in [8, 1024]"), std::string::npos);
|
||||
|
||||
root.setParam("LaneRouteDisabledInvalidLatticeTest", YAML::Load("{lattice_enabled: false, lattice_heading_bins: 7}"));
|
||||
LaneRoutePlanner disabled;
|
||||
testing::internal::CaptureStdout();
|
||||
const bool disabled_initialized = disabled.initialize("LaneRouteDisabledInvalidLatticeTest", nullptr);
|
||||
const std::string disabled_log = testing::internal::GetCapturedStdout();
|
||||
EXPECT_FALSE(disabled_initialized);
|
||||
EXPECT_NE(disabled_log.find("invalid configuration: lattice_heading_bins must be even and in [8, 1024]"),
|
||||
std::string::npos);
|
||||
}
|
||||
|
||||
TEST(AdapterLog, FallbackSwitchDoesNotSuppressFailure)
|
||||
{
|
||||
robot::NodeHandle root;
|
||||
root.setParam("LaneRouteFallbackLogTest", YAML::Load("{debug: {fallback: false}}"));
|
||||
const auto config = loadSessionConfig(robot::NodeHandle(root, "LaneRouteFallbackLogTest"));
|
||||
PlanResult result;
|
||||
result.info.reason = "lattice_exhausted";
|
||||
result.info.graph_reason = "no_route";
|
||||
result.info.lattice_reason = "lattice_exhausted";
|
||||
result.info.lattice_ms = 1.0;
|
||||
result.info.lattice_rung_reasons.push_back(result.info.lattice_reason);
|
||||
testing::internal::CaptureStdout();
|
||||
logPlanResult(result, config.debug_fallback);
|
||||
const std::string quiet = testing::internal::GetCapturedStdout();
|
||||
EXPECT_EQ(quiet.find("[debug] fallback tier="), std::string::npos);
|
||||
EXPECT_NE(quiet.find("plan failed: lattice_exhausted"), std::string::npos);
|
||||
testing::internal::CaptureStdout();
|
||||
logPlanResult(result, true);
|
||||
const std::string verbose = testing::internal::GetCapturedStdout();
|
||||
EXPECT_NE(verbose.find("[debug] fallback tier=none"), std::string::npos);
|
||||
EXPECT_NE(verbose.find("plan failed: lattice_exhausted"), std::string::npos);
|
||||
|
||||
result.info.lattice_ms = 0.0;
|
||||
testing::internal::CaptureStdout();
|
||||
logPlanResult(result, true);
|
||||
const std::string no_lattice = testing::internal::GetCapturedStdout();
|
||||
EXPECT_EQ(no_lattice.find("[debug] fallback tier="), std::string::npos);
|
||||
EXPECT_NE(no_lattice.find("plan failed: lattice_exhausted"), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(AdapterConfig, FootprintBoundsAndCollisionDistances)
|
||||
{
|
||||
double x, y;
|
||||
|
||||
Reference in New Issue
Block a user