25 #ifndef INCLUDED_FlexibleKalmanCorrect_h_GUID_354B7B5B_CF4F_49AF_7F71_A4279BD8DA8C
26 #define INCLUDED_FlexibleKalmanCorrect_h_GUID_354B7B5B_CF4F_49AF_7F71_A4279BD8DA8C
39 template <
typename StateType,
typename MeasurementType>
40 struct CorrectionInProgress {
43 types::Dimension<MeasurementType>::value;
46 types::Dimension<StateType>::value;
48 CorrectionInProgress(
StateType &state, MeasurementType &meas,
49 types::SquareMatrix<n>
const &P_,
50 types::Matrix<n, m>
const &PHt_,
51 types::SquareMatrix<m>
const &S)
52 : P(P_), PHt(PHt_), denom(S), deltaz(meas.getResidual(state)),
53 stateCorrection(PHt * denom.solve(deltaz)), state_(state),
54 stateCorrectionFinite(stateCorrection.array().allFinite()) {}
57 types::SquareMatrix<n> P;
60 types::Matrix<n, m> PHt;
70 Eigen::LDLT<types::SquareMatrix<m>> denom;
73 types::Vector<m> deltaz;
76 types::Vector<n> stateCorrection;
79 bool stateCorrectionFinite;
88 bool finishCorrection(
bool cancelIfNotFinite =
true) {
92 types::SquareMatrix<n> newP =
93 P - (PHt * denom.solve(PHt.transpose()));
100 OSVR_KALMAN_DEBUG_OUTPUT(
101 "error covariance scale",
102 (types::SquareMatrix<n>::Identity() - PHt * denom.solve(H)));
103 types::SquareMatrix<n> newP =
104 (types::SquareMatrix<n>::Identity() - PHt * denom.solve(H)) * P;
107 if (!newP.array().allFinite()) {
112 state_.setStateVector(state_.stateVector() + stateCorrection);
115 state_.setErrorCovariance(newP);
119 state_.setErrorCovariance((newP + newP.transpose()) / 2.);
124 state_.postCorrect();
133 typename MeasurementType>
134 inline CorrectionInProgress<StateType, MeasurementType>
136 MeasurementType &meas) {
160 return CorrectionInProgress<StateType, MeasurementType>(state, meas, P,
167 #endif // INCLUDED_FlexibleKalmanCorrect_h_GUID_354B7B5B_CF4F_49AF_7F71_A4279BD8DA8C
typename FilterType::State StateType
Given a filter type, get the state type.
typename detail::Dimension_impl< T >::type Dimension
Eigen::Matrix< Scalar, n, n > SquareMatrix
A square matrix, n x n.
The main namespace for all C++ elements of the framework, internal and external.
typename FilterType::ProcessModel ProcessModelType
Given a filter type, get the process model type.
CorrectionInProgress< StateType, MeasurementType > beginCorrection(StateType &state, ProcessModelType &processModel, MeasurementType &meas)
std::size_t DimensionType
Type for dimensions.
Eigen::Matrix< Scalar, m, n > Matrix
A matrix with rows = m, cols = n.