feat(lane_route): radius ladder and failure dumps (R2.6)
Radius ladder: the first graph pass, the lattice and the smoother use only radii at or above regular_turn_radius_m (1.06 m), as before. When min_turn_radius_m is lower, the graph runs a second pass with all corner_radii_m if the first fails or returns a long detour, and keeps it only when at least 20% shorter. Optional lattice tight arcs exist behind lattice_tight_arcs (off: they cost many queries to timeouts). C++ defaults keep the old 1.06 m floor; regress7 output is identical. With a 0.4 m floor: graph-only coverage +5 (hook_150) and +8 (kit), none lost; with fallback, coverage unchanged and 27/29 queries move from lattice to graph; tight corners used 0.9 m. Failure dumps: with debug/dump_dir set, the plugin writes each failed query as lane_route_eval input (static cost, master cost, direction codes, poses, settings), at most debug/dump_max_files per session.
This commit is contained in:
@@ -4,8 +4,13 @@
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
|
||||
#include <lane_route_core/costmap_backend.h>
|
||||
@@ -55,11 +60,91 @@ std::string SessionConfig::validate() const
|
||||
<< " must be >= clearance_min_margin_m=" << clearance_min_margin_m;
|
||||
else if (!nonnegative(collision_check_margin_m))
|
||||
error << "collision_check_margin_m must be finite and >= 0, got " << collision_check_margin_m;
|
||||
else if (debug_dump_max_files < 0)
|
||||
error << "debug/dump_max_files must be >= 0, got " << debug_dump_max_files;
|
||||
if (!error.str().empty())
|
||||
return error.str();
|
||||
return planner.validate();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
// Run-length text in the format lane_route_eval reads: "<key> <run count>" then "<value> <count>" pairs.
|
||||
void writeRuns(std::ostream& out, const char* key, const uint8_t* data, std::size_t count)
|
||||
{
|
||||
std::vector<std::pair<int, std::size_t>> runs;
|
||||
for (std::size_t i = 0; i < count;)
|
||||
{
|
||||
std::size_t j = i;
|
||||
while (j < count && data[j] == data[i])
|
||||
++j;
|
||||
runs.emplace_back(data[i], j - i);
|
||||
i = j;
|
||||
}
|
||||
out << key << ' ' << runs.size() << '\n';
|
||||
for (const auto& run : runs)
|
||||
out << run.first << ' ' << run.second << ' ';
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
void writePose(std::ostream& out, const lane_route_core::Pose2& pose)
|
||||
{
|
||||
out << (pose.has_yaw ? 1 : 0) << ' ' << pose.x << ' ' << pose.y << ' ' << pose.yaw;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string writeFailureDump(const std::string& dir, const std::string& name, const lane_route_core::GridRef& live,
|
||||
const std::vector<uint8_t>& static_cost, const std::vector<uint8_t>& directions,
|
||||
const lane_route_core::RouteRequest& route, const lane_route_core::PlannerConfig& config,
|
||||
const lane_route_core::PlanResult& result)
|
||||
{
|
||||
const std::size_t cells = static_cast<std::size_t>(live.width) * static_cast<std::size_t>(live.height);
|
||||
if (!live.cost || static_cost.size() != cells || (!directions.empty() && directions.size() != cells))
|
||||
return {};
|
||||
std::error_code error;
|
||||
std::filesystem::create_directories(dir, error);
|
||||
if (error)
|
||||
return {};
|
||||
const std::string stem = (std::filesystem::path(dir) / name).string();
|
||||
{
|
||||
std::ofstream grid(stem + ".grid");
|
||||
grid << std::setprecision(10) << "reference_grid 1\nsize " << live.width << ' ' << live.height << "\nresolution "
|
||||
<< live.resolution << "\norigin " << live.origin_x << ' ' << live.origin_y << '\n';
|
||||
writeRuns(grid, "cost", static_cost.data(), cells);
|
||||
grid << "variants 1\n";
|
||||
if (directions.empty())
|
||||
{
|
||||
const std::vector<uint8_t> none(cells, 0);
|
||||
writeRuns(grid, "direction", none.data(), cells);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeRuns(grid, "direction", directions.data(), cells);
|
||||
}
|
||||
std::ofstream master(stem + ".live");
|
||||
writeRuns(master, "cost", live.cost, cells);
|
||||
std::ofstream scene(stem + ".scene");
|
||||
scene << std::setprecision(10) << name << ' ' << stem << ".grid 0 " << stem << ".live ";
|
||||
writePose(scene, route.start);
|
||||
scene << ' ';
|
||||
writePose(scene, route.goal);
|
||||
scene << " 0\n";
|
||||
std::ofstream meta(stem + ".txt");
|
||||
const auto& info = result.info;
|
||||
meta << std::setprecision(10) << "reason " << info.reason << "\ngraph_reason " << info.graph_reason << "\nlattice_reason "
|
||||
<< info.lattice_reason << "\nquery_ms " << info.query_ms << "\nlattice_states_expanded " << info.lattice_states_expanded
|
||||
<< "\nmax_deviation_deg " << config.max_deviation_deg << "\nhalf_x_m " << config.half_x_m << "\nhalf_y_m "
|
||||
<< config.half_y_m << "\nclearance_min_m " << config.clearance_min_m << "\nfootprint_min_gap_m "
|
||||
<< config.footprint_min_gap_m << "\nmin_turn_radius_m " << config.min_turn_radius_m << "\nlattice_enabled "
|
||||
<< config.lattice_enabled << "\nfallback_time_limit_s " << config.fallback_time_limit_s << "\ntime_limit_s "
|
||||
<< config.time_limit_s << "\n# Replay: lane_route_eval " << stem << ".scene " << stem
|
||||
<< ".jsonl <profile with these half sizes> " << config.max_deviation_deg << " none fallback\n";
|
||||
if (!grid || !master || !scene || !meta)
|
||||
return {};
|
||||
}
|
||||
return stem;
|
||||
}
|
||||
|
||||
bool footprintRectangle(const std::vector<robot_geometry_msgs::Point>& footprint, double* half_x, double* half_y,
|
||||
bool* centered_rectangle)
|
||||
{
|
||||
@@ -165,6 +250,7 @@ void LaneRouteSession::clearCache()
|
||||
lane_route_core::PlanResult LaneRouteSession::plan(const SessionRequest& request)
|
||||
{
|
||||
using namespace lane_route_core;
|
||||
last_dump_.clear();
|
||||
PlanResult failed;
|
||||
failed.info.reason = validateRequest(request);
|
||||
if (!failed.info.reason.empty())
|
||||
@@ -318,6 +404,20 @@ lane_route_core::PlanResult LaneRouteSession::plan(const SessionRequest& request
|
||||
result.info.reason = request.cancel && request.cancel->load(std::memory_order_relaxed) ? "cancelled" : "exact_goal_invalid";
|
||||
}
|
||||
}
|
||||
// A failed query is dumped only after the core ran on it, so the replay sees the same grid, zones and poses.
|
||||
if (!result.ok && result.info.reason != "cancelled" && !config_.debug_dump_dir.empty() &&
|
||||
dumps_attempted_ < config_.debug_dump_max_files)
|
||||
{
|
||||
++dumps_attempted_;
|
||||
const std::time_t now = std::time(nullptr);
|
||||
std::tm local{};
|
||||
localtime_r(&now, &local);
|
||||
std::ostringstream name;
|
||||
name << "lane_route_" << std::put_time(&local, "%Y%m%d_%H%M%S") << '_' << dumps_attempted_;
|
||||
const std::string stem = writeFailureDump(config_.debug_dump_dir, name.str(), live, reference.static_cost, directions_,
|
||||
route, config, result);
|
||||
last_dump_ = stem.empty() ? "!" + config_.debug_dump_dir : stem;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace lane_route_planner
|
||||
|
||||
Reference in New Issue
Block a user