33 #ifndef INCLUDED_FlexibleUnscentedCorrect_h_GUID_21E01E3B_5BD0_4F85_3B75_BBF6C657DBB4
34 #define INCLUDED_FlexibleUnscentedCorrect_h_GUID_21E01E3B_5BD0_4F85_3B75_BBF6C657DBB4
48 template <
typename State,
typename Measurement>
74 SigmaPointsGen::NumSigmaPoints;
78 using TransformedSigmaPointsMat =
79 typename Reconstruction::TransformedSigmaPointsMat;
84 State &s, Measurement &m,
86 : state(s), measurement(m),
88 getAugmentedStateCov(s, m), params),
91 reconstruction(sigmaPoints, transformedPoints),
93 state, measurement, reconstruction)),
98 deltaz(measurement.getResidual(reconstruction.getMean(), state)),
100 stateCorrection(K *
deltaz),
103 computeStateCorrection(reconstruction,
deltaz, PvvDecomp)),
105 stateCorrectionFinite(stateCorrection.array().allFinite()) {
109 Measurement
const &m) {
110 AugmentedStateVec ret;
112 ret << s.stateVector(), MeasurementVec::Zero();
116 static AugmentedStateCovMatrix getAugmentedStateCov(State
const &s,
118 AugmentedStateCovMatrix ret;
127 static TransformedSigmaPointsMat
130 TransformedSigmaPointsMat ret;
132 for (std::size_t i = 0; i < NumSigmaPoints; ++i) {
133 tempS.setStateVector(sigmaPoints.getSigmaPoint(i));
134 ret.col(i) = meas.predictMeasurement(tempS);
139 static MeasurementSquareMatrix
140 computeInnovationCovariance(State
const &s, Measurement &meas,
141 Reconstruction
const &recon) {
142 return recon.getCov() + meas.getCovariance(s);
150 static GainMatrix computeKalmanGain(MeasurementSquareMatrix
const &Pvv,
151 Reconstruction
const &recon) {
154 GainMatrix ret = Pvv.transpose().ldlt().solve(recon.getCrossCov());
158 static StateVec computeStateCorrection(
159 Reconstruction
const &recon, MeasurementVec
const &
deltaz,
160 Eigen::LDLT<MeasurementSquareMatrix>
const &pvvDecomp) {
161 StateVec ret = recon.getCrossCov() * pvvDecomp.solve(deltaz);
172 StateSquareMatrix newP = state.errorCovariance() -
175 StateSquareMatrix newP =
190 state.errorCovariance() -
191 reconstruction.getCrossCov() *
192 PvvDecomp.solve(MeasurementSquareMatrix::Identity()) *
193 reconstruction.getCrossCov().transpose();
195 bool finite = newP.array().allFinite();
196 if (cancelIfNotFinite && !finite) {
200 state.setStateVector(state.stateVector() + stateCorrection);
202 state.setErrorCovariance(newP);
210 Measurement &measurement;
211 SigmaPointsGen sigmaPoints;
212 TransformedSigmaPointsMat transformedPoints;
213 Reconstruction reconstruction;
216 Eigen::LDLT<MeasurementSquareMatrix> PvvDecomp;
222 StateVec stateCorrection;
223 bool stateCorrectionFinite;
225 template <
typename State,
typename Measurement>
227 beginUnscentedCorrection(
228 State &s, Measurement &m,
235 #endif // INCLUDED_FlexibleUnscentedCorrect_h_GUID_21E01E3B_5BD0_4F85_3B75_BBF6C657DBB4
Eigen::Matrix< Scalar, n, 1 > Vector
A vector of length n.
static AugmentedStateVec getAugmentedStateVec(State const &s, Measurement const &m)
static TransformedSigmaPointsMat transformSigmaPoints(State const &s, Measurement &meas, SigmaPointsGen const &sigmaPoints)
typename detail::Dimension_impl< T >::type Dimension
Eigen::Matrix< Scalar, n, n > SquareMatrix
A square matrix, n x n.
Vector< Dimension< T >::value > DimVector
A vector of length = dimension of T.
static const types::DimensionType AugmentedStateDim
state augmented with measurement noise mean
SquareMatrix< Dimension< T >::value > DimSquareMatrix
A square matrix, n x n, where n is the dimension of T.
MeasurementSquareMatrix innovationCovariance
aka Pvv
types::Vector< m > deltaz
reconstructed mean measurement residual/delta z/innovation
bool finishCorrection(bool cancelIfNotFinite=true)
std::size_t DimensionType
Type for dimensions.
Eigen::Matrix< Scalar, m, n > Matrix
A matrix with rows = m, cols = n.