fix: report residuals as observed minus computed - #70
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #70 +/- ##
=======================================
Coverage 98.56% 98.56%
=======================================
Files 7 7
Lines 488 488
=======================================
Hits 481 481
Misses 7 7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
giove-a
force-pushed
the
sc/residual-convention-fix
branch
from
August 5, 2026 10:39
9c11a68 to
0d8a789
Compare
`SatInfo.residual` and `SatInfo.rate_residual` change sign. Both are now measured − modeled, the orientation GNSS software reports observation residuals in: RTKLIB's `rescode` (`v = P - (r + dtr - c·dts + dion + dtrp)`) and `resdop` (`v = -λ·D - (rate + ċ - c·dts)`), and GNSS-SDR and PocketSDR, which take both from RTKLIB — GNSS-SDR vendors it as `rtklib_pntpos.cc` and PocketSDR calls `pntpos()` and logs `ssat[i].resp[0]` as its per-satellite residual. Neither sign was chosen before. The pseudorange residual was whatever `LsqFit` returns (`resid = model - data`), and the range-rate one was written to match its wording. So the values were self-consistent but inverted against every reference implementation, and against a receiver that forms the same difference itself. The negation is the whole of the change: it is applied to the converged fit and to the solved velocity, so both solves — their iterations, their normal equations, the state they return — are untouched. `calc_pvt` passes the vectors straight through. No API, type or arity changes. One asymmetry is worth stating because it survives the fix and is invisible in magnitudes: `yⱼ` carries `-doppler * λ`, so `rate_residual` runs in the geometric range-rate sense — positive while the satellite *recedes* — which is RTKLIB's `resdop` sense but the negative of the `λ · carrier_doppler` a tracking loop works in. A consumer forming the rate residual from its own loops has to negate one of the two. Documented on `SatInfo` and at the residual loop. Tests pin both orientations directly (`test/pvt.jl`): a satellite measured 100 m long keeps a positive residual and one measured short a negative one, antisym- metric to sub-mm; and a satellite whose Doppler is raised by 50 Hz — closing faster — moves its rate residual negative by less than `λ · 50 Hz`. Every other residual assertion in the suite is magnitude- or orthogonality-based and so was blind to the sign, which is why a flip needed pinning of its own. Full suite passes, including the opt-in L125 real-data fix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
giove-a
force-pushed
the
sc/residual-convention-fix
branch
from
August 5, 2026 10:48
0d8a789 to
2066e47
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
SatInfo.residualandSatInfo.rate_residualchange sign. Both are now measured − modeled, the orientation GNSS software reports observation residuals in.Neither sign had been chosen. The pseudorange residual was whatever
LsqFithands back (resid = model - data), and #67 wrote the range-rate one to match its wording. Self-consistent, but inverted against every reference implementation — and against any receiver that forms the same difference itself.Why measured − modeled
pntpos.c: rescode()v[nv] = P - (r + dtr - CLIGHT*dts + dion + dtrp), withH[j] = -e[j]pntpos.c: resdop()v[nv] = -lam*obs[i].D[band] - (rate + x[3] - CLIGHT*dts)src/algorithms/libs/rtklib/rtklib_pntpos.cc— both lines verbatimsrc/sdr_pvt.ccalls RTKLIB'spntpos()and logsssat[i].resp[0], i.e. that samev, as its per-satelliteresObserved minus computed, in both domains, in all three.
How
The negation is the whole of the change. It is applied to the converged fit and to the solved velocity, so both solves — their iterations, their normal equations, the state they return — are untouched, and
calc_pvtpasses the vectors straight through.No API, type or arity change: field access and keyword construction are unaffected, which is why this is a
fix:and not afeat!:.One asymmetry survives, and is now documented
yⱼcarries-doppler * λ, sorate_residualruns in the geometric range-rate sense — positive while the satellite recedes. That is RTKLIB'sresdopsense, but the negative of theλ · carrier_dopplera tracking loop works in. A consumer forming the rate residual from its own loops has to negate one of the two; magnitudes agree either way.This is invisible to a magnitude check, so it is stated on
SatInfoand at the residual loop rather than left to be rediscovered. It is exactly what bit the downstream port below: matching the wording of "modeled − measured" there produced numbers inverted against this package's, and only a numerical comparison caught it.Tests
Every existing residual assertion in the suite is magnitude- or orthogonality-based, so all of them pass either sign — which is how the inversion went unnoticed in the first place. The new testset pins the orientations directly, in both domains:
1 - Pⱼⱼ, its leverage;λ · 50 Hz.Full suite passes, including the opt-in L125 real-data fix (
PVT_RUN_INTEGRATION_TEST=true, 8/8).Downstream
GNSSReceiver.jl's vector-tracking loop reports the same two fields from its navigation filter and has been aligned in lockstep (itssc/vector-trackingbranch): pseudorangez - h(x), rateh(x) - z, the second because of the observable asymmetry above. Verified numerically against this branch rather than from the docstrings:Anything else thresholding on the sign of
residual(rather thanabs) inverts;rate_residualis new in 5.0.0 and not yet in General, so it has no released consumers to speak of.Merges cleanly with #68 and #69 — neither touches these lines.
🤖 Generated with Claude Code