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:
@@ -31,67 +31,128 @@ void setExternalGridOn(robot_nav_core::BaseGlobalPlanner* planner, const robot_c
|
||||
robot::log_error("[lane_route_planner] ExternalGrid: wrong planner instance");
|
||||
}
|
||||
|
||||
SessionConfig loadSessionConfig(const robot::NodeHandle& nh)
|
||||
{
|
||||
SessionConfig config;
|
||||
const auto load = [&nh](const char* key, auto& value, const auto& fallback)
|
||||
{
|
||||
if (nh.hasParam(key))
|
||||
{
|
||||
if (!nh.getParam(key, value, fallback))
|
||||
throw std::invalid_argument(std::string("invalid parameter: ") + key);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = fallback;
|
||||
}
|
||||
};
|
||||
SessionConfig defaults;
|
||||
auto& p = config.planner;
|
||||
const auto& d = defaults.planner;
|
||||
load("min_turn_radius_m", p.min_turn_radius_m, d.min_turn_radius_m);
|
||||
load("corner_radii_m", p.corner_radii_m, d.corner_radii_m);
|
||||
load("clearance_min_margin_m", config.clearance_min_margin_m, defaults.clearance_min_margin_m);
|
||||
load("clearance_preferred_margin_m", config.clearance_preferred_margin_m, defaults.clearance_preferred_margin_m);
|
||||
load("collision_check_margin_m", config.collision_check_margin_m, defaults.collision_check_margin_m);
|
||||
load("footprint_min_gap_m", p.footprint_min_gap_m, d.footprint_min_gap_m);
|
||||
load("footprint_gap_shortcut_raise_m", p.footprint_gap_shortcut_raise_m, d.footprint_gap_shortcut_raise_m);
|
||||
load("deviation_ladder_deg", p.deviation_ladder_deg, d.deviation_ladder_deg);
|
||||
load("route_too_long_ratio", p.route_too_long_ratio, d.route_too_long_ratio);
|
||||
load("route_too_long_margin_m", p.route_too_long_margin_m, d.route_too_long_margin_m);
|
||||
load("suspicious_ratio", p.suspicious_ratio, d.suspicious_ratio);
|
||||
load("suspicious_margin_m", p.suspicious_margin_m, d.suspicious_margin_m);
|
||||
load("max_route_attempts", p.max_route_attempts, d.max_route_attempts);
|
||||
load("time_limit_s", p.time_limit_s, d.time_limit_s);
|
||||
load("output_step_m", p.output_step_m, d.output_step_m);
|
||||
load("live_ridge_pad_m", p.live_ridge_pad_m, d.live_ridge_pad_m);
|
||||
int max_cells = static_cast<int>(d.live_ridge_max_cells);
|
||||
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_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);
|
||||
load("lattice_bucket_width_m", p.lattice_bucket_width_m, d.lattice_bucket_width_m);
|
||||
load("lattice_field_clearance_weight_m", p.lattice_field_clearance_weight_m, d.lattice_field_clearance_weight_m);
|
||||
load("lattice_wall_weight_m", p.lattice_wall_weight_m, d.lattice_wall_weight_m);
|
||||
load("lattice_switch_cost_m", p.lattice_switch_cost_m, d.lattice_switch_cost_m);
|
||||
load("lattice_steer_cost_m", p.lattice_steer_cost_m, d.lattice_steer_cost_m);
|
||||
load("lattice_primitive_multiple_1", p.lattice_primitive_multiple_1, d.lattice_primitive_multiple_1);
|
||||
load("lattice_primitive_multiple_2", p.lattice_primitive_multiple_2, d.lattice_primitive_multiple_2);
|
||||
load("lattice_primitive_multiple_3", p.lattice_primitive_multiple_3, d.lattice_primitive_multiple_3);
|
||||
load("lattice_analytic_radius_m", p.lattice_analytic_radius_m, d.lattice_analytic_radius_m);
|
||||
load("lattice_analytic_interval", p.lattice_analytic_interval, d.lattice_analytic_interval);
|
||||
load("lattice_analytic_near_goal_m", p.lattice_analytic_near_goal_m, d.lattice_analytic_near_goal_m);
|
||||
load("lattice_analytic_goal_headings", p.lattice_analytic_goal_headings, d.lattice_analytic_goal_headings);
|
||||
load("lattice_field_time_fraction", p.lattice_field_time_fraction, d.lattice_field_time_fraction);
|
||||
load("lattice_field_cell_factor", p.lattice_field_cell_factor, d.lattice_field_cell_factor);
|
||||
int field_max_cells = static_cast<int>(d.lattice_field_max_cells);
|
||||
load("lattice_field_max_cells", field_max_cells, field_max_cells);
|
||||
p.lattice_field_max_cells = field_max_cells;
|
||||
load("fallback_time_limit_s", p.fallback_time_limit_s, d.fallback_time_limit_s);
|
||||
load("lattice_end_relax_radius_m", p.lattice_end_relax_radius_m, d.lattice_end_relax_radius_m);
|
||||
int max_memory_mb = static_cast<int>(d.lattice_max_memory_mb);
|
||||
load("lattice_max_memory_mb", max_memory_mb, max_memory_mb);
|
||||
p.lattice_max_memory_mb = max_memory_mb;
|
||||
load("debug/fallback", config.debug_fallback, defaults.debug_fallback);
|
||||
load("debug_plan", config.debug_plan, defaults.debug_plan);
|
||||
load("debug_state", config.debug_state, defaults.debug_state);
|
||||
return config;
|
||||
}
|
||||
|
||||
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",
|
||||
result.info.tier_used.empty() ? "none" : result.info.tier_used.c_str(),
|
||||
result.info.graph_reason.c_str(), result.info.lattice_reason.c_str(),
|
||||
static_cast<unsigned long long>(result.info.lattice_states_expanded), result.info.lattice_field_ms,
|
||||
result.info.lattice_search_ms, result.info.lattice_verify_ms,
|
||||
static_cast<double>(result.info.lattice_peak_bytes) / (1024.0 * 1024.0));
|
||||
if (!result.ok || result.path.empty() || !result.check.valid)
|
||||
{
|
||||
const char* reason = result.ok ? "invalid_or_empty_verified_path" : result.info.reason.c_str();
|
||||
robot::log_warning("[lane_route_planner] plan failed: %s", reason);
|
||||
}
|
||||
}
|
||||
|
||||
bool LaneRoutePlanner::initialize(std::string name, robot_costmap_2d::Costmap2DROBOT* costmap)
|
||||
{
|
||||
if (initialized_)
|
||||
return true;
|
||||
if (!costmap || !costmap->getLayeredCostmap() || !costmap->getCostmap())
|
||||
{
|
||||
robot::log_error("[lane_route_planner] initialize: missing costmap");
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
robot::NodeHandle root;
|
||||
robot::NodeHandle nh(root, name);
|
||||
const auto load = [&nh](const char* key, auto& value, const auto& fallback)
|
||||
config_ = loadSessionConfig(nh);
|
||||
std::string error = config_.validate();
|
||||
// Core validates lattice limits only when enabled; reject invalid dormant settings too.
|
||||
if (error.empty() && !config_.planner.lattice_enabled)
|
||||
{
|
||||
if (nh.hasParam(key))
|
||||
{
|
||||
if (!nh.getParam(key, value, fallback))
|
||||
throw std::invalid_argument(std::string("invalid parameter: ") + key);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = fallback;
|
||||
}
|
||||
};
|
||||
SessionConfig defaults;
|
||||
auto& p = config_.planner;
|
||||
const auto& d = defaults.planner;
|
||||
load("min_turn_radius_m", p.min_turn_radius_m, d.min_turn_radius_m);
|
||||
load("corner_radii_m", p.corner_radii_m, d.corner_radii_m);
|
||||
load("clearance_min_margin_m", config_.clearance_min_margin_m, defaults.clearance_min_margin_m);
|
||||
load("clearance_preferred_margin_m", config_.clearance_preferred_margin_m, defaults.clearance_preferred_margin_m);
|
||||
load("collision_check_margin_m", config_.collision_check_margin_m, defaults.collision_check_margin_m);
|
||||
load("footprint_min_gap_m", p.footprint_min_gap_m, d.footprint_min_gap_m);
|
||||
load("footprint_gap_shortcut_raise_m", p.footprint_gap_shortcut_raise_m, d.footprint_gap_shortcut_raise_m);
|
||||
load("deviation_ladder_deg", p.deviation_ladder_deg, d.deviation_ladder_deg);
|
||||
load("route_too_long_ratio", p.route_too_long_ratio, d.route_too_long_ratio);
|
||||
load("route_too_long_margin_m", p.route_too_long_margin_m, d.route_too_long_margin_m);
|
||||
load("suspicious_ratio", p.suspicious_ratio, d.suspicious_ratio);
|
||||
load("suspicious_margin_m", p.suspicious_margin_m, d.suspicious_margin_m);
|
||||
load("max_route_attempts", p.max_route_attempts, d.max_route_attempts);
|
||||
load("time_limit_s", p.time_limit_s, d.time_limit_s);
|
||||
load("output_step_m", p.output_step_m, d.output_step_m);
|
||||
load("live_ridge_pad_m", p.live_ridge_pad_m, d.live_ridge_pad_m);
|
||||
int max_cells = static_cast<int>(d.live_ridge_max_cells);
|
||||
load("live_ridge_max_cells", max_cells, max_cells);
|
||||
p.live_ridge_max_cells = max_cells;
|
||||
load("debug_plan", config_.debug_plan, defaults.debug_plan);
|
||||
load("debug_state", config_.debug_state, defaults.debug_state);
|
||||
const std::string error = config_.validate();
|
||||
auto lattice_config = config_.planner;
|
||||
lattice_config.lattice_enabled = true;
|
||||
error = lattice_config.validate();
|
||||
}
|
||||
if (!error.empty())
|
||||
{
|
||||
robot::log_error("[lane_route_planner] invalid configuration: %s", error.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!costmap || !costmap->getLayeredCostmap() || !costmap->getCostmap())
|
||||
{
|
||||
robot::log_error("[lane_route_planner] initialize: missing costmap");
|
||||
return false;
|
||||
}
|
||||
const auto& p = config_.planner;
|
||||
costmap_ = costmap;
|
||||
session_.setConfig(config_);
|
||||
initialized_ = true;
|
||||
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,
|
||||
static_cast<long long>(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");
|
||||
return true;
|
||||
@@ -222,12 +283,9 @@ bool LaneRoutePlanner::makePlan(const robot_geometry_msgs::PoseStamped& start, c
|
||||
result.info.query_ms, result.info.compile_ms, result.info.search_ms, result.info.build_ms, result.info.verify_ms,
|
||||
result.info.live_ridge_ms, result.info.min_gap_m, result.info.gap_shortcut_raise_m, result.info.gap_exemption_used,
|
||||
result.info.swing_windows, result.info.swing_line_checks, result.info.swing_builds, result.info.swing_selected);
|
||||
logPlanResult(result, config_.debug_fallback);
|
||||
if (!result.ok || result.path.empty() || !result.check.valid)
|
||||
{
|
||||
const char* reason = result.ok ? "invalid_or_empty_verified_path" : result.info.reason.c_str();
|
||||
robot::log_warning("[lane_route_planner] plan failed: %s", reason);
|
||||
return false;
|
||||
}
|
||||
const auto final_graph = layered->getReferenceGraphSnapshot();
|
||||
const auto final_direction = layered->getDirectionFieldSnapshot();
|
||||
if (preempt_.load(std::memory_order_relaxed) || final_graph.state != request.graph.state ||
|
||||
|
||||
Reference in New Issue
Block a user