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

@@ -13,6 +13,12 @@ namespace dock_pattern_detector
namespace
{
/// [m] Trần hiệu chỉnh tịnh tiến. Xem lý do ở validate().
constexpr double kMaxCalibXy = 0.30;
/// [rad] Trần hiệu chỉnh góc, ~11 độ.
constexpr double kMaxCalibYaw = 0.20;
bool positive(double value)
{
return std::isfinite(value) && value > 0.0;
@@ -124,6 +130,26 @@ bool DockProfile::validate(std::string& error) const
error = "offset_x/offset_y/offset_yaw must be finite";
return false;
}
if (!std::isfinite(calib_x) || !std::isfinite(calib_y) || !std::isfinite(calib_yaw))
{
error = "calib_x/calib_y/calib_yaw must be finite";
return false;
}
// Chặn trên có chủ đích. Hiệu chỉnh hiện trường là centimet và độ; ai gõ 0.5 m vào đây thì thứ
// họ đang bù không phải sai số cảm biến mà là một lỗi hình học ở `offset_*` — và dán băng dính
// lên nó bằng calib là giấu mất nguyên nhân.
if (std::fabs(calib_x) > kMaxCalibXy || std::fabs(calib_y) > kMaxCalibXy)
{
error = "calib_x/calib_y must be within +-" + std::to_string(kMaxCalibXy) +
" m; a larger correction means offset_x/offset_y is wrong, not miscalibrated";
return false;
}
if (std::fabs(calib_yaw) > kMaxCalibYaw)
{
error = "calib_yaw must be within +-" + std::to_string(kMaxCalibYaw) +
" rad; a larger correction means the pattern geometry is wrong";
return false;
}
if (min_wing_points < 2)
{
// Hai điểm là tối thiểu tuyệt đối để có một đoạn; dưới đó không có gì để khớp.

View File

@@ -273,13 +273,17 @@ Detection VPatternMatcher::match(const std::vector<Line>& lines) const
best.measured_wing_length[1] = len2;
// Pose đích = đỉnh dịch theo offset của profile, trong hệ của CHÍNH hình: x dọc pháp tuyến
// hướng ra phía robot, y sang trái.
// hướng ra phía robot, y sang trái. `calib_*` cộng thẳng vào offset — cùng hệ quy chiếu, chỉ
// khác nguồn gốc: offset suy ra từ hình học, calib đo được ngoài hiện trường.
const double dx = profile_.offset_x + profile_.calib_x;
const double dy = profile_.offset_y + profile_.calib_y;
const double dyaw = profile_.offset_yaw + profile_.calib_yaw;
const double cos_y = std::cos(yaw);
const double sin_y = std::sin(yaw);
best.x = apex.x + cos_y * profile_.offset_x - sin_y * profile_.offset_y;
best.y = apex.y + sin_y * profile_.offset_x + cos_y * profile_.offset_y;
best.yaw = std::atan2(std::sin(yaw + profile_.offset_yaw),
std::cos(yaw + profile_.offset_yaw));
best.x = apex.x + cos_y * dx - sin_y * dy;
best.y = apex.y + sin_y * dx + cos_y * dy;
best.yaw = std::atan2(std::sin(yaw + dyaw), std::cos(yaw + dyaw));
}
}