6 Commits

Author SHA1 Message Date
b5f61111bc build: add BUILD_DOCK_PATTERN_DETECTOR_TESTS option, off by default
Tests used to build whenever CATKIN_ENABLE_TESTING was on. They now also
need -DBUILD_DOCK_PATTERN_DETECTOR_TESTS=ON, in both build modes.
2026-11-17 20:36:11 +07:00
7ce7c7db52 feat(reflector_pair): add ReflectorPairMatcher for two flat reflective strips on a wall
Pure geometry core for the upcoming wall reflector detection action. The wall
line is fitted from dark rays only; each strip edge is the half-step bearing
between the intensity core and its neighbour, intersected with that line, so
the range bias of bright returns never enters the pose. Exactly one valid pair
is required; two or more report ambiguous. Synthetic tests cover geometry,
quantisation, bloom, bright range bias, realistic range noise, wall ends,
occluders, ambiguity and malformed input.
2026-11-12 10:12:57 +07:00
979bef360d fix(leg_pattern): accept attached legs, treat zero range as no echo, rank ties by fit
On the KIT robot (28/10), hiding one trolley leg with a post always made
detection fail with "too few legs". The far-right leg stood less than
leg_min_depth_gap in front of another object, so its cluster was rejected
as "attached". Hiding one more leg left only two free-standing legs.

- LegProfile::accept_attached_legs (default false): an attached cluster
  that passes the width and point gates becomes a weak leg. A weak leg
  can be assigned to a corner, counts toward min_legs and enters the fit,
  but it cannot start a hypothesis. So every cart still needs one pair of
  free-standing legs at the right spacing.
- ScanLimits::zero_range_is_no_echo (default false): the KIT driver
  reports no echo as range 0. The matcher read 0 as "blocked closer than
  min_range", so every leg edge was marked partial, and a 0 ray at a
  missing corner always read as occluded. With the flag set, an edge next
  to a 0 ray is free. A corner that sees only 0 rays carries no evidence.
  A ray that passes the corner and returns from a surface behind it still
  rejects the cart.
- Confidence ties: fit_term saturates at 1, so two 4-leg hypotheses can
  both score 1.00. The nearer one used to win, even when it had taken a
  post standing 9 cm from a leg (3.4 cm off). Ties now go to the lower
  normalized RMS first.
- LegDetection::legs_attached; the reason text says when only attached
  legs were found at the cart spacing.

Tests: leg_pattern_matcher_kit_test replays 6 real KIT scans
(test/data/kit_f_scan_trolley_occlusion.txt). leg_pattern_matcher_test
adds 4 synthetic cases. With both keys off, behaviour is unchanged except
for the tie rule. All 111 tests of this package and the trolley handler
pass.
2026-10-28 16:37:28 +07:00
c568e90c53 feat(leg_pattern): add LegPatternMatcher for 4-leg trolleys
Finds a 4-leg trolley in a raw LaserScan without line extraction:
shadow filter, leg clusters in ray order with free/occluded/attached edges,
pair hypotheses from cart_opening/cart_depth/diagonal, then a Gauss-Newton
pose fit over every leg point with an along-ray residual, Huber weights and
backtracking. Gates: pair spacing after the fit, see-through leg positions,
optional empty interior, entry side (entry tape / prior yaw / facing the
sensor), optional prior, confidence, and ambiguity between two carts.

LegProfile validates every key at load. Two gtests (7 + 23) run on a
synthetic ray-cast scan (test/leg_scan_sim.h). Used by trolley_detection_action.
2026-10-28 13:43:56 +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
duongtd
a694d5abe2 Find a dock plate in a laser scan and say where the robot must stop
The detection chain had a gap between line segments and a navigation goal.
This is that step: segments plus the geometry of one charger, out comes the
pose base_link has to reach, in the scan's own frame.

Pure geometry, no TF and no action, so it is testable the same way the line
extractor is - build the world, cast the rays, and the answer is known before
the code runs. The tests exercise the real chain end to end, from synthetic
world through robot_line_extraction into the matcher.

The output is the goal pose, not the charger's pose. dock_planner deliberately
carries no standoff key: it derives which edge of the robot meets the dock from
which side of the goal the robot stands on, and that only works because the
goal already is where base_link must end up. The standoff is also a property of
the charger - how deep its contacts sit - so it belongs to the profile.
apex_x/apex_y keep the pre-offset vertex, because a wrong offset and a wrong
detection look identical from the final pose alone.

Matching a V:

The vertex is the intersection of the two fitted lines, not the midpoint of
their endpoints. A line is a least-squares fit over tens of rays; an endpoint
is one ray and much noisier.

Both segments must END near that intersection. Any two non-parallel walls cross
somewhere, and without this gate a corridor corner reads as a dock.

The vertex angle is measured between the two wing vectors from the apex, not
between the two normals. The two agree at exactly 90 degrees and diverge
everywhere else, so confusing them is a silent error at every other opening.

Wing length is what rejects a pallet corner: a pallet has a perfect right
angle, it just has metre-long sides.

Yaw is the bisector pointing back at the sensor, and its sign is chosen by
comparing against the sensor position rather than by the order of the two
wings. That order flips with which side the robot approaches from, and being
180 degrees out here means reversing into the plate instead of driving in.

Confidence is the worst of the three criteria, not their mean. A mean lets a
shape with a badly wrong angle through on the strength of the other two.

The search gate is not optional in a warehouse: any two perpendicular pallets
are a V. candidate_count reports how many survived every gate, so an ambiguous
scene is visible to the layer above rather than silently resolved.

A failed detection reports which gate it failed. "Nothing there" and "something
there but the wrong length" need opposite responses, and one failure line
cannot carry that.

Declaring a pattern that is not implemented is refused at configure time.
Accepting it would produce a detector that never finds anything, which looks
exactly like a charger out of range.
2026-08-26 12:38:29 +07:00