Repository navigation
Galilean equivariant filter with online GNSS delay estimation - #2857
MosesTheRedSea wants to merge 7 commits into
Conversation
dellaert
left a comment
There was a problem hiding this comment.
We reviewed in our meeting. Please re-request review when you think it's ready.
|
@MosesTheRedSea any movement on this? |
|
final changes today pushing everything next 15 minutes. |
|
Updated the naming convention to I built As we discussed, the Galilean equivariant filter is split across the five files needed for the paper:
A couple of questions:
Let me know if there are any other changes you'd like. |
|
further standardized file names across all "equivariant filter" related things in gtsam_unstable. edit: removed my changes, factored into #2948 |
dellaert
left a comment
There was a problem hiding this comment.
Two performance suggestions with concrete replacement code: integrate the buffered IMU history on demand, and share the A/B linearization blocks.
| void UpsilonBuffer::push(const Vector10& wTilde, double dt) { | ||
| entries_.push_back({now_, wTilde, Gal3()}); | ||
| const Gal3 increment = Gal3::Expmap(wTilde * dt); | ||
| for (Entry& e : entries_) e.upsilon = e.upsilon * increment; // eq. 20 |
There was a problem hiding this comment.
Could we simplify this by keeping the recent corrected IMU samples and integrating from the requested start to now whenever a GNSS measurement arrives?
This loop updates every retained suffix at every IMU step. With N buffered intervals, that means N group compositions per sample, even when no GNSS update needs them. Storing the held inputs instead makes push() amortized O(1); at() then does O(log N + M) work for the M intervals covered by the query. Here is a concrete replacement that keeps the current public buffer API.
1. In Gal3GnssEqFCommon.h, replace the private Entry struct with:
struct Entry {
double start; ///< Elapsed time at the start of this hold interval.
Vector10 input; ///< Bias-corrected input captured when pushed.
double dt; ///< Original duration of this hold interval.
};2. In Gal3GnssEqFSymmetry.cpp, replace push() and at() with the following. Keep span() unchanged; the existing <algorithm> include is sufficient.
void UpsilonBuffer::push(const Vector10& wTilde, double dt) {
// dt is the hold duration supplied by predict(), not an IMU timestamp.
entries_.push_back({now_, wTilde, dt});
now_ += dt;
// Keep the interval that contains the beginning of the retained window.
while (entries_.size() > 1 && entries_[1].start <= now_ - window_) {
entries_.pop_front();
}
}
Gal3 UpsilonBuffer::at(double delta, Vector10* wStart) const {
if (entries_.empty()) {
if (wStart) wStart->setZero();
return Gal3();
}
const double s = now_ - std::clamp(delta, 0.0, span());
auto it = std::upper_bound(
entries_.begin(), entries_.end(), s,
[](double value, const Entry& e) { return value < e.start; });
if (it != entries_.begin()) --it;
if (wStart) *wStart = it->input;
// Preserve the endpoint input above, even for a zero/negative delay.
if (s == now_) return Gal3();
// Only the first interval can be partial. Clamp roundoff at its ends.
const double firstDt =
std::clamp(it->dt - (s - it->start), 0.0, it->dt);
Gal3 upsilon = Gal3::Expmap(it->input * firstDt);
for (++it; it != entries_.end(); ++it) {
// Time order matters: append each later increment on the RIGHT.
upsilon = upsilon * Gal3::Expmap(it->input * it->dt);
}
return upsilon;
}A few details matter here:
- Keep passing the existing
wTilde = imu.extended() - bias(xi)frompredict(). This preserves the current policy of freezing each sample's bias correction when it is recorded; a later bias update does not re-correct old samples. startandnow_remain elapsed times accumulated fromdt. Neither optionalstampfield becomes part of the time calculation. As in the current prediction path, hold durations must be positive.- The first exponential covers only the remaining part of the interval containing
s. Later intervals use their original stored durations, and their increments are multiplied in chronological order on the right. - The pruning rule, empty-buffer result, delay clamp, and
wStartselection are retained. In particular, an exact internal boundary selects the interval starting there, and a nonempty zero-delay query still returns the last input throughwStart.
3. Avoid integrating the same window twice in update(). Its current predictGnss(state()) and measurementMatrixC() calls each query the buffer. Replace those two lines with:
Matrix3x20 H;
const Point3 yHat = predictGnss(state(), H);
const Matrix3x10 HF = H.leftCols<10>();
const Matrix3x20 C = EqFOutputMatrixC(groupEstimate(), HF);This uses the existing Jacobian output of predictGnss(); the public measurementMatrixC() can remain for other callers and tests. Also update the buffer documentation and the comment above buffer_.push() to describe storing inputs and integrating on demand.
This trades work at the IMU rate for work at the query rate, so please profile the complete prediction/update path: each query now evaluates the interval exponentials, and frequent calls to delayedNavState() or measurementMatrixC() also incur this cost.
I checked the replacement buffer in a standalone C++/Eigen harness using the 5x5 Gal(3) matrix representation against the current suffix algorithm: 9,600 queries across variable durations, pruning, changing biases, partial intervals, boundaries, and out-of-range delays agreed to about 1.1e-13 per matrix entry, with identical wStart selections. That is an isolated check, not a GTSAM build. Please add those boundary cases to the repository tests and run the existing filter tests as well.
There was a problem hiding this comment.
in the other implementation, every new IMU sample looped over all buffer entries and updated each one's stored Υ, even when no GNSS fix needed it. Now the buffer just saves each sample (start, input, dt), and at() only integrates when a GNSS fix comes in. update() also reads the buffer once now by reusing the Jacobian from predictGnss().
Added tests that check the buffer against a brute-force calculation and cover edge cases (empty buffer, zero delay, exact boundaries, delays past the buffer). Also added one checking the new C in update() matches measurementMatrixC(). All tests pass.
Results match the old code to ~1e-12. Overall it's ~1.3x faster at 200 Hz and ~2.5x faster at 1000 Hz.
| const Matrix20 Phi = EqFStateMatrixA(X, gN_, wTilde, dt); | ||
| const Matrix20 B = EqFInputMatrixB(X, gN_, wTilde, dt); |
There was a problem hiding this comment.
These two calls use the same X, gN_, wTilde, and dt, but each independently calls errorBlocks(). Each IMU prediction therefore repeats the same two Gal3 exponentials, exponential derivative, and adjoint computations.
Could we compute the common blocks once and assemble both matrices from them? The following keeps the existing single-matrix functions available for tests and other callers.
1. In Gal3GnssEqFSymmetry.cpp, insert these two private helpers immediately after errorBlocks(), before the anonymous namespace closes:
Matrix20 stateMatrixA(const ErrorBlocks& k, double dt) {
// eq. 34 in GTSAM error coordinates (S A S).
Matrix20 Phi = Matrix20::Zero();
Phi.topLeftCorner<10, 10>() = k.A1;
Phi.topRightCorner<10, 10>() = -k.A1 * k.JL * dt;
Phi.bottomRightCorner<10, 10>() = k.A2;
return Phi;
}
Matrix20 inputMatrixB(const ErrorBlocks& k, double dt) {
// eq. 36 in GTSAM error coordinates (S B).
Matrix20 B = Matrix20::Zero();
B.topLeftCorner<10, 10>() = -k.A1 * k.JL * k.AdX * dt;
B.bottomRightCorner<10, 10>() = k.A2 * k.AdX * dt;
return B;
}2. Replace the existing EqFStateMatrixA and EqFInputMatrixB definitions with these three functions, outside the anonymous namespace:
Matrix20 EqFStateMatrixA(const Group& X, const Vector10& gN,
const Vector10& wTilde, double dt) {
return stateMatrixA(errorBlocks(X, gN, wTilde, dt), dt);
}
Matrix20 EqFInputMatrixB(const Group& X, const Vector10& gN,
const Vector10& wTilde, double dt) {
return inputMatrixB(errorBlocks(X, gN, wTilde, dt), dt);
}
void EqFStateAndInputMatrices(const Group& X, const Vector10& gN,
const Vector10& wTilde, double dt,
Matrix20& Phi, Matrix20& B) {
const ErrorBlocks k = errorBlocks(X, gN, wTilde, dt);
Phi = stateMatrixA(k, dt);
B = inputMatrixB(k, dt);
}3. In Gal3GnssEqFSymmetry.h, retain both existing declarations and add this declaration immediately after EqFInputMatrixB:
/// Compute Phi and B with shared intermediate blocks.
/// The output arguments must refer to distinct matrices.
GTSAM_UNSTABLE_EXPORT void EqFStateAndInputMatrices(
const Group& X, const Vector10& gN, const Vector10& wTilde,
double dt, Matrix20& Phi, Matrix20& B);4. Replace the two calls here with:
Matrix20 Phi, B;
EqFStateAndInputMatrices(X, gN_, wTilde, dt, Phi, B);The Qd calculation and predictWithStep() call stay unchanged. This preserves the formulas, multiplication order, signs, and dt scaling while removing the duplicate common-block calculation.
I compiled the assembly helpers in an isolated C++/Eigen check and compared them with the original expressions over 1,000 randomized block sets at dt = 0, 0.005, 0.1; the outputs were elementwise identical. This was not a full GTSAM build. For the repository regression, please compare both outputs of the combined function against the existing single-matrix APIs using a nonidentity X and several time steps, then run the existing symmetry and filter tests.
There was a problem hiding this comment.
in th eold code, predict() called EqFStateMatrixA() and EqFInputMatrixB() separately, so errorBlocks() ran twice per IMU step with the same inputs. Now EqFStateAndInputMatrices() computes the blocks once and builds both Φ and B. The original two functions are still there and use the same helpers, so the math is unchanged.
Added a test that checks the combined function matches the two separate ones exactly, using a random nonidentity X and dt = 0, 0.005 and 0.1. The existing symmetry and filter tests still pass.
41d3d86 to
074dbdc
Compare
dellaert
left a comment
There was a problem hiding this comment.
I reviewed this with Codex. The on-demand IMU buffer and shared A/B computation address the earlier performance concerns. Three things to fix before merging:
- The GNSS delay Jacobian disagrees with the prediction outside the IMU buffer.
UpsilonBuffer::at()clamps the query, butGnssOutput()still subtracts the endpoint input as if the integration interval changed. In a finite-difference check with 0.2 s of history and velocity(1,0,0), the reported derivative agreed at 0.1 s; at −0.1 s and 0.3 s it reported zero where the numerical derivative was(1,0,0)m/s. Make the derivative match the clamped prediction, or reject updates outside usable history. Please test both ends. - Nonfinite sensor input can corrupt the filter.
update()checks the covariance but not the GNSS position. In a Release-style build, a NaN position with identity covariance was accepted, incremented the counter, and left the position nonfinite. A NaN IMU timestep also bypasses the currentdt <= 0guard. Reject nonfinite input before changing state, history, or counters. - The symmetry test doesn't compile on Apple Clang.
Symmetry::Orbit(State::Identity())(Group::Identity(), &Dphi0)is parsed as a declaration. Changing the constructor toSymmetry::Orbit{State::Identity()}made all 14 symmetry tests pass in the targeted Mac build. The 15 filter tests passed unchanged.
…d Python wrapper, tests and example notebook
074dbdc to
96a45a4
Compare
Implements Algorithm 1 of Delama et al., "Galilean State Estimation for Inertial Navigation Systems with Unknown Time Delay" (RSS 2026), on top of
EquivariantFilter, following the EqVIO structure made by Rohan.It estimates attitude, velocity, position, IMU biases and the unknown GNSS delay online, with the delay represented as the time component of a Gal(3) frame.