feat(lane_route_planner): trim endpoint spin fans, load zone_deviation_weight (R2.12)

- New output_endpoint_spins (default false): the published plan starts at the
  first driving pose and ends with one goal pose. The local planner turns in
  place by itself; the planner still verifies both spins are collision free.
- Load and clamp zone_deviation_weight; print both keys in the boot line.
- Tests for the trim helper (29 pass).
This commit is contained in:
2026-11-11 14:31:32 +07:00
parent 4bed23baa7
commit cca126551c
4 changed files with 75 additions and 4 deletions

View File

@@ -25,6 +25,10 @@ struct SessionConfig
double clearance_min_margin_m = 0.035; ///< [m] Added to inscribed radius for hard clearance.
double clearance_preferred_margin_m = 0.30; ///< [m] Added to inscribed radius for preferred clearance.
double collision_check_margin_m = 0.056; ///< [m] Added to the bounding rectangle's circumscribed radius.
/// Publish the in-place rotation poses that the core plans at the start and the goal. Off: the plan starts at the
/// first driving pose and ends with one goal pose, and the controller turns in place itself. The core still checks
/// that both rotations are collision-free either way.
bool output_endpoint_spins = false;
bool debug_fallback = true; ///< Enable per-request fallback diagnostics.
bool debug_plan = true; ///< Enable plan diagnostics.
bool debug_state = true; ///< Enable state-change diagnostics.
@@ -40,6 +44,12 @@ struct SessionConfig
/** @brief Read the plugin namespace with PlannerConfig defaults; malformed types throw. */
SessionConfig loadSessionConfig(const robot::NodeHandle& nh);
/** @brief Drop the in-place rotation poses at both ends of a planned path.
* Keeps the last pose of the leading run (start position, first driving heading) and the first pose of the trailing
* run (goal position, arrival heading); the caller then writes the requested goal pose into that last pose.
* A path that only rotates is returned unchanged, because it has no driving pose to keep. */
lane_route_core::Path trimEndpointSpins(const lane_route_core::Path& path);
/** @brief Log fallback diagnostics when enabled and always report a failed result. */
void logPlanResult(const lane_route_core::PlanResult& result, bool debug_fallback);

View File

