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.
This commit is contained in:
@@ -57,12 +57,25 @@ public:
|
||||
return radius_;
|
||||
}
|
||||
|
||||
/// @brief Row-major 2x2 covariance of (radius, angle). Only meaningful after @ref leastSqFit.
|
||||
/// @brief Row-major 2x2 covariance of (radius, angle). Only meaningful when @ref hasCovariance.
|
||||
const std::array<double, 4>& getCovariance() const
|
||||
{
|
||||
return covariance_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Whether the weighted fit converged, so the covariance means something.
|
||||
*
|
||||
* false = the segment carries only its endpoint fit. Angle, radius, endpoints and support are
|
||||
* all still usable — the dump of a failed run shows them correct to a millimetre — but the
|
||||
* covariance is whatever the iteration left behind, so nothing may decide by it. @ref
|
||||
* LineExtractor::mergeLines refuses to merge such a segment for exactly that reason.
|
||||
*/
|
||||
bool hasCovariance() const
|
||||
{
|
||||
return has_covariance_;
|
||||
}
|
||||
|
||||
const std::array<double, 2>& getStart() const
|
||||
{
|
||||
return start_;
|
||||
@@ -96,9 +109,13 @@ public:
|
||||
/**
|
||||
* @brief Weighted least-squares fit, iterated to convergence, then the covariance.
|
||||
*
|
||||
* @return false if it did not converge within the iteration cap, leaving the endpoint fit in
|
||||
* place. Upstream looped unbounded here; a scan that makes the increment oscillate then
|
||||
* hangs the control thread outright, which is worse than a line that failed to refine.
|
||||
* @return false if it did not converge within the iteration cap, leaving the ENDPOINT fit in
|
||||
* place and @ref hasCovariance false. Upstream looped unbounded here; a scan that makes
|
||||
* the increment oscillate then hangs the control thread outright, which is worse than a
|
||||
* line that failed to refine.
|
||||
*
|
||||
* @note false is not a reason to discard the segment. It stops being refined, not being a
|
||||
* segment — see @ref hasCovariance.
|
||||
*/
|
||||
bool leastSqFit();
|
||||
|
||||
@@ -133,6 +150,7 @@ private:
|
||||
std::array<double, 2> start_{ { 0.0, 0.0 } };
|
||||
std::array<double, 2> end_{ { 0.0, 0.0 } };
|
||||
std::array<double, 4> covariance_{ { 0.0, 0.0, 0.0, 0.0 } };
|
||||
bool has_covariance_ = false;
|
||||
};
|
||||
|
||||
} // namespace robot_line_extraction
|
||||
|
||||
@@ -75,6 +75,24 @@ struct LineExtractionParams
|
||||
/// Fewer supporting points than this and the line is dropped. Below 3 a fit is meaningless.
|
||||
unsigned int min_line_points = 6;
|
||||
|
||||
/**
|
||||
* [rad] Two segments whose directions differ by more than this are never merged.
|
||||
*
|
||||
* Merging exists to rejoin one surface that noise broke in two, and it decides by comparing the
|
||||
* line parameters against their own covariance. That test is only as good as the covariance, and
|
||||
* on a short run of ten or so rays the covariance is wide enough that two walls meeting at a
|
||||
* right angle come out "statistically indistinguishable" and get fused into one segment. The
|
||||
* corner then vanishes, and anything looking for a corner - a dock plate above all - finds one
|
||||
* line where there were two.
|
||||
*
|
||||
* The endpoint-gap rule cannot catch this: at a corner the two segments touch, so the gap is
|
||||
* zero. Only the angle separates them.
|
||||
*
|
||||
* Default 0.26 rad, about 15 degrees: far wider than the wobble between two pieces of one wall,
|
||||
* far narrower than any corner worth keeping.
|
||||
*/
|
||||
double merge_max_angle = 0.26;
|
||||
|
||||
/**
|
||||
* @brief Reject a parameter set that cannot produce a sensible fit.
|
||||
* @param[out] error Which field, and why.
|
||||
|
||||
Reference in New Issue
Block a user