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

@@ -174,6 +174,44 @@ TEST(LegPoseFit, TwoLegsAreEnoughWhenTheModelIsKnown)
EXPECT_LT(yawError(fit.pose.yaw, axis), 0.2 * kDeg);
}
TEST(LegPoseFit, ModelSigmaChangesTheScoreButNotThePose)
{
// Xe thật lệch so với profile 3 cm cạnh vào, 2.5 cm cạnh dọc: sai số gia công của xe cùng loại.
LegProfile real = tciTrolley();
real.cart_opening = 0.487;
real.cart_depth = 0.745;
const LegProfile model = tciTrolley();
const double cx = 1.3, cy = 0.0, axis = M_PI + 5.0 * kDeg;
const std::vector<FitPoint> pts = pointsOf(real, cx, cy, axis, 0.01);
Pose2D init;
init.x = cx + 0.02;
init.y = cy;
init.yaw = axis;
const FitNoise strict = s300Noise(); // model_sigma = 0: như trước khi có khoá này
FitNoise lenient = strict;
lenient.model_sigma = 0.02; // = cart_dim_tolerance / 2 của profile mặc định
const PoseFitResult a = fitCartPose(LegModel::fromProfile(model), pts, init, strict);
const PoseFitResult b = fitCartPose(LegModel::fromProfile(model), pts, init, lenient);
ASSERT_TRUE(a.valid);
ASSERT_TRUE(b.valid);
// Trọng số của phép khớp không dùng model_sigma, nên kết quả khớp phải y hệt từng bit.
EXPECT_EQ(a.pose.x, b.pose.x);
EXPECT_EQ(a.pose.y, b.pose.y);
EXPECT_EQ(a.pose.yaw, b.pose.yaw);
EXPECT_EQ(a.rms, b.rms);
EXPECT_EQ(a.iterations, b.iterations);
// Điểm số thì khác: mẫu số σ² + model_sigma² làm phần dư do lệch mô hình đỡ nặng hơn rõ rệt.
EXPECT_GT(a.normalized_rms, 1.0);
EXPECT_LT(b.normalized_rms, 0.6 * a.normalized_rms);
EXPECT_EQ(FitNoise().model_sigma, 0.0);
}
TEST(LegPoseFit, IsDeterministic)
{
const LegProfile p = tciTrolley();