@@ -58,6 +58,12 @@ SessionConfig loadSessionConfig(const robot::NodeHandle& nh)
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("zone_transition_m", p.zone_transition_m, d.zone_transition_m);
load("zone_deviation_weight", p.zone_deviation_weight, d.zone_deviation_weight);
if (!std::isfinite(p.zone_deviation_weight) || p.zone_deviation_weight < 0.0)
{
robot::log_warning("[lane_route_planner] zone_deviation_weight must be finite and >= 0; clamped to 0");
p.zone_deviation_weight = 0.0;
}
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);
@@ -111,6 +117,7 @@ SessionConfig loadSessionConfig(const robot::NodeHandle& nh)
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("output_endpoint_spins", config.output_endpoint_spins, defaults.output_endpoint_spins);
load("debug/fallback", config.debug_fallback, defaults.debug_fallback);
load("debug/dump_dir", config.debug_dump_dir, defaults.debug_dump_dir);
load("debug/dump_max_files", config.debug_dump_max_files, defaults.debug_dump_max_files);
@@ -170,9 +177,10 @@ bool LaneRoutePlanner::initialize(std::string name, robot_costmap_2d::Costmap2DR
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 zone_transition_m=%.3f debug_plan=%d debug_state=%d",
robot::log_info("[lane_route_planner] %s: time_limit=%.2fs min_radius=%.3fm clearance_margin=%.3fm gap=%.3fm zone_transition_m=%.3f zone_deviation_weight=%.3f output_endpoint_spins=%d 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, p.zone_transition_m, config_.debug_plan, config_.debug_state);
p.footprint_min_gap_m, p.zone_transition_m, p.zone_deviation_weight, config_.output_endpoint_spins,
config_.debug_plan, config_.debug_state);
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 lattice_field_standability_relax_m=%.3f lattice_field_zone_margin_deg=%.1f lattice_alt_field_enabled=%d lattice_alt_field_relax_m=%.3f lattice_alt_field_switch_fraction=%.2f 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<long long>(p.lattice_smooth_max_checks), p.lattice_heuristic_weight, p.lattice_heading_bins,
@@ -346,8 +354,11 @@ bool LaneRoutePlanner::makePlan(const robot_geometry_msgs::PoseStamped& start, c
}
}
const auto stamp = robot::Time::now();
plan.reserve(result.path.size());
for (const auto& point : result.path)
// The controller turns in place at the start and to the goal yaw by itself; it takes the goal yaw from the last
// plan pose, which is set to the requested goal below.
const lane_route_core::Path published = config_.output_endpoint_spins ? result.path : trimEndpointSpins(result.path);
plan.reserve(published.size());
for (const auto& point : published)
{
robot_geometry_msgs::PoseStamped pose;
pose.header.frame_id = request.frame;

View File

@@ -67,6 +67,27 @@ std::string SessionConfig::validate() const
return planner.validate();
}
lane_route_core::Path trimEndpointSpins(const lane_route_core::Path& path)
{
// The core writes an endpoint rotation as poses at one exact position, so a tight tolerance is enough.
constexpr double kSamePositionM = 1e-6;
const auto same = [&path](std::size_t a, std::size_t b) {
return std::hypot(path[a].x - path[b].x, path[a].y - path[b].y) <= kSamePositionM;
};
if (path.size() < 3)
return path;
std::size_t first = 0;
while (first + 1 < path.size() && same(first, first + 1))
++first;
std::size_t last = path.size() - 1;
while (last > first && same(last - 1, last))
--last;
if (first >= last)
return path;
return lane_route_core::Path(path.begin() + static_cast<std::ptrdiff_t>(first),
path.begin() + static_cast<std::ptrdiff_t>(last) + 1);
}
namespace
{
// Run-length text in the format lane_route_eval reads: "<key> <run count>" then "<value> <count>" pairs.

View File

@@ -305,6 +305,7 @@ TEST(AdapterConfig, LatticeYamlReachesPlannerConfig)
const PlannerConfig expected;
EXPECT_FALSE(defaults.planner.lattice_enabled);
EXPECT_DOUBLE_EQ(defaults.planner.zone_transition_m, 1.0);
EXPECT_FALSE(defaults.output_endpoint_spins);
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);
@@ -833,4 +834,32 @@ TEST(AdapterDump, FailureDumpIsReadableRunLengthText)
EXPECT_TRUE(writeFailureDump(dir, "bad", live, std::vector<uint8_t>(5, 0), directions, route, config, result).empty());
}
TEST(EndpointSpins, TrimKeepsFirstDrivingPoseAndArrivalPose)
{
// Start spin 0 -> 0.2 rad, drive 1 m along x, goal spin 0.2 -> 1.0 rad.
const Path path{ {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.1, 0.0}, {0.0, 0.0, 0.2, 0.0},
{0.5, 0.0, 0.2, 0.0}, {1.0, 0.0, 0.2, 0.0},
{1.0, 0.0, 0.6, 0.0}, {1.0, 0.0, 1.0, 0.0} };
const Path trimmed = trimEndpointSpins(path);
ASSERT_EQ(trimmed.size(), 3u);
EXPECT_DOUBLE_EQ(trimmed.front().x, 0.0);
EXPECT_DOUBLE_EQ(trimmed.front().yaw, 0.2);
EXPECT_DOUBLE_EQ(trimmed[1].x, 0.5);
EXPECT_DOUBLE_EQ(trimmed.back().x, 1.0);
EXPECT_DOUBLE_EQ(trimmed.back().yaw, 0.2);
for (std::size_t i = 1; i < trimmed.size(); ++i)
EXPECT_GT(std::hypot(trimmed[i].x - trimmed[i - 1].x, trimmed[i].y - trimmed[i - 1].y), 0.1);
}
TEST(EndpointSpins, PathsWithoutSpinsOrWithoutDrivingAreUnchanged)
{
const Path straight{ {0.0, 0.0, 0.0, 0.0}, {0.5, 0.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0} };
EXPECT_EQ(trimEndpointSpins(straight).size(), straight.size());
// A rotation-only plan has no driving pose to keep, so the controller still gets the full turn.
const Path rotate{ {2.0, 1.0, 0.0, 0.0}, {2.0, 1.0, 0.5, 0.0}, {2.0, 1.0, 1.0, 0.0} };
EXPECT_EQ(trimEndpointSpins(rotate).size(), rotate.size());
const Path two{ {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0} };
EXPECT_EQ(trimEndpointSpins(two).size(), two.size());
}
} // namespace