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

@@ -407,6 +407,42 @@ TEST(LegPatternMatcher, StaysWithinToleranceUnderS300Noise)
EXPECT_LT(max_yaw, 2.0 * kDeg);
}
TEST(LegPatternMatcher, AcceptsACartWithinTheDimensionTolerance)
{
// Cùng một loại xe nhưng chiếc này gia công lệch: hẹp hơn profile 3 cm, dài hơn 2.5 cm — trong
// cart_dim_tolerance (4 cm). Phải dò được, kể cả khi một chân nấp sau chân kia: chỉ 3 chân thì
// điểm số chân chỉ có 0.375, nên phần khớp không được trừ điểm vì lệch mô hình.
const LegProfile p = tciTrolley();
LegProfile real = p;
real.cart_opening = p.cart_opening - 0.03;
real.cart_depth = p.cart_depth + 0.025;
for (double cy : { 0.0, real.cart_opening / 2.0 }) // đủ 4 chân / một chân nấp sau chân kia
{
World w;
leg_scan_sim::addCart(w, real, kCx, cy, M_PI);
const LegDetection d = detect(p, w, 0.01, 3);
ASSERT_TRUE(d.valid) << "cy " << cy << ": " << d.reason;
EXPECT_GE(d.confidence, p.min_confidence) << "cy " << cy;
EXPECT_NEAR(d.center_x, kCx, 0.02) << "cy " << cy;
EXPECT_NEAR(d.center_y, cy, 0.015) << "cy " << cy;
EXPECT_LT(yawError(d.center_yaw, M_PI), 2.0 * kDeg) << "cy " << cy;
}
}
TEST(LegPatternMatcher, RejectsACartFarOutsideTheDimensionTolerance)
{
// Nới điểm tin theo dung sai không được biến thành nhận mọi vật 4 chân: xe rộng hơn profile 15 cm
// vẫn không có cặp chân nào đúng cạnh vào.
const LegProfile p = tciTrolley();
LegProfile real = p;
real.cart_opening = p.cart_opening + 0.15;
World w;
leg_scan_sim::addCart(w, real, kCx, 0.0, M_PI);
const LegDetection d = detect(p, w);
EXPECT_FALSE(d.valid) << "confidence " << d.confidence;
}
TEST(LegPatternMatcher, IsDeterministic)
{
const LegProfile p = tciTrolley();