1 Commits

Author SHA1 Message Date
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