Estimators¶
navkit.estimators.eskf
¶
Error-state Kalman filter fusing inertial, GNSS and visual data.
Formulation
Nominal state x = (R, p, v, b_a, b_g). The filter carries a 21-dimensional
error state in the order
``[dtheta (0:3), dp (3:6), dv (6:9), db_g (9:12), db_a (12:15),
c_p (15:18), c_t (18:21)]``
The first fifteen are the usual inertial states. c_p names the stored
anchor position error. c_t names a body-frame perturbation of the relative
visual rotation in the single-anchor model, and the stored-pose attitude error
in the clone model; _vision_update gives the convention for each. Both are
nuisance parameters, not physical states, needed because an anchor is a pose the
filter itself produced and its error is therefore not independent evidence. The
module docstring below explains the failure they fix and the one they do not.
The convention that the true state relates to the nominal one as
R_true = R Exp(dtheta), p_true = p + dp, v_true = v + dv, and the
biases additively. Gravity is a known constant, not a filter state.
This is the textbook first-order error-state formulation, not an invariant
one: the update equations are linearised around the current estimate and the
transport is not enforced through the group. That choice is deliberate and
documented in docs/architecture.md -- an invariant EKF gives marginally
better behaviour in fast rotation, and buys it with algebra that a reader
cannot check by inspection.
Process model (discrete, first order), with a = accel - b_a:
dp' = dp + dv dt
dv' = dv - R [a]x dt dtheta - R dt db_a
dtheta' = Exp(-omega dt) dtheta - dt db_g
Measurement models
- GNSS position:
z = p,H = [0 I 0 0 0]. - Visual relative rotation
R_rel = R_{i-1}^T R_i: the residual isLog(R_rel_meas R_rel_pred^T) = Log(R_rel_pred Exp(dtheta) R_rel_pred^T) = R_rel_pred dtheta, so the attitude block ofHisR_rel_predand not the identity. The two agree only whenR_rel_predis the identity. With the anchor modelled,c_tenters through-R_rel_pred J_r(c_t). It is a perturbation of the relative rotation, not the stored anchor attitude (see_vision_update); that Jacobian is exact under the stated generative model. The noise covariance is isotropic. - Visual relative translation
t_rel = R_{i-1}^T (p_i - p_{i-1}): withh(x) = R_prev^T (p_cur - p_prev)the residual ist_meas - h(x_nom)andH = [0 R_prev^T 0 0 0]. With the anchor modelled thec_pcolumn is-R_prev^Tand there is noc_tcolumn; the omitted[t]x c_tterm is a known limitation of the anchor model.
The previous side of a visual constraint is the filter state saved at the previous visual update, not at the previous inertial tick. At 200 Hz inertial against 20 Hz vision those are different poses, and using the inertial tick would make the relative constraint compare the current frame with itself.
A gate rejects updates whose normalised residual exceeds gate_sigma times
the predicted standard deviation, and the rejection count is reported. Silent
gating would hide a divergence, so it is counted rather than merely applied.
Fusing vision without corrupting the filter
A relative-pose visual measurement constrains how the vehicle moved, not where it is. Fusing one by re-deriving the visual anchor from the filter's own corrected state -- the obvious implementation, and the one this filter started with -- turns the two into the same thing: the filter is handed its own output and averages it as though it were fresh independent evidence. The covariance collapses, and once it has collapsed the filter is certain and wrong.
Measured figures for the failing configuration, the FDIR-gated one and the
anchor-as-a-state fix are in docs/results.md, generated from the benchmark.
They are not quoted here, because a typed copy goes stale.
The failure in one line: the claimed 1-sigma is centimetres while the error is metres, and the innovation gate discards a large share of the absolute GNSS fixes as outliers. A system monitoring only its own gating counters would see this as "vision is noisy", when the actual fault is that vision has silenced the GNSS.
With the FDIR gate active (ADR-0005) the error drops, which looks like an improvement. It is not one. More of the absolute fixes are discarded, and the claimed 1-sigma is unchanged, so the NEES stays far from calibrated. The gate is applying a chi-square test to an innovation covariance that the defect has already made wrong, and a stricter threshold on a wrong denominator buys a smaller number rather than a more correct filter. The run that the regression test measures is the FDIR-off one, on purpose: FDIR partially masks this defect, and a test that measured the masked version would be measuring the mitigation rather than the fault.
The fix is to carry the anchor error as states in the covariance, and it takes three things that are easy to get wrong:
- The anchor error is carried as six states (
c_p,c_t) in the covariance, rather than folded into the innovation covariance. An error common to every visual update is a quantity to be tracked, not noise to be divided down. The states carry a declared prior and their correlation with the live state. The correction computed for them is not applied to the stored anchor, so they do not estimate the anchor error (CN-003, ADR-0001; the reasoning is in the comment in_inject_correction). - Those states are given a declared uncertainty, not the filter's own covariance. Deriving the new anchor's uncertainty from the current covariance is circular, and it ratchets the overconfidence downward at every re-commit.
- The covariance update uses the Joseph form. The textbook shortcut
(I - K H) Pis symmetric but not positive semidefinite; with the anchor states it drove the smallest eigenvalue negative within two visual updates, which is a physically meaningless covariance rather than a small inaccuracy.
With GNSS available and vision enabled, the visual channel no longer causes the
GNSS fixes to be rejected (pinned by
test_enabling_the_visual_channel_no_longer_silences_the_gnss). The benchmark
measures calibration in that configuration only with an outage (outage_visual).
Vision with no GNSS at all is not calibrated: the vision_only row is badly
overconfident, because nothing constrains the absolute position. The generated
figures are in docs/results.md and the README table.
The limit that remains
Under a GNSS denial the same filter still over-trusts vision: the error is
metres against a claimed 1-sigma of centimetres, and the mean NEES is far above
its expected value (outage_visual in docs/results.md and the README
table). The cause is structural rather than a matter of tuning. The information
a visual measurement carries about absolute position is the Schur complement
P_pp - P_pc P_cc^-1 P_cp
Declaring the anchor blocks uncorrelated collapses this to P_pp: the
measurement acts as if the anchor did not exist. Declaring them perfectly
correlated -- which is the honest description of an anchor copied from the
current estimate -- collapses it to zero and makes the measurement model exactly
degenerate, which is numerically unusable. The truth lies between those extremes
and cannot be represented by one anchor state, because a chain of relative
measurements is only jointly informative about position once the whole chain
is considered. That requires a pose graph over the visual keyframes, not a
single-anchor ESKF, and it is the change this project has not made.
So the visual channel ships disabled by default. The failure above is not a
reason to hide it, and it stays measured in docs/results.md; it is a reason
not to hand a caller a filter that silently reports centimetres of uncertainty
while being metres wrong.
vision_anchor_modelled is exposed only so the regression tests can reproduce
the middle row.
Known simplifications
- Measurements are applied at the next inertial tick, so a measurement carries
a latency of up to one IMU period (5 ms at 200 Hz). This is recorded in the
result and is far below the timescales this project studies, but it does put
a floor under the effect of the
timestamp_offsetscenario. - With the visual channel disabled there is no constraint tying the bias states to anything but GNSS excitation, so a vision-only run has no absolute reference at all. Its error grows, and the covariance is expected to grow with it; a vision-only run cannot demonstrate a benefit over dead reckoning and must not be reported as one.
- The camera-to-IMU extrinsic is assumed identity.
- No motion-constrained zero-velocity or zero-rotation update is applied, so bias observability comes only from GNSS excitation over the sequence.
run(t0=...)truncates the inertial stream and cold-starts the filter at that instant with zero position, zero velocity and identity attitude. It does not mean "assist until t0 and then deny". A denial window must be expressed as a scenario on the fix stream, not as a start time.
FilterState
¶
Bases: TypedDict
The filter's propagated state.
This was annotated dict[str, np.ndarray], which was wrong in both
directions: it forbade the integers, the boolean, and the None that the
state genuinely holds, so the 12 type errors it produced were being silenced
with disable_error_code in pyproject.toml. Naming the members makes
a wrong key or a wrong dtype a type error at the point of the mistake, and
it lets the silence be removed.
anchor_snapshot is optional in practice -- it is absent until the first
GNSS outage opens, and the cross-check falls back to the live anchor when it
is missing -- so total=False models that honestly.
InitialState
dataclass
¶
Where a run starts, when it does not start at the origin at rest.
The default start is the identity pose at rest with zero biases, which is wrong for any recorded
sequence and no longer how the synthetic benchmark starts (it passes the true initial state plus a
draw from the declared prior, ADR-0027). A caller that knows the pose,
velocity and biases at the first sample (from a reference trajectory, or from an initial
alignment) passes them here. The covariance is not part of it: the declared
initial_*_sigma terms in :class:EskfConfig still say how far from the truth the
start is allowed to be.
EskfConfig
dataclass
¶
Tuning and noise for the filter, in physical units.
ErrorStateKalmanFilter
¶
21-state error-state Kalman filter over a timestamped IMU stream.
navkit.estimators.dead_reckoning
¶
Dead-reckoning reference estimator.
Integrates the (possibly degraded) inertial stream with no external updates. It exists for two reasons:
- It is the honest lower bound: with no aiding, inertial integration error accumulates without bound. Any aiding scheme must beat it, and showing the gap is more informative than showing one number.
- It isolates the replay harness from the fusion algorithm. If dead reckoning diverges by roughly the amount implied by the injected noise and bias, the harness is behaving; the divergence is not a bug in the replay plumbing.
Nominal propagation (world frame, gravity assumed known):
v <- v + (R f + g) dt
p <- p + v dt + 0.5 (R f + g) dt^2
R <- R Exp(omega dt)
InitialPose
¶
Bases: Protocol
What a start needs: attitude, position and velocity. :class:~navkit.estimators.eskf.InitialState has them.
EstimatorResult
dataclass
¶
Output of any estimator: the estimated trajectory plus run metadata.
DeadReckoning
¶
Midpoint (constant-acceleration) inertial integrator.
run(imu, t0=None, t_end=None, initial=None)
¶
Integrate the inertial stream.
initial is where the run starts: attitude, position and velocity, as for the filter. The default is the
identity pose at rest at the origin. A scene whose first pose is elsewhere needs the true start passed in,
or the error mixes that offset with the drift. The biases in initial are not used: this integrator has no
bias state.