Separate the measured calibration from the derived offset

offset_x/y/yaw carried two different things at once. Part of it is geometry
that can be worked out on paper - half the robot, the footprint padding, how
far the wings project toward the robot, the clearance. The rest is whatever
the real station turns out to need: a laser mounted slightly off, odometry
bias, a systematic lean in the detection.

Folded into one number, changing the footprint silently discards the field
correction that was tuned into it, and nobody can look at the value later and
say which half is which. The first time someone re-derives the geometry, the
calibration is gone and nothing says so.

calib_x/y/yaw are added on top, in the same frame, defaulting to zero. Dock,
measure how far base_link ended up from where it should have, subtract it
here. The geometry stays derivable and the correction stays visible.

They are bounded to 0.30 m and 0.20 rad. Field calibration is centimetres and
degrees; needing half a metre means offset_x is wrong, and taping over that
with a calibration term hides the cause until the next footprint change makes
it worse.
This commit is contained in:
duongtd
2026-08-26 15:07:24 +07:00
parent c54f8d4cd1
commit 000374791b
4 changed files with 104 additions and 5 deletions

View File

@@ -217,6 +217,50 @@ TEST(VPatternMatcher, TheOffsetMovesTheGoalOutTowardTheRobot)
EXPECT_NEAR(d.y, 0.00, 0.03);
}
TEST(VPatternMatcher, CalibrationShiftsTheGoalOnTopOfTheOffset)
{
DockProfile p = vProfile();
p.offset_x = 0.60; // [m] phần HÌNH HỌC, suy ra bằng công thức
p.calib_x = -0.03; // [m] phần ĐO ĐƯỢC: lần dock thật dừng xa 3 cm
p.calib_y = 0.02; // [m]
Rig rig(p);
ASSERT_TRUE(rig.ok_) << rig.error_;
const Detection d = rig.run(vPlate(1.20, M_PI / 4.0, 0.30));
ASSERT_TRUE(d.valid) << d.reason;
// Đỉnh ở x=1.20; hiệu chỉnh cộng thẳng vào offset, cùng hệ quy chiếu của hình.
// Hình quay 180 độ so với trục x của cảm biến nên +x của hình là -x của cảm biến.
EXPECT_NEAR(d.apex_x, 1.20, 0.02);
EXPECT_NEAR(d.x, 1.20 - (0.60 - 0.03), 0.03);
EXPECT_NEAR(d.y, -0.02, 0.03);
}
TEST(VPatternMatcher, RefusesACalibrationBigEnoughToBeHidingAGeometryError)
{
VPatternMatcher matcher;
std::string error;
DockProfile huge = vProfile();
huge.calib_x = 0.5; // [m]
// Hiệu chỉnh hiện trường là centimet. Nửa mét nghĩa là `offset_x` sai, và dán băng dính lên nó
// bằng calib là giấu mất nguyên nhân — lần đổi footprint sau sẽ không ai hiểu con số này từ đâu.
EXPECT_FALSE(matcher.configure(huge, error));
EXPECT_NE(error.find("calib_x"), std::string::npos) << error;
DockProfile spin = vProfile();
spin.calib_yaw = 0.6; // [rad] ~34 do
EXPECT_FALSE(matcher.configure(spin, error));
EXPECT_NE(error.find("calib_yaw"), std::string::npos) << error;
// Hiệu chỉnh thật thì phải nhận.
DockProfile ok = vProfile();
ok.calib_x = -0.03;
ok.calib_yaw = 0.02;
EXPECT_TRUE(matcher.configure(ok, error)) << error;
}
TEST(VPatternMatcher, ATiltedPlateIsStillFoundAndItsYawFollows)
{
Rig rig;