2 Commits

Author SHA1 Message Date
00e5f3e2cb 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.
2026-08-26 21:09:26 +07:00
8eb0040efa feat: detect a concave arc, the cradle that curves around the robot
Second shape after the V. Same output contract - a pose in the scan frame - so
dock_target and everything downstream of it are untouched.

CircleFit uses Taubin rather than Kasa, and that is the whole reason it is
worth writing rather than reaching for the four-line linear fit. Kasa is biased
on a SHORT arc, and a short arc is the normal case: the dock is partly hidden,
or the robot approaches at an angle. Measured on a true 0.40 m arc, 18 points,
3 mm noise, averaged over 200 seeds:

   arc span   Taubin      Kasa
    180 deg   +0.0 mm    -0.0 mm
     90 deg   +0.1 mm    -1.4 mm
     45 deg   +1.9 mm   -24.3 mm
     30 deg   +8.6 mm  -101.6 mm     <- Kasa reads 0.40 m as 0.298 m
     20 deg  +25.4 mm  -256.7 mm

With Kasa a 0.40 m dock seen at an angle is scored as 0.30 m, falls outside
radius_tolerance, and the symptom is "it never detects" - indistinguishable
from the dock not being in range. arc_min_span defaults to 30 degrees off that
same table, because below it even Taubin starts to drift.

The matcher takes line segments as input even though it is looking for a curve.
The extractor breaks a curved surface into short straight pieces - correct
behaviour, and convenient here: those pieces are adjacent by ray number, so
their combined support is the arc's point run. That reuses the gap splitting
and outlier rejection that already ran instead of adding a second segmenter
beside the first. A short shallow arc can come out as one segment, looking
straight under min_split_dist, and still fits: the circle fit reads raw points
and does not care what the extractor called them.

Grouping keys on this_start >= prev_end, not >. On a distance split the
extractor SHARES the corner point between both halves, so two pieces of one
surface meet at the same ray number. Requiring strictly greater grouped
nothing, and every 0.5 rad fragment then failed arc_min_span - a real arc
rejected on a fragment's arithmetic. The shared point is also skipped when
gathering, so it does not get double weight at the joint.

The gates, in order:
  - fit residual first, because EVERY set of points fits some circle, a right
    angle included. Residual is the only thing separating an arc from a bend,
    so radius and span only mean something after it passes.
  - span has a floor (numerical: trust the fit) and a ceiling (geometric: a
    longer arc is a different object). Not an equality - occlusion only ever
    shortens an arc, the same asymmetry as the V's wing lengths.
  - concavity: the centre must lie between the sensor and the surface. A convex
    cylinder is the same circle curving the other way, and taking one for the
    other puts the target pose behind the surface - the robot is told to drive
    into the object.

The target is the deepest point, C * (1 + R/|C|), which depends only on centre
and radius and so does not move when part of the arc is hidden. The midpoint of
the observed arc would be easier and would shift the moment one side is
occluded.

tape_enabled is refused on an arc profile rather than ignored. findTape walks
the ray span of a fitted line and an arc produces none, so accepting the flag
would leave someone believing a gate is protecting them.

Measured end to end, 200 runs per cell, 3 mm noise, 690 rays: 100% detection at
1.4-2.0 rad of span out to 3 m, apex within 1-2 mm, radius read as 0.399-0.401
against a true 0.400. It thins out at 0.7 rad (77-80% near, 26% at 5 m), which
is arc_min_span doing its job.
2026-08-26 20:09:31 +07:00