Skip to content

Commit fe72ca8

Browse files
authored
Update Kalman3D_Wave.h
1 parent c160148 commit fe72ca8

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

bbn_wave_freq_m5atomS3/Kalman3D_Wave.h

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ template<typename T, bool with_gyro_bias, bool with_accel_bias>
579579
void Kalman3D_Wave<T, with_gyro_bias, with_accel_bias>::time_update(
580580
Vector3 const& gyr, T Ts)
581581
{
582-
// ===== Mean propagation (unchanged) =====
582+
// ===== Mean propagation =====
583583
Vector3 gyro_bias;
584584
if constexpr (with_gyro_bias) {
585585
gyro_bias = xext.template segment<3>(3);
@@ -588,10 +588,12 @@ void Kalman3D_Wave<T, with_gyro_bias, with_accel_bias>::time_update(
588588
}
589589
last_gyr_bias_corrected = gyr - gyro_bias;
590590

591+
// Δθ = ω Ts → quaternion increment
591592
Eigen::Quaternion<T> dq = quat_from_delta_theta((last_gyr_bias_corrected * Ts).eval());
592593
qref = qref * dq;
593594
qref.normalize();
594595

596+
// Build F, Q
595597
MatrixNX F_a_ext;
596598
MatrixNX Q_a_ext;
597599
assembleExtendedFandQ(Vector3::Zero(), Ts, F_a_ext, Q_a_ext);
@@ -611,82 +613,75 @@ void Kalman3D_Wave<T, with_gyro_bias, with_accel_bias>::time_update(
611613
xext.template segment<3>(OFF_S) = x_lin_next.template segment<3>(6);
612614
xext.template segment<3>(OFF_AW) = x_lin_next.template segment<3>(9);
613615

614-
// ===== Covariance propagation (block-wise, complete) =====
615-
constexpr int NA = BASE_N; // attitude (+ gyro bias if enabled)
616+
// ===== Covariance propagation (block-wise exact) =====
617+
constexpr int NA = BASE_N; // attitude (+ gyro bias)
616618
constexpr int NL = 12; // [v p S a_w]
617619
constexpr int NC = with_accel_bias ? 3 : 0;
618620

619-
// Blocks of F and Q we actually need
621+
// F and Q blocks
620622
const Eigen::Matrix<T,NA,NA> F_AA = F_a_ext.template block<NA,NA>(0,0);
621623
const Eigen::Matrix<T,NL,NL> F_LL = F_a_ext.template block<NL,NL>(OFF_V, OFF_V);
622624
Eigen::Matrix<T,NC,NC> F_CC;
623-
if constexpr (with_accel_bias) {
624-
F_CC.setIdentity(); // accel bias is RW ⇒ F = I
625-
}
625+
if constexpr (with_accel_bias) F_CC.setIdentity();
626626

627627
const Eigen::Matrix<T,NA,NA> Q_AA = Q_a_ext.template block<NA,NA>(0,0);
628628
const Eigen::Matrix<T,NL,NL> Q_LL = Q_a_ext.template block<NL,NL>(OFF_V, OFF_V);
629629
Eigen::Matrix<T,NC,NC> Q_CC;
630-
if constexpr (with_accel_bias) {
631-
Q_CC = Q_a_ext.template block<NC,NC>(OFF_BA, OFF_BA);
632-
}
630+
if constexpr (with_accel_bias) Q_CC = Q_a_ext.template block<NC,NC>(OFF_BA, OFF_BA);
633631

634-
// Take needed P blocks (read-only views)
632+
// Old P blocks
635633
const Eigen::Matrix<T,NA,NA> P_AA = Pext.template block<NA,NA>(0,0);
636634
const Eigen::Matrix<T,NL,NL> P_LL = Pext.template block<NL,NL>(OFF_V, OFF_V);
637-
638635
Eigen::Matrix<T,NA,NL> P_AL = Pext.template block<NA,NL>(0, OFF_V);
636+
637+
Eigen::Matrix<T,NC,NC> P_CC;
639638
Eigen::Matrix<T,NA,NC> P_AC;
640639
Eigen::Matrix<T,NL,NC> P_LC;
641-
Eigen::Matrix<T,NC,NC> P_CC;
642640
if constexpr (with_accel_bias) {
641+
P_CC = Pext.template block<NC,NC>(OFF_BA, OFF_BA);
643642
P_AC = Pext.template block<NA,NC>(0, OFF_BA);
644643
P_LC = Pext.template block<NL,NC>(OFF_V, OFF_BA);
645-
P_CC = Pext.template block<NC,NC>(OFF_BA, OFF_BA);
646644
}
647645

648-
// ---- propagate diagonal blocks ----
646+
// Diagonal block updates
649647
Eigen::Matrix<T,NA,NA> P_AA_new = F_AA * P_AA * F_AA.transpose() + Q_AA;
650648
Eigen::Matrix<T,NL,NL> P_LL_new = F_LL * P_LL * F_LL.transpose() + Q_LL;
651649

652650
Eigen::Matrix<T,NC,NC> P_CC_new;
653651
if constexpr (with_accel_bias) {
654-
// F_CC = I, so: P_CC' = P_CC + Q_CC
655-
P_CC_new = P_CC + Q_CC;
652+
P_CC_new = P_CC + Q_CC; // F_CC = I
656653
}
657654

658-
// ---- propagate cross blocks (because F is block-diagonal) ----
655+
// Cross blocks
659656
Eigen::Matrix<T,NA,NL> P_AL_new = F_AA * P_AL * F_LL.transpose();
660-
661657
Eigen::Matrix<T,NA,NC> P_AC_new;
662658
Eigen::Matrix<T,NL,NC> P_LC_new;
663659
if constexpr (with_accel_bias) {
664-
// F_CC = I
665660
P_AC_new = F_AA * P_AC;
666661
P_LC_new = F_LL * P_LC;
667662
}
668663

669-
// ---- write back (and enforce symmetry) ----
670-
Pext.template block<NA,NA>(0,0) = P_AA_new;
671-
Pext.template block<NL,NL>(OFF_V, OFF_V) = P_LL_new;
672-
Pext.template block<NA,NL>(0, OFF_V) = P_AL_new;
673-
Pext.template block<NL,NA>(OFF_V, 0) = P_AL_new.transpose();
664+
// Write back
665+
Pext.template block<NA,NA>(0,0) = P_AA_new;
666+
Pext.template block<NL,NL>(OFF_V,OFF_V) = P_LL_new;
667+
Pext.template block<NA,NL>(0,OFF_V) = P_AL_new;
668+
Pext.template block<NL,NA>(OFF_V,0) = P_AL_new.transpose();
674669

675670
if constexpr (with_accel_bias) {
676-
Pext.template block<NC,NC>(OFF_BA, OFF_BA) = P_CC_new;
677-
Pext.template block<NA,NC>(0, OFF_BA) = P_AC_new;
678-
Pext.template block<NC,NA>(OFF_BA, 0) = P_AC_new.transpose();
679-
Pext.template block<NL,NC>(OFF_V, OFF_BA) = P_LC_new;
680-
Pext.template block<NC,NL>(OFF_BA, OFF_V) = P_LC_new.transpose();
671+
Pext.template block<NC,NC>(OFF_BA,OFF_BA) = P_CC_new;
672+
Pext.template block<NA,NC>(0,OFF_BA) = P_AC_new;
673+
Pext.template block<NC,NA>(OFF_BA,0) = P_AC_new.transpose();
674+
Pext.template block<NL,NC>(OFF_V,OFF_BA) = P_LC_new;
675+
Pext.template block<NC,NL>(OFF_BA,OFF_V) = P_LC_new.transpose();
681676
}
682677

683-
// Final symmetry clean-up
678+
// Enforce symmetry
684679
Pext = T(0.5) * (Pext + Pext.transpose());
685680

686-
// Keep mirror of the base block (for your accessors)
681+
// Mirror base block
687682
Pbase = Pext.topLeftCorner(NA, NA);
688683

689-
// ===== periodic pseudo-measurement on S (unchanged) =====
684+
// ===== periodic pseudo-measurement =====
690685
if (++pseudo_update_counter_ >= PSEUDO_UPDATE_PERIOD) {
691686
applyIntegralZeroPseudoMeas();
692687
pseudo_update_counter_ = 0;

0 commit comments

Comments
 (0)