fix(leg_pattern): let cart_dim_tolerance widen the confidence score

The fit term divided the residual by the lidar noise only, so a trolley that
is a few cm off the profile (machining tolerance between carts of the same
type) scored a "poor fit" even though its pose was accurate: 3 legs seen and
a 3 cm error gave confidence 0.38 < 0.5 and the action timed out on the KIT
robot.

Add FitNoise::model_sigma and divide by sqrt(sigma^2 + model_sigma^2) when
scoring. The matcher passes cart_dim_tolerance / 2. Only the score changes:
the fit weights, the pose and the rms are bit-identical. A cart far outside
the tolerance is still rejected by the pair gates.

Tests: model_sigma changes the score but not the pose; a cart 3 cm narrower
and 2.5 cm longer than the profile is accepted with 4 and with 3 legs; a cart
15 cm wider is rejected. v/arc/circle tests unchanged.
This commit is contained in:
2026-10-28 15:48:49 +07:00
parent c568e90c53
commit cb401e6316
7 changed files with 108 additions and 3 deletions

View File

@@ -706,6 +706,10 @@ bool LegPatternMatcher::evaluate(Hypothesis& h, const ScanLimits& limits,
FitNoise noise;
noise.range_sigma = limits.range_sigma;
noise.angle_increment = dtheta;
// Xe cùng loại vẫn lệch vài cm do gia công: một cạnh lệch tối đa `cart_dim_tolerance` đẩy mỗi
// chân lệch tối đa tolerance/2 khỏi góc của mô hình. Coi mức đó là 1σ của mô hình, để điểm tin
// không trừ điểm xe nằm trong dung sai mà vẫn trừ điểm xe lệch xa hơn.
noise.model_sigma = profile_.cart_dim_tolerance / 2.0;
PoseFitResult fit;
for (int round = 0; round < kMaxFitRounds; ++round)
{

View File

@@ -373,13 +373,16 @@ PoseFitResult fitCartPose(const LegModel& model, const std::vector<FitPoint>& po
}
}
// Điểm số chia cho σ_tổng² = σ_điểm² + model_sigma²: xe lệch trong dung sai gia công không phải là
// "khớp tệ". Trọng số của chính phép khớp ở trên KHÔNG dùng model_sigma, nên pose không đổi.
const double model_var = noise.model_sigma > 0.0 ? noise.model_sigma * noise.model_sigma : 0.0;
double sum_r2 = 0.0;
double sum_e2 = 0.0;
for (const FitPoint& p : points)
{
const PointTerm t = evaluate(model, p, pose, noise);
sum_r2 += t.r * t.r;
sum_e2 += (t.r / t.sigma) * (t.r / t.sigma);
sum_e2 += (t.r * t.r) / (t.sigma * t.sigma + model_var);
}
const double n = static_cast<double>(points.size());
result.rms = std::sqrt(sum_r2 / n);