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:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user