Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpUnscentedKalman.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Display a point cloud using PCL library.
32 */
33
34#ifndef VP_UNSCENTED_KALMAN_H
35#define VP_UNSCENTED_KALMAN_H
36
37#include <visp3/core/vpConfig.h>
38
39#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
40#include <visp3/core/vpColVector.h>
41#include <visp3/core/vpMatrix.h>
42#include <visp3/core/vpUKSigmaDrawerAbstract.h>
43
44#include <functional> // std::function
45#include <memory> // std::shared_ptr
46
143class VISP_EXPORT vpUnscentedKalman
144{
145public:
152 typedef std::function<vpColVector(const vpColVector &, const double &)> vpCommandOnlyFunction;
153
160 typedef std::function<vpColVector(const vpColVector &, const vpColVector &, const double &)> vpCommandStateFunction;
161
169 typedef std::function<vpColVector(const std::vector<vpColVector> &, const std::vector<double> &)> vpMeanFunction;
170
176 typedef std::function<vpColVector(const vpColVector &)> vpMeasurementFunction;
177
183 typedef std::function<vpColVector(const vpColVector &, const double &)> vpProcessFunction;
184
192 typedef std::function<vpColVector(const vpColVector &, const vpColVector &)> vpAddSubFunction;
193
207 vpUnscentedKalman(const vpMatrix &Q, const vpMatrix &R, std::shared_ptr<vpUKSigmaDrawerAbstract> &drawer, const vpProcessFunction &f, const vpMeasurementFunction &h);
208
215 void init(const vpColVector &mu0, const vpMatrix &P0);
216
223 {
224 m_b = b;
225 }
226
233 {
234 m_bx = bx;
235 }
236
243 inline void setMeasurementMeanFunction(const vpMeanFunction &meanFunc)
244 {
245 m_measMeanFunc = meanFunc;
246 }
247
254 inline void setMeasurementResidualFunction(const vpAddSubFunction &measResFunc)
255 {
256 m_measResFunc = measResFunc;
257 }
258
265 inline void setStateAddFunction(const vpAddSubFunction &stateAddFunc)
266 {
267 m_stateAddFunction = stateAddFunc;
268 }
269
276 inline void setStateMeanFunction(const vpMeanFunction &meanFunc)
277 {
278 m_stateMeanFunc = meanFunc;
279 }
280
287 inline void setStateResidualFunction(const vpAddSubFunction &stateResFunc)
288 {
289 m_stateResFunc = stateResFunc;
290 }
291
297 inline void setProcessCovariance(const vpMatrix &Q)
298 {
299 m_Q = Q;
300 }
301
307 inline void setMeasurementCovariance(const vpMatrix &R)
308 {
309 m_R = R;
310 }
311
322 void filter(const vpColVector &z, const double &dt, const vpColVector &u = vpColVector());
323
333 void predict(const double &dt, const vpColVector &u = vpColVector());
334
340 void update(const vpColVector &z);
341
347 inline vpMatrix getPest() const
348 {
349 return m_Pest;
350 }
351
357 inline vpMatrix getPpred() const
358 {
359 return m_Ppred;
360 }
361
367 inline vpColVector getXest() const
368 {
369 return m_Xest;
370 }
371
377 inline vpColVector getXpred() const
378 {
379 return m_mu;
380 }
381
389 inline static vpColVector simpleAdd(const vpColVector &a, const vpColVector &toAdd)
390 {
391 vpColVector res = a + toAdd;
392 return res;
393 }
394
402 inline static vpColVector simpleResidual(const vpColVector &a, const vpColVector &toSubtract)
403 {
404 vpColVector res = a - toSubtract;
405 return res;
406 }
407
415 inline static vpColVector simpleMean(const std::vector<vpColVector> &vals, const std::vector<double> &wm)
416 {
417 size_t nbPoints = vals.size();
418 if (nbPoints == 0) {
419 throw(vpException(vpException::dimensionError, "No points to add when computing the mean"));
420 }
421 vpColVector mean = vals[0] * wm[0];
422 for (size_t i = 1; i < nbPoints; ++i) {
423 mean += vals[i] * wm[i];
424 }
425 return mean;
426 }
427private:
428 bool m_hasUpdateBeenCalled;
429 vpColVector m_Xest;
430 vpMatrix m_Pest;
431 vpMatrix m_Q;
432 std::vector<vpColVector> m_chi;
433 std::vector<double> m_wm;
434 std::vector<double> m_wc;
435 std::vector<vpColVector> m_Y;
436 vpColVector m_mu;
437 vpMatrix m_Ppred;
438 vpMatrix m_R;
439 std::vector<vpColVector> m_Z;
440 vpColVector m_muz;
441 vpMatrix m_Pz;
442 vpMatrix m_Pxz;
443 vpColVector m_y;
444 vpMatrix m_K;
445 vpProcessFunction m_f;
446 vpMeasurementFunction m_h;
447 std::shared_ptr<vpUKSigmaDrawerAbstract> m_sigmaDrawer;
448 vpCommandOnlyFunction m_b;
449 vpCommandStateFunction m_bx;
450 vpMeanFunction m_measMeanFunc;
451 vpAddSubFunction m_measResFunc;
452 vpAddSubFunction m_stateAddFunction;
453 vpMeanFunction m_stateMeanFunc;
454 vpAddSubFunction m_stateResFunc;
455
460 typedef struct vpUnscentedTransformResult
461 {
462 vpColVector m_mu;
463 vpMatrix m_P;
464 } vpUnscentedTransformResult;
465
475 static vpUnscentedTransformResult unscentedTransform(const std::vector<vpColVector> &sigmaPoints, const std::vector<double> &wm,
476 const std::vector<double> &wc, const vpMatrix &cov, const vpAddSubFunction &resFunc, const vpMeanFunction &meanFunc);
477};
478END_VISP_NAMESPACE
479#endif
480#endif
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ dimensionError
Bad dimension.
Definition vpException.h:71
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void setMeasurementResidualFunction(const vpAddSubFunction &measResFunc)
Set the measurement residual function to use when computing a subtraction in the measurement space.
void setMeasurementMeanFunction(const vpMeanFunction &meanFunc)
Set the measurement mean function to use when computing a mean in the measurement space.
std::function< vpColVector(const std::vector< vpColVector > &, const std::vector< double > &)> vpMeanFunction
Mean function, which computes the weighted mean of either the prior or the prior expressed in the mea...
vpUnscentedKalman(const vpMatrix &Q, const vpMatrix &R, std::shared_ptr< vpUKSigmaDrawerAbstract > &drawer, const vpProcessFunction &f, const vpMeasurementFunction &h)
Construct a new vpUnscentedKalman object.
static vpColVector simpleAdd(const vpColVector &a, const vpColVector &toAdd)
Simple function to compute an addition, which just does .
vpMatrix getPest() const
Get the estimated (i.e. filtered) covariance of the state.
static vpColVector simpleResidual(const vpColVector &a, const vpColVector &toSubtract)
Simple function to compute a residual, which just does .
void setMeasurementCovariance(const vpMatrix &R)
Permit to change the covariance introduced at each update step.
static vpColVector simpleMean(const std::vector< vpColVector > &vals, const std::vector< double > &wm)
Simple function to compute a mean, which just does .
std::function< vpColVector(const vpColVector &, const vpColVector &)> vpAddSubFunction
Function that computes either the equivalent of an addition or the equivalent of a subtraction in the...
std::function< vpColVector(const vpColVector &, const vpColVector &, const double &)> vpCommandStateFunction
Command model function, which projects effect of the command on the state, when the effect of the com...
vpColVector getXpred() const
Get the predicted state (i.e. the prior).
vpColVector getXest() const
Get the estimated (i.e. filtered) state.
void setStateMeanFunction(const vpMeanFunction &meanFunc)
Set the state mean function to use when computing a mean in the state space.
vpMatrix getPpred() const
Get the predicted covariance of the state, i.e. the covariance of the prior.
void setCommandStateFunction(const vpCommandStateFunction &bx)
Set the command function to use when computing the prior.
std::function< vpColVector(const vpColVector &)> vpMeasurementFunction
Measurement function, which converts the prior points in the measurement space. The argument is a poi...
void setProcessCovariance(const vpMatrix &Q)
Permit to change the covariance introduced at each prediction step.
std::function< vpColVector(const vpColVector &, const double &)> vpCommandOnlyFunction
Command model function, which projects effect of the command on the state. The first argument is the ...
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 setCommandOnlyFunction(const vpCommandOnlyFunction &b)
Set the command function to use when computing the prior.
void init(const vpColVector &mu0, const vpMatrix &P0)
Set the guess of the initial state and covariance.
void setStateResidualFunction(const vpAddSubFunction &stateResFunc)
Set the state residual function to use when computing a subtraction in the state space.
void setStateAddFunction(const vpAddSubFunction &stateAddFunc)
Set the state addition function to use when computing a addition in the state space.