The constructor mergeLines uses took only the fitted parameters and the ray
indices, leaving c_data_ and r_data_ default-constructed. pointAt indexes
r_data_.xs directly, so asking a merged segment where one of its own rays is
read past the end of an empty vector.
Two callers already do exactly that. The reflective-tape check walks the ray
span of a wing and reads each point; the arc matcher gathers the points of
adjacent segments to fit a circle to them. The arc matcher is how it surfaced -
it segfaulted, and AddressSanitizer put it on line.cpp:58.
It stayed hidden because mergeLines almost never fires with the default
parameters: a gap wide enough to split at is already wider than max_line_gap,
which is the gate merging has to pass. That is the merge gate working as
intended, and it is also why this could not be reached from a synthesized
scene - a scene-based test here would guard nothing, so the regression test
builds a merged Line directly instead.
The constructor now takes the scan data, like the other one. A merged segment
is still built from the same scan, so there was never a reason for it to lose
it, and a consumer cannot tell a merged segment from a fresh one - the
invariant has to be that every segment answers for every ray it supports.
pointAt also bounds-checks now and returns NaN for a ray it does not carry.
That is a second line of defence, not the fix: every caller already has to
reject non-finite points because a real scan contains them, so a future
constructor that forgets the data degrades instead of reading out of bounds.
Line already holds the scan it was fitted from, so pointAt() is a lookup and
not a conversion. A consumer that wants to say something about the individual
rays behind a segment - which of them are bright, where along the segment they
sit - would otherwise have to be handed the whole scan alongside the segment
and re-derive what the segment already knows.
The index is a ray number, the same numbering getIndices() returns, so it also
reaches rays the segment dropped as outliers or that a split pushed into a
neighbouring segment.
The iterative weighted fit started from the line through the first and last
supporting point. That is a Newton iteration on a non-convex objective started
from a poor guess, and measured on a V dock plate at 1.7-2.5 m with 3 mm range
noise, 22-24% of all segments spent the whole 50-iteration budget without
converging.
Seeding from a closed-form total-least-squares fit over every supporting point
takes that to 0%: from the answer, the iteration converges in a step or two.
The seed also decides what a segment keeps when the iteration does give up, and
two endpoints are a poor thing to fall back on - the direction of the whole
segment then rests on the range noise of exactly two rays, several times the
angular error of a seventeen-point fit, and on a V that error lands straight on
the apex because the apex is where the two wings intersect.
Measured over 400 scans per case:
endpoint seed TLS seed
fits converged 76-78% 100%
apex yaw sd @1.7 m 0.0116 rad 0.0055 rad
apex y sd @1.7 m 0.0084 m 0.0040 m
apex yaw sd @2.5 m 0.0163 rad 0.0087 rad
apex y sd @2.5 m 0.0114 m 0.0061 m
Detection rate stays 100%. This matters end to end: the docking action needs
five detections agreeing within 0.030 m and 0.050 rad, and on the robot the
spread was sitting at 0.031-0.039 m, just over the line, so a run took 11.9 s
to find a window that happened to fall inside instead of converging at once.
TotalLeastSquaresIsAnchoredByEveryPointNotJustTheTwoEnds pins the property that
makes the seed worth having, by comparing the two fits directly on a wall whose
two end rays are pushed apart while the nineteen between them stay clean.
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.
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.