diff --git a/README.md b/README.md index 89b2a17..a007bbf 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,11 @@ Keys (defaults from `PlannerConfig`): - `lattice_field_time_fraction: 0.4`, `lattice_field_cell_factor: 0`, `lattice_field_max_cells: 1000000`, `fallback_time_limit_s: 3.0`, `lattice_end_relax_radius_m: 1.0`, `lattice_max_memory_mb: 512` (MiB). +- `lattice_preferred_gap_m: 0.15`, `lattice_preferred_time_fraction: 0.25`: each rung first finds a + minimum-gap path, then checks it for the preferred gap away from the ends. If needed, a new search + uses at most the configured share of the rung budget. An unsuccessful upgrade retains the verified minimum path. + A preferred gap at or below `footprint_min_gap_m` disables the upgrade. +- `lattice_smooth_enabled: true`, `lattice_smooth_max_checks: 450000`. - `debug/fallback: true` enables one diagnostic line per request when lattice ran; failure logs remain enabled. See the runtime YAML for units, tuning effects and valid ranges. diff --git a/src/lane_route_planner.cpp b/src/lane_route_planner.cpp index 1337bd6..beb0f0c 100644 --- a/src/lane_route_planner.cpp +++ b/src/lane_route_planner.cpp @@ -69,6 +69,12 @@ SessionConfig loadSessionConfig(const robot::NodeHandle& nh) load("live_ridge_max_cells", max_cells, max_cells); p.live_ridge_max_cells = max_cells; load("lattice_enabled", p.lattice_enabled, d.lattice_enabled); + load("lattice_preferred_gap_m", p.lattice_preferred_gap_m, d.lattice_preferred_gap_m); + load("lattice_preferred_time_fraction", p.lattice_preferred_time_fraction, d.lattice_preferred_time_fraction); + load("lattice_smooth_enabled", p.lattice_smooth_enabled, d.lattice_smooth_enabled); + int smooth_max_checks = static_cast(d.lattice_smooth_max_checks); + load("lattice_smooth_max_checks", smooth_max_checks, smooth_max_checks); + p.lattice_smooth_max_checks = smooth_max_checks; load("lattice_heading_bins", p.lattice_heading_bins, d.lattice_heading_bins); load("lattice_closed_resolution_m", p.lattice_closed_resolution_m, d.lattice_closed_resolution_m); load("lattice_heuristic_weight", p.lattice_heuristic_weight, d.lattice_heuristic_weight); @@ -103,11 +109,13 @@ SessionConfig loadSessionConfig(const robot::NodeHandle& nh) void logPlanResult(const lane_route_core::PlanResult& result, bool debug_fallback) { if (debug_fallback && result.info.lattice_ms > 0.0) - robot::log_info("[lane_route_planner] [debug] fallback tier=%s graph_reason=%s lattice_reason=%s expanded=%llu field=%.1fms search=%.1fms verify=%.1fms peak=%.1fMiB", + robot::log_info("[lane_route_planner] [debug] fallback tier=%s graph_reason=%s lattice_reason=%s gap_pass=%s min_gap_m=%.3f gap_exact=%d expanded=%llu field=%.1fms search=%.1fms verify=%.1fms upgrade=%.1fms peak=%.1fMiB", result.info.tier_used.empty() ? "none" : result.info.tier_used.c_str(), result.info.graph_reason.c_str(), result.info.lattice_reason.c_str(), + result.info.lattice_gap_pass.empty() ? "none" : result.info.lattice_gap_pass.c_str(), result.info.min_gap_m, + result.info.lattice_gap_exact ? 1 : 0, static_cast(result.info.lattice_states_expanded), result.info.lattice_field_ms, - result.info.lattice_search_ms, result.info.lattice_verify_ms, + result.info.lattice_search_ms, result.info.lattice_verify_ms, result.info.lattice_upgrade_ms, static_cast(result.info.lattice_peak_bytes) / (1024.0 * 1024.0)); if (!result.ok || result.path.empty() || !result.check.valid) { @@ -126,7 +134,8 @@ bool LaneRoutePlanner::initialize(std::string name, robot_costmap_2d::Costmap2DR robot::NodeHandle nh(root, name); config_ = loadSessionConfig(nh); std::string error = config_.validate(); - // Core validates lattice limits only when enabled; reject invalid dormant settings too. + // Core validates lattice limits only when enabled; reject invalid dormant settings too, so turning the lattice on later + // cannot reveal a broken value on the robot. if (error.empty() && !config_.planner.lattice_enabled) { auto lattice_config = config_.planner; @@ -150,8 +159,9 @@ bool LaneRoutePlanner::initialize(std::string name, robot_costmap_2d::Costmap2DR robot::log_info("[lane_route_planner] %s: time_limit=%.2fs min_radius=%.3fm clearance_margin=%.3fm gap=%.3fm debug_plan=%d debug_state=%d", name.c_str(), p.time_limit_s, p.min_turn_radius_m, config_.clearance_min_margin_m, p.footprint_min_gap_m, config_.debug_plan, config_.debug_state); - robot::log_info("[lane_route_planner] fallback: lattice_enabled=%d fallback_time_limit_s=%.2f lattice_heuristic_weight=%.2f lattice_heading_bins=%d lattice_max_memory_mb=%lld debug/fallback=%d", - p.lattice_enabled, p.fallback_time_limit_s, p.lattice_heuristic_weight, p.lattice_heading_bins, + robot::log_info("[lane_route_planner] fallback: lattice_enabled=%d fallback_time_limit_s=%.2f lattice_preferred_gap_m=%.3f lattice_preferred_time_fraction=%.2f lattice_smooth_enabled=%d lattice_smooth_max_checks=%lld lattice_heuristic_weight=%.2f lattice_heading_bins=%d lattice_max_memory_mb=%lld debug/fallback=%d", + p.lattice_enabled, p.fallback_time_limit_s, p.lattice_preferred_gap_m, p.lattice_preferred_time_fraction, + p.lattice_smooth_enabled, static_cast(p.lattice_smooth_max_checks), p.lattice_heuristic_weight, p.lattice_heading_bins, static_cast(p.lattice_max_memory_mb), config_.debug_fallback); if (costmap_->getLayeredCostmap()->getReferenceGraphSnapshot().state == robot_costmap_2d::ReferenceGraphState::kDisabled) robot::log_error("[lane_route_planner] reference graph is disabled; plans will fail until enabled"); diff --git a/test/lane_route_planner_test.cpp b/test/lane_route_planner_test.cpp index 2000942..616b7a6 100644 --- a/test/lane_route_planner_test.cpp +++ b/test/lane_route_planner_test.cpp @@ -233,6 +233,10 @@ TEST(AdapterConfig, LatticeYamlReachesPlannerConfig) robot::NodeHandle root; root.setParam("LaneRouteLatticeConfigTest", YAML::Load(R"( lattice_enabled: true + lattice_preferred_gap_m: 0.18 + lattice_preferred_time_fraction: 0.35 + lattice_smooth_enabled: false + lattice_smooth_max_checks: 123456 lattice_heading_bins: 64 lattice_closed_resolution_m: 0.2 lattice_heuristic_weight: 2.0 @@ -261,6 +265,10 @@ TEST(AdapterConfig, LatticeYamlReachesPlannerConfig) const auto& p = config.planner; EXPECT_TRUE(config.validate().empty()); EXPECT_TRUE(p.lattice_enabled); + EXPECT_DOUBLE_EQ(p.lattice_preferred_gap_m, 0.18); + EXPECT_DOUBLE_EQ(p.lattice_preferred_time_fraction, 0.35); + EXPECT_FALSE(p.lattice_smooth_enabled); + EXPECT_EQ(p.lattice_smooth_max_checks, 123456); 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); @@ -289,6 +297,10 @@ TEST(AdapterConfig, LatticeYamlReachesPlannerConfig) 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.lattice_preferred_gap_m, expected.lattice_preferred_gap_m); + EXPECT_DOUBLE_EQ(defaults.planner.lattice_preferred_time_fraction, expected.lattice_preferred_time_fraction); + EXPECT_EQ(defaults.planner.lattice_smooth_enabled, expected.lattice_smooth_enabled); + EXPECT_EQ(defaults.planner.lattice_smooth_max_checks, expected.lattice_smooth_max_checks); 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); @@ -320,6 +332,23 @@ TEST(AdapterConfig, InvalidLatticeRejectsPluginInitialization) EXPECT_FALSE(disabled_initialized); EXPECT_NE(disabled_log.find("invalid configuration: lattice_heading_bins must be even and in [8, 1024]"), std::string::npos); + + // A minimum gap above the preferred gap only switches the preferred pass off; it must not stop initialisation. + root.setParam("LaneRouteWideMinimumGapTest", YAML::Load("{lattice_enabled: true, footprint_min_gap_m: 0.20}")); + LaneRoutePlanner wide_gap; + testing::internal::CaptureStdout(); + EXPECT_FALSE(wide_gap.initialize("LaneRouteWideMinimumGapTest", nullptr)); + const std::string wide_gap_log = testing::internal::GetCapturedStdout(); + EXPECT_EQ(wide_gap_log.find("invalid configuration"), std::string::npos); + EXPECT_NE(wide_gap_log.find("missing costmap"), std::string::npos); + + // A broken smoother budget is rejected even while the lattice is off. + root.setParam("LaneRouteDisabledSmoothTest", YAML::Load("{lattice_enabled: false, lattice_smooth_max_checks: -1}")); + LaneRoutePlanner disabled_smooth; + testing::internal::CaptureStdout(); + EXPECT_FALSE(disabled_smooth.initialize("LaneRouteDisabledSmoothTest", nullptr)); + const std::string disabled_smooth_log = testing::internal::GetCapturedStdout(); + EXPECT_NE(disabled_smooth_log.find("invalid configuration"), std::string::npos); } TEST(AdapterLog, FallbackSwitchDoesNotSuppressFailure) @@ -332,6 +361,9 @@ TEST(AdapterLog, FallbackSwitchDoesNotSuppressFailure) result.info.graph_reason = "no_route"; result.info.lattice_reason = "lattice_exhausted"; result.info.lattice_ms = 1.0; + result.info.lattice_gap_pass = "minimum"; + result.info.min_gap_m = 0.08; + result.info.lattice_upgrade_ms = 12.3; result.info.lattice_rung_reasons.push_back(result.info.lattice_reason); testing::internal::CaptureStdout(); logPlanResult(result, config.debug_fallback); @@ -342,6 +374,8 @@ TEST(AdapterLog, FallbackSwitchDoesNotSuppressFailure) 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("gap_pass=minimum min_gap_m=0.080"), std::string::npos); + EXPECT_NE(verbose.find("upgrade=12.3ms"), std::string::npos); EXPECT_NE(verbose.find("plan failed: lattice_exhausted"), std::string::npos); result.info.lattice_ms = 0.0;