Skip to content

Fix outlier gate to compare residual against sqrt(map_v + v) - #147

Open
shravankumargulvadi wants to merge 1 commit into
leggedrobotics:ros2from
shravankumargulvadi:fix/mahalanobis-residual-gate
Open

shravankumargulvadi wants to merge 1 commit into
leggedrobotics:ros2from
shravankumargulvadi:fix/mahalanobis-residual-gate

Conversation

@shravankumargulvadi

@shravankumargulvadi shravankumargulvadi commented Oct 24, 2026 •

Copy link
Copy Markdown

The outlier gate compares a height difference (metres) against a scaled variance (square metres):

abs(map_h - z) > (map_v * mahalanobis_thresh)

The units don't match, so the check only behaves sensibly when the variance happens to be near 1. The obvious fix is to compare against the cell's standard deviation, sqrt(map_v). Since the residual also carries the measurement noise v (already computed just above), sqrt(map_v + v) seemed like the right step, that's the actual standard deviation of map_h - z, i.e. what "Mahalanobis distance" means here.

Applied to all three places using this comparison: the fusion outlier gate, the edge-sharpen check, and the drift-compensation inlier counter. kk.py had identical copies and is updated too, though it doesn't appear to be imported anywhere, happy to drop it instead.

Also added tests/test_outlier_gate.py: a confident cell receiving a point 1cm off now fuses it (stock code rejects it and inflates variance), and a 60cm residual is still rejected.

@shravankumargulvadi

shravankumargulvadi commented Oct 24, 2026 •

Copy link
Copy Markdown
Author

Closing, opened prematurely, will resubmit after internal review.

@shravankumargulvadi
shravankumargulvadi deleted the fix/mahalanobis-residual-gate branch October 24, 2026 17:13
The outlier gate compared |map_h - z| (metres) against map_v *
mahalanobis_thresh (square metres). As cells converge and map_v
shrinks, the acceptance band collapses quadratically, so confident
cells reject good measurements and each rejection inflates variance
again.

Compare against the residual standard deviation instead: for
independent cell and measurement errors the residual variance is
map_v + v, so the gate becomes sqrt(map_v + v) * thresh, matching
what "Mahalanobis distance" means and keeping both sides in metres.
Applied to the fusion gate, the edge-sharpen check, and the drift-
compensation inlier counter. The same expressions are fixed in kk.py,
which is currently dead code.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@shravankumargulvadi
shravankumargulvadi restored the fix/mahalanobis-residual-gate branch October 24, 2026 17:19
@shravankumargulvadi
shravankumargulvadi force-pushed the fix/mahalanobis-residual-gate branch from 4e8021f to 89431b5 Compare October 24, 2026 17:21
@shravankumargulvadi

shravankumargulvadi commented Oct 24, 2026 •

Copy link
Copy Markdown
Author

@mktk1117 please take a look (I have used the AI coding agent to generate the test for my fix and have retained it as coauthor of the commit). The same issue seems to exist in the ROS1 (main) branch as well, I can back-port this fix if needed.

@shravankumargulvadi

shravankumargulvadi commented Nov 2, 2026 •

Copy link
Copy Markdown
Author

Tagging another potential reviewer to this PR, @Idate96 please take a look or tag the right person to review this PR, thanks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant