39 #include <visp3/core/vpUnscentedKalman.h>
41 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
44 : m_hasUpdateBeenCalled(false)
49 , m_sigmaDrawer(drawer)
84 if (m_hasUpdateBeenCalled) {
88 m_hasUpdateBeenCalled =
false;
97 m_chi = m_sigmaDrawer->drawSigmaPoints(x, P);
105 size_t nbPoints = m_chi.size();
106 if (m_Y.size() != nbPoints) {
107 m_Y.resize(nbPoints);
109 for (
size_t i = 0; i < nbPoints; ++i) {
112 prior = m_stateAddFunction(prior, m_b(u, dt));
115 prior = m_stateAddFunction(prior, m_bx(u, m_chi[i], dt));
121 vpUnscentedTransformResult transformResults = unscentedTransform(m_Y, m_wm, m_wc, m_Q, m_stateResFunc, m_stateMeanFunc);
122 m_mu = transformResults.m_mu;
123 m_Ppred = transformResults.m_P;
128 size_t nbPoints = m_chi.size();
129 if (m_Z.size() != nbPoints) {
130 m_Z.resize(nbPoints);
132 for (
size_t i = 0; i < nbPoints; ++i) {
133 m_Z[i] = (m_h(m_Y[i]));
137 vpUnscentedTransformResult transformResults = unscentedTransform(m_Z, m_wm, m_wc, m_R, m_measResFunc, m_measMeanFunc);
138 m_muz = transformResults.m_mu;
139 m_Pz = transformResults.m_P;
142 vpMatrix Pxz = m_wc[0] * m_stateResFunc(m_Y[0], m_mu) * m_measResFunc(m_Z[0], m_muz).transpose();
143 size_t nbPts = m_wc.size();
144 for (
size_t i = 1; i < nbPts; ++i) {
145 Pxz += m_wc[i] * m_stateResFunc(m_Y[i], m_mu) * m_measResFunc(m_Z[i], m_muz).transpose();
150 m_Xest = m_stateAddFunction(m_mu, m_K * m_measResFunc(z, m_muz));
151 m_Pest = m_Ppred - m_K * m_Pz * m_K.
transpose();
152 m_hasUpdateBeenCalled =
true;
155 vpUnscentedKalman::vpUnscentedTransformResult vpUnscentedKalman::unscentedTransform(
const std::vector<vpColVector> &sigmaPoints,
156 const std::vector<double> &wm,
const std::vector<double> &wc,
const vpMatrix &cov,
157 const vpAddSubFunction &resFunc,
const vpMeanFunction &meanFunc
160 vpUnscentedKalman::vpUnscentedTransformResult result;
163 result.m_mu = meanFunc(sigmaPoints, wm);
167 size_t nbSigmaPoints = sigmaPoints.
size();
168 for (
size_t i = 0; i < nbSigmaPoints; ++i) {
169 vpColVector e = resFunc(sigmaPoints[i], result.m_mu);
176 void vpUnscentedKalman_dummy()
unsigned int getCols() const
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
vpRowVector transpose() const
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of a matrix and operations on matrices.
vpMatrix inverseByCholesky() const
vpMatrix transpose() const
vpUnscentedKalman(const vpMatrix &Q, const vpMatrix &R, std::shared_ptr< vpUKSigmaDrawerAbstract > &drawer, const vpProcessFunction &f, const vpMeasurementFunction &h)
Construct a new vpUnscentedKalman object.
void update(const vpColVector &z)
Update the estimate of the state based on a new measurement.
void filter(const vpColVector &z, const double &dt, const vpColVector &u=vpColVector())
Perform first the prediction step and then the filtering step.
void predict(const double &dt, const vpColVector &u=vpColVector())
Predict the new state based on the last state and how far in time we want to predict.
std::function< vpColVector(const vpColVector &)> vpMeasurementFunction
Measurement function, which converts the prior points in the measurement space. The argument is a poi...
std::function< vpColVector(const vpColVector &, const double &)> vpProcessFunction
Process model function, which projects the sigma points forward in time. The first argument is a sigm...
void init(const vpColVector &mu0, const vpMatrix &P0)
Set the guess of the initial state and covariance.
The weights corresponding to the sigma points drawing.
std::vector< double > m_wm
std::vector< double > m_wc