fix: the arc pose was defined against the sensor, so it followed the robot
The target point was the point on the fitted circle furthest from the sensor,
and yaw was the direction from there back to the sensor. Both are defined
against WHERE YOU ARE STANDING, so the detector always reported that the dock
faces exactly where the robot happens to be. Measured on one fixed cradle from
five positions:
view offset 0 10 20 30 40 deg
yaw error -0.0 -10.0 -20.0 -30.0 -40.0 deg
The yaw error equals the viewing offset exactly, and the target slid along the
arc with it, from (0.400, 0.000) to (0.306, -0.257). Nothing in the log looked
wrong. It surfaced because the goal moved between missions while the cradle had
not been touched.
A CIRCLE has no axis. Only the physical ARC does, and it is the bisector of the
two endpoint radii. fitCircle now reports mid_angle, and the pose comes from
that: target = C + R*(cos mid, sin mid), yaw = mid + pi. Same five positions:
yaw error -0.2 -0.2 -0.3 -2.4 -3.9 deg
I had written the old definition up as a feature - stable when part of the arc
is hidden. It was stable, at the wrong value, by not looking at the shape.
The residual at 30-40 degrees is real and has to be gated, not hidden: an
occluded edge moves the observed midpoint, and the measured relationship is
yaw error ~= (true span - observed span) / 2. So arc_span is now checked on
BOTH sides with its own arc_span_tolerance, rather than being an upper bound
borrowing slack from arc_radius_tolerance. Seeing too little of the arc is as
dangerous as seeing too much, and only one of those was being caught.
This reverses the earlier reasoning that copied the V's asymmetric wing rule.
The analogy does not hold: a V's apex and bisector survive one wing being
short because they are intrinsic, and an arc's axis does not exist at all
without both edges.
ThePoseFollowsTheDockNotTheRobot pins it, and pins it by rotating the DOCK, not
the world. The first draft rotated the whole scene about the sensor, which
leaves the sensor-to-dock relationship unchanged and passes under the old
definition too - it guarded nothing. Rotating the dock in place fails the old
code by 20.05 degrees.
RefusesAnArcWithAnEdgeHiddenBecauseTheAxisWouldBeWrong replaces a test that
asserted the opposite. That test was pinning the bug.
This commit is contained in:
@@ -116,8 +116,9 @@ DockProfile arcProfile()
|
||||
p.pattern = PatternType::kArc;
|
||||
p.arc_radius = 0.40; // [m]
|
||||
p.arc_radius_tolerance = 0.06; // [m]
|
||||
p.arc_span = 2.2; // [rad] toàn phần của máng
|
||||
p.arc_min_span = 0.52; // [rad]
|
||||
p.arc_span = 2.0; // [rad] góc mở THẬT của máng, không cộng dư
|
||||
p.arc_span_tolerance = 0.20; // [rad] hai phía
|
||||
p.arc_min_span = 0.52; // [rad] sàn số học
|
||||
p.arc_max_rms = 0.010; // [m]
|
||||
p.min_arc_points = 8;
|
||||
p.min_confidence = 0.3;
|
||||
@@ -207,50 +208,63 @@ TEST(ArcPatternMatcher, TheOffsetMovesTheTargetOutTowardsTheRobot)
|
||||
EXPECT_NEAR(d.y, 0.00, 0.03);
|
||||
}
|
||||
|
||||
TEST(ArcPatternMatcher, APartlyOccludedArcStillGivesTheSameDeepestPoint)
|
||||
TEST(ArcPatternMatcher, ThePoseFollowsTheDockNotTheRobot)
|
||||
{
|
||||
// Đây là lý do điểm đích được định nghĩa từ TÂM và BÁN KÍNH chứ không phải trung điểm cung quan
|
||||
// sát được: che một bên thì trung điểm dịch ngay, còn tâm thì không.
|
||||
// ĐÂY LÀ TEST QUAN TRỌNG NHẤT CỦA CẢ TỆP.
|
||||
//
|
||||
// Bản đầu lấy điểm trên đường tròn XA CẢM BIẾN NHẤT làm đích, và hướng từ đó về phía cảm biến làm
|
||||
// yaw. Cả hai định nghĩa theo VỊ TRÍ NGƯỜI QUAN SÁT, nên bộ dò luôn báo rằng cái máng quay mặt
|
||||
// đúng vào chỗ robot đang đứng — và không dòng log nào tỏ ra bất thường.
|
||||
//
|
||||
// Cách kiểm PHẢI là xoay CÁI MÁNG, không phải xoay cả thế giới quanh cảm biến: xoay cả thế giới
|
||||
// thì quan hệ cảm biến↔máng không đổi, và định nghĩa cũ vẫn ra đúng. Đó là một test vô dụng, và
|
||||
// bản nháp của test này chính là như vậy.
|
||||
//
|
||||
// Ở đây tâm máng đứng NGUYÊN một chỗ; chỉ hướng của máng đổi. Định nghĩa cũ cho ra cùng một yaw
|
||||
// trong cả hai lượt vì tâm không đổi. Định nghĩa đúng phải đi theo hướng của máng.
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.ok_) << rig.error_;
|
||||
|
||||
const Detection full = rig.run(concaveCradle(1.60, 0.40, 2.0));
|
||||
ASSERT_TRUE(full.valid) << full.reason;
|
||||
const double cx = 1.60;
|
||||
const double r = 0.40;
|
||||
const double span = 2.0;
|
||||
|
||||
// Chỉ còn nửa bên phải của cung.
|
||||
const Detection half = rig.run(arcSegments(1.60, 0.0, 0.40, 0.0, 1.0));
|
||||
ASSERT_TRUE(half.valid) << half.reason;
|
||||
for (const double axis : { 0.0, 0.35 }) // [rad] huong cua mang, 0.35 rad = 20 do
|
||||
{
|
||||
// Cung vẽ đối xứng quanh `axis` tính từ TÂM; mặt cong ở xa hơn tâm nên vẫn là máng lõm.
|
||||
const Detection d = rig.run(arcSegments(cx, 0.0, r, axis - span / 2.0, span));
|
||||
ASSERT_TRUE(d.valid) << "axis=" << axis << ": " << d.reason;
|
||||
|
||||
EXPECT_NEAR(half.apex_x, full.apex_x, 0.03);
|
||||
EXPECT_NEAR(half.apex_y, full.apex_y, 0.03);
|
||||
// Đích = tâm + bán kính theo hướng máng. Hướng ra miệng = axis + pi.
|
||||
const double want_x = cx + r * std::cos(axis);
|
||||
const double want_y = r * std::sin(axis);
|
||||
const double want_yaw = std::atan2(std::sin(axis + M_PI), std::cos(axis + M_PI));
|
||||
double dyaw = std::atan2(std::sin(d.yaw - want_yaw), std::cos(d.yaw - want_yaw));
|
||||
|
||||
EXPECT_NEAR(d.apex_x, want_x, 0.03) << "axis=" << axis;
|
||||
EXPECT_NEAR(d.apex_y, want_y, 0.03) << "axis=" << axis;
|
||||
EXPECT_LT(std::fabs(dyaw), 0.09)
|
||||
<< "axis=" << axis << ": yaw lech " << dyaw * 180.0 / M_PI
|
||||
<< " do — pose dang bam theo cho robot dung, khong theo huong mang";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ArcPatternMatcher, AWallJustPastTheArcIsNotAbsorbedIntoIt)
|
||||
TEST(ArcPatternMatcher, RefusesAnArcWithAnEdgeHiddenBecauseTheAxisWouldBeWrong)
|
||||
{
|
||||
// Hồi quy cho một lỗi CHỈ SIM MỚI LỘ. Ban đầu phép gom chỉ xét khoảng cách theo SỐ TIA, và trong
|
||||
// world Gazebo bức tường ngay sau máng chỉ cách 2 tia — lọt ngưỡng. Bốn đoạn của máng bị gom
|
||||
// cùng bức tường 6.6 m, khớp tròn trên cả cụm cho bán kính 3.2 m và sai số 0.11 m, nên cái máng
|
||||
// thật bị loại vì một thứ không thuộc về nó.
|
||||
// Mặt kia của test trên. Trục của máng suy từ HAI đầu mút; che mất một bên là trung điểm cung
|
||||
// dịch đi, và trục dịch theo đúng ngần ấy — âm thầm, không có dấu hiệu nào khác.
|
||||
//
|
||||
// Liền nhau theo số tia KHÔNG có nghĩa là liền nhau trong không gian: tia kế tiếp có thể rơi
|
||||
// xuống một mặt cách đó vài mét.
|
||||
// Bản trước có một test khẳng định ngược lại: cung bị che nửa vẫn ra "cùng điểm sâu nhất". Đúng
|
||||
// theo định nghĩa cũ, và chính vì thế định nghĩa cũ sai — nó ổn định bằng cách không nhìn vào
|
||||
// hình dạng vật.
|
||||
//
|
||||
// Không suy được trục thì phải TỪ CHỐI, không được đoán.
|
||||
Rig rig;
|
||||
ASSERT_TRUE(rig.ok_) << rig.error_;
|
||||
|
||||
// Máng ở 2 m; mép của nó nằm quanh bearing +-0.17 rad.
|
||||
std::vector<Segment> world = concaveCradle(1.60, 0.40, 2.0);
|
||||
|
||||
// Tường ở 4 m, bắt đầu ngay sát mép máng theo GÓC nhưng cách xa theo KHÔNG GIAN.
|
||||
const double a0 = 0.18;
|
||||
const double a1 = 0.95;
|
||||
world.push_back({ 4.0 * std::cos(a0), 4.0 * std::sin(a0), 4.0 * std::cos(a1),
|
||||
4.0 * std::sin(a1) });
|
||||
|
||||
const Detection d = rig.run(world);
|
||||
ASSERT_TRUE(d.valid) << d.reason;
|
||||
EXPECT_NEAR(d.apex_x, 2.00, 0.03);
|
||||
EXPECT_NEAR(d.measured_arc_radius, 0.40, 0.03);
|
||||
EXPECT_LT(d.measured_arc_rms, 0.010) << "sai so khop no ra = da nuot ca buc tuong";
|
||||
const Detection d = rig.run(arcSegments(1.60, 0.0, 0.40, 0.0, 1.0)); // chi con nua ben phai
|
||||
EXPECT_FALSE(d.valid) << d.reason;
|
||||
EXPECT_NE(d.reason.find("edge is hidden"), std::string::npos) << d.reason;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
@@ -312,7 +326,8 @@ TEST(ArcPatternMatcher, RefusesAnArcThatShowsTooLittleOfItself)
|
||||
TEST(ArcPatternMatcher, RefusesAnArcThatSpansMoreThanTheProfileSays)
|
||||
{
|
||||
DockProfile p = arcProfile();
|
||||
p.arc_span = 1.0; // [rad] mang that chi mo 1.0 rad
|
||||
p.arc_span = 1.0; // [rad] máng thật chỉ mở 1.0 rad
|
||||
p.arc_span_tolerance = 0.20; // [rad]
|
||||
Rig rig(p);
|
||||
ASSERT_TRUE(rig.ok_) << rig.error_;
|
||||
|
||||
@@ -363,6 +378,11 @@ TEST(ArcPatternMatcher, RefusesAProfileThatCanNeverMatch)
|
||||
EXPECT_FALSE(m.configure(p, error));
|
||||
EXPECT_NE(error.find("arc_radius_tolerance"), std::string::npos) << error;
|
||||
|
||||
p = arcProfile();
|
||||
p.arc_span_tolerance = p.arc_span; // dung sai nuot tron phep do
|
||||
EXPECT_FALSE(m.configure(p, error));
|
||||
EXPECT_NE(error.find("arc_span_tolerance"), std::string::npos) << error;
|
||||
|
||||
p = arcProfile();
|
||||
p.arc_min_span = p.arc_span + 0.1; // san cao hon tran: khong cung nao lot
|
||||
EXPECT_FALSE(m.configure(p, error));
|
||||
|
||||
Reference in New Issue
Block a user