Visual Servoing Platform
version 3.6.1 under development (2024-11-21)
|
#include <visp3/core/vpUnscentedKalman.h>
Public Types | |
typedef std::function< vpColVector(const vpColVector &, const double &)> | vpCommandOnlyFunction |
typedef std::function< vpColVector(const vpColVector &, const vpColVector &, const double &)> | vpCommandStateFunction |
typedef std::function< vpColVector(const std::vector< vpColVector > &, const std::vector< double > &)> | vpMeanFunction |
typedef std::function< vpColVector(const vpColVector &)> | vpMeasurementFunction |
typedef std::function< vpColVector(const vpColVector &, const double &)> | vpProcessFunction |
typedef std::function< vpColVector(const vpColVector &, const vpColVector &)> | vpAddSubFunction |
Static Public Member Functions | |
static vpColVector | simpleAdd (const vpColVector &a, const vpColVector &toAdd) |
static vpColVector | simpleResidual (const vpColVector &a, const vpColVector &toSubtract) |
static vpColVector | simpleMean (const std::vector< vpColVector > &vals, const std::vector< double > &wm) |
This class permits to use Unscented Kalman Filter (UKF) to tackle non-linear problems. Non-linearity can arise in the process function , which makes evolve the internal state of the UKF over time, or in the measurement function , which expresses the internal state of the UKF in the measurement space of dimension .
We will briefly explain the principles of the UKF and the maths behind the wheel. We refer the interested readers to the web-book by R. Labbe, chapter 10, for more details.
The UKF is performed in two steps. First, the prediction step, during which we draw the sigma points and compute their corresponding weights and . Be the internal state of the UKF and the process covariance matrix. We have:
There are different ways of drawing the sigma points and associated weights in the litterature, such as the one proposed by Julier or the one proposed by E. A. Wan and R. van der Merwe.
Be the vector containing the known commands sent to the system, if any. Then, we pass each sigma point through the process function , the command function and the command function depending on the state to project them forward in time, forming the new prior:
Then, we apply the Unscented Transform to compute the mean and covariance of the prior:
where is the covariance of the error introduced by the process function.
The second step is the update step. It is performed in the measurement space, so we must convert the sigma points of the prior into measurements using the measurement function :
Then, we use once again the Unscented Transform to compute the mean and the covariance of these points:
where is the measurement covariance matrix.
Then, we compute the residual of the measurement :
To compute the Kalman's gain, we first need to compute the cross covariance of the state and the measurements:
The Kalman's gain is then defined as:
Finally, we can compute the new state estimate and the new covariance :
Definition at line 134 of file vpUnscentedKalman.h.
typedef std::function<vpColVector(const vpColVector &, const vpColVector &)> vpUnscentedKalman::vpAddSubFunction |
Function that computes either the equivalent of an addition or the equivalent of a subtraction in the state space or in the measurement space. The first argument is the vector to which we must add/subtract something and the second argument is the thing to be added/subtracted. The return is the result of this operation.
Definition at line 183 of file vpUnscentedKalman.h.
typedef std::function<vpColVector(const vpColVector &, const double &)> vpUnscentedKalman::vpCommandOnlyFunction |
Command model function, which projects effect of the command on the state. The first argument is the command(s), the second is the period and the return is the effect of the command on the state after period seconds.
Definition at line 143 of file vpUnscentedKalman.h.
typedef std::function<vpColVector(const vpColVector &, const vpColVector &, const double &)> vpUnscentedKalman::vpCommandStateFunction |
Command model function, which projects effect of the command on the state, when the effect of the command depends on the current state. The first argument is the command(s), the second is the state and the third is the period. The return is the effect of the command on the state after period seconds.
Definition at line 151 of file vpUnscentedKalman.h.
typedef std::function<vpColVector(const std::vector<vpColVector> &, const std::vector<double> &)> vpUnscentedKalman::vpMeanFunction |
Mean function, which computes the weighted mean of either the prior or the prior expressed in the measurement space. The first argument is either the prior or the prior expressed in the measurement space and the second argument is the associated vector of weights. The return is the corresponding mean.
Definition at line 160 of file vpUnscentedKalman.h.
typedef std::function<vpColVector(const vpColVector &)> vpUnscentedKalman::vpMeasurementFunction |
Measurement function, which converts the prior points in the measurement space. The argument is a point of a prior point and the return is its projection in the measurement space.
Definition at line 167 of file vpUnscentedKalman.h.
typedef std::function<vpColVector(const vpColVector &, const double &)> vpUnscentedKalman::vpProcessFunction |
Process model function, which projects the sigma points forward in time. The first argument is a sigma point, the second is the period and the return is the sigma point projected in the future (i.e. a point of the prior).
Definition at line 174 of file vpUnscentedKalman.h.
BEGIN_VISP_NAMESPACE vpUnscentedKalman::vpUnscentedKalman | ( | const vpMatrix & | Q, |
const vpMatrix & | R, | ||
std::shared_ptr< vpUKSigmaDrawerAbstract > & | drawer, | ||
const vpProcessFunction & | f, | ||
const vpMeasurementFunction & | h | ||
) |
Construct a new vpUnscentedKalman object.
[in] | Q | The covariance introduced by performing the prediction step. |
[in] | R | The covariance introduced by performing the update step. |
[in] | drawer | Object that permits to draw the sigma points. |
[in] | f | Process model function, which projects the sigma points forward in time. The first argument is a sigma point, the second is the period and the return is the sigma point projected in the future (i.e. a point of the prior). |
[in] | h | Measurement function, which converts the prior points in the measurement space. The argument is a point of a prior point and the return is its projection in the measurement space. |
Definition at line 43 of file vpUnscentedKalman.cpp.
void vpUnscentedKalman::filter | ( | const vpColVector & | z, |
const double & | dt, | ||
const vpColVector & | u = vpColVector() |
||
) |
Perform first the prediction step and then the filtering step.
[in] | z | The new measurement. |
[in] | dt | The time in the future we must predict. |
[in] | u | The command(s) given to the system, if the impact of the system is known. |
Definition at line 73 of file vpUnscentedKalman.cpp.
|
inline |
Get the estimated (i.e. filtered) covariance of the state.
Definition at line 338 of file vpUnscentedKalman.h.
|
inline |
Get the predicted covariance of the state, i.e. the covariance of the prior.
Definition at line 348 of file vpUnscentedKalman.h.
|
inline |
Get the estimated (i.e. filtered) state.
Definition at line 358 of file vpUnscentedKalman.h.
|
inline |
Get the predicted state (i.e. the prior).
Definition at line 368 of file vpUnscentedKalman.h.
void vpUnscentedKalman::init | ( | const vpColVector & | mu0, |
const vpMatrix & | P0 | ||
) |
Set the guess of the initial state and covariance.
[in] | mu0 | Guess of the initial state. |
[in] | P0 | Guess of the initial covariance. |
Definition at line 59 of file vpUnscentedKalman.cpp.
References vpException::dimensionError, vpArray2D< Type >::getCols(), and vpArray2D< Type >::getRows().
void vpUnscentedKalman::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.
[in] | dt | The time in the future we must predict. |
[in] | u | The command(s) given to the system, if the impact of the system is known. |
Definition at line 79 of file vpUnscentedKalman.cpp.
References vpUKSigmaDrawerAbstract::vpSigmaPointsWeights::m_wc, and vpUKSigmaDrawerAbstract::vpSigmaPointsWeights::m_wm.
Referenced by filter().
|
inline |
Set the command function to use when computing the prior.
b | The command function to use. |
Definition at line 213 of file vpUnscentedKalman.h.
|
inline |
Set the command function to use when computing the prior.
bx | The command function to use. |
Definition at line 223 of file vpUnscentedKalman.h.
|
inline |
Permit to change the covariance introduced at each update step.
[in] | R | The measurement covariance matrix. |
Definition at line 298 of file vpUnscentedKalman.h.
|
inline |
Set the measurement mean function to use when computing a mean in the measurement space.
meanFunc | The mean function to use. |
Definition at line 234 of file vpUnscentedKalman.h.
|
inline |
Set the measurement residual function to use when computing a subtraction in the measurement space.
measResFunc | The residual function to use. |
Definition at line 245 of file vpUnscentedKalman.h.
|
inline |
Permit to change the covariance introduced at each prediction step.
[in] | Q | The process covariance matrix. |
Definition at line 288 of file vpUnscentedKalman.h.
|
inline |
Set the state addition function to use when computing a addition in the state space.
stateAddFunc | The addition function to use. |
Definition at line 256 of file vpUnscentedKalman.h.
|
inline |
Set the state mean function to use when computing a mean in the state space.
meanFunc | The mean function to use. |
Definition at line 267 of file vpUnscentedKalman.h.
|
inline |
Set the state residual function to use when computing a subtraction in the state space.
stateResFunc | The residual function to use. |
Definition at line 278 of file vpUnscentedKalman.h.
|
inlinestatic |
Simple function to compute an addition, which just does .
[in] | a | Vector to which we must add something. |
[in] | toAdd | The something we must add to a . |
Definition at line 380 of file vpUnscentedKalman.h.
|
inlinestatic |
Simple function to compute a mean, which just does .
[in] | vals | Vector containing all the vectors we must compute the mean. |
[in] | wm | The correspond list of weights. |
Definition at line 406 of file vpUnscentedKalman.h.
References vpException::dimensionError, and vpArray2D< Type >::size().
|
inlinestatic |
Simple function to compute a residual, which just does .
[in] | a | Vector to which we must subtract something. |
[in] | toSubtract | The something we must subtract to a . |
Definition at line 393 of file vpUnscentedKalman.h.
void vpUnscentedKalman::update | ( | const vpColVector & | z | ) |
Update the estimate of the state based on a new measurement.
[in] | z | The measurements at the current timestep. |
Definition at line 126 of file vpUnscentedKalman.cpp.
References vpMatrix::inverseByCholesky(), and vpMatrix::transpose().
Referenced by filter().