Commit Graph

2 Commits

Author SHA1 Message Date
d8f11d2df6 fix: keep a segment whose least-squares refinement did not converge
extract() dropped any run whose weighted fit ran out of iterations. That was
too harsh: a failed refinement loses only the covariance, while the angle,
radius, endpoints and support all remain those of the endpoint fit and stay
usable.

Measured on a V dock plate at 2 m with 34 rays on the plate: both wings split
correctly with 17-18 points each and lengths correct to a few millimetres, yet
one of the two vanished on roughly half of the noise realizations because its
fit hit the 50-iteration cap. Everything downstream then saw one line where
there were two, and the corner disappeared. End-to-end V detection rate was
48%; keeping the segment takes it to 100% across 0-5 mm tape protrusion at
both 2 m and 3 m.

Line now reports hasCovariance(), false when the fit did not converge, and
mergeLines() refuses to merge such a segment - merging decides by comparing
line parameters against their own covariance, so a meaningless covariance must
not be allowed to make that decision.

TheLeastSquaresLoopIsBounded keeps guarding the iteration cap itself; the new
ALineThatFailedToRefineIsStillReturned guards against dropping the segment,
and fails if extract() goes back to discarding it.
2026-08-26 15:55:32 +07:00
duongtd
1d38e77afa Extract line segments from an ordered range scan
Fitting a line needs the ranges in ray order with a known angular step. A
costmap has neither: at 0.05 m with inflation it has already destroyed ray
order and object shape, so the two 0.2 m wings of a dock plate are one blob
there. This is the consumer that robot_sensor_ports keeps readings raw for.

Pure geometry - the input is a scan layout and a vector of ranges, the output
is segments in polar form with their endpoints, supporting rays and
covariance. Eigen is the only dependency and only the merge step uses it. No
robot_cpp, no costmap, no message types, which is what makes it testable
against synthetic scans with no runtime around it: build the shape, generate
the rays, and the answer is known in advance.

Polar rather than slope-intercept because a vertical wall has no finite slope
and a laser sees vertical walls constantly. Radius is kept non-negative so one
line has one representation - otherwise the merge step sees two.

Ported from laser_line_extraction (Marc Gallant, BSD) with the ROS layer
removed, and four defects fixed, each with a test that fails without the fix:

split() sliced with &indices[i_split - 1] and &indices.back(), dropping a point
off each half at every split. Anything angular came out a ray short at both
ends of every arm.

mergeLines() called resize() and then inserted at end(), leaving the first half
of the vector zero-filled. A merged line reported twice its real support and
every index in that half pointed at ray 0.

The least-squares loop had no iteration cap. The increment is a ratio of two
sums that can both approach zero on a degenerate run, and when it oscillates
the loop never exits - in a control thread that is a stopped robot, not a slow
frame. Segments that will not converge are now dropped, since their covariance
would be meaningless and the merge step decides by covariance.

Merging compared line parameters and nothing else, so two halves of a wall
either side of a doorway - perfectly collinear - were rejoined into one segment
spanning the doorway, undoing the split that had just separated them for that
exact reason. Merging now also requires the facing endpoints to be within
max_line_gap, so split and merge agree on what one surface means.

The corner point at a distance split now belongs to both halves. It is the last
point of one surface and the first of the next; giving it to one side shortens
the other arm by a ray and tilts its fit.

split() is iterative over an explicit stack rather than recursive: depth is
bounded only by the ray count, and a noisy scan that splits at nearly every
point would recurse a thousand deep in the control thread.

Parameters are validated at configure time rather than per scan. A threshold
that can never produce a fit otherwise shows up as "the detector finds
nothing", which is indistinguishable from a sensor fault.
2026-08-26 12:09:28 +07:00