Commit Graph

3 Commits

Author SHA1 Message Date
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
cb401e6316 fix(leg_pattern): let cart_dim_tolerance widen the confidence score
The fit term divided the residual by the lidar noise only, so a trolley that
is a few cm off the profile (machining tolerance between carts of the same
type) scored a "poor fit" even though its pose was accurate: 3 legs seen and
a 3 cm error gave confidence 0.38 < 0.5 and the action timed out on the KIT
robot.

Add FitNoise::model_sigma and divide by sqrt(sigma^2 + model_sigma^2) when
scoring. The matcher passes cart_dim_tolerance / 2. Only the score changes:
the fit weights, the pose and the rms are bit-identical. A cart far outside
the tolerance is still rejected by the pair gates.

Tests: model_sigma changes the score but not the pose; a cart 3 cm narrower
and 2.5 cm longer than the profile is accepted with 4 and with 3 legs; a cart
15 cm wider is rejected. v/arc/circle tests unchanged.
2026-10-28 15:48:49 +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