class
#include <iDynTree/ExtendedKalmanFilter.h>
DiscreteExtendedKalmanFilterHelper class implementation of discrete EKF with additive Gaussian noise
The derived class must must set the size for states, inputs and outputs using ekfSetStateSize(), ekfSetInputSize() and ekfSetOutputSize() methods. Then the derived class must call ekfInit() to resize the vectors and matrices for the EKF.
Similarly before running the estimator through a loop, it is recommended to set the initial states and variances for measurements, system dynamics and intial states. This is necessary to avoid any NaN values to be propagated.
Once, initialized properly, the filter can be run by
- calling ekfSetInputVector() to set the control inputs and then calling ekfPredict() at each prediction step, and
- calling ekfSetMeasurementVector() to set the measurements and then calling ekfUpdate() at each update step
The internal state of the estimator can be obtained by calling ekfGetStates().
The Discrete Extended Kalman Filter equations implemented in this class are coherent with the ones described in Discrete-time predict and update equations section of this article.
The general workflow implementing/inheriting this class would be in the order,
- call ekfSetInputSize(), ekfSetOutputSize(), ekfSetStateSize() methods
- call ekfInit()
- call ekfSetInitialState(), ekfSetStateCovariance() (either done externally later or internally. usually done externally later, however, filter runs properly only if this step is done)
call ekfSetSystemNoiseCovariance(), ekfSetMeasurementNoiseCovariance()
once this is setup,
- in a loop
- call ekfSetInputVector() then ekfPredict(). Calling ekfGetStates() and ekfGetStateCovariance() at this point will give us the predicted states and its covariance
call ekfSetMeasurementVector() then ekfUpdate(). Calling ekfGetStates() and ekfGetStateCovariance() at this point will give us the updated states and its covariance
Derived classes
- class AttitudeQuaternionEKF
- Quaternion based Discrete Extended Kalman Filter fusing IMU measurements, to give estimates of orientation, angular velocity and gyroscope bias.
Constructors, destructors, conversion operators
Public functions
-
auto ekf_f(const iDynTree::
VectorDynSize& x_k, const iDynTree:: VectorDynSize& u_k, iDynTree:: VectorDynSize& xhat_k_plus_one) -> bool pure virtual - Describes the state propagation for a given dynamical system If state of the system is denoted by and the control input by , then the system dynamics is given as .
-
auto ekf_h(const iDynTree::
VectorDynSize& xhat_k_plus_one, iDynTree:: VectorDynSize& zhat_k_plus_one) -> bool pure virtual - Describes the measurement model of the system, i.e., how the measurements can be described as a function of states, Given a state of the system described by , what would be the measurement observed from this state .
-
auto ekfComputeJacobianF(iDynTree::
VectorDynSize& x, iDynTree:: MatrixDynSize& F) -> bool pure virtual - This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
auto ekfComputeJacobianF(iDynTree::
VectorDynSize& x, iDynTree:: VectorDynSize& u, iDynTree:: MatrixDynSize& F) -> bool pure virtual - Describes the system Jacobian necessary for the propagation of predicted state covariance The analytical Jacobian describing the partial derivative of the system propagation with respect to the state and the system propagation with respect to the input.
-
auto ekfComputeJacobianH(iDynTree::
VectorDynSize& x, iDynTree:: MatrixDynSize& H) -> bool pure virtual - Describes the measurement Jacobian necessary for computing Kalman gain and updating the predicted state and its covariance The analytical Jacobian describing the partial derivative of the measurement model with respect to the state.
- auto ekfPredict() -> bool
- Implements the Discrete EKF prediction equation described by is given by the ekf_
f() method where, is given by the ekfComputejacobianF() method. - auto ekfUpdate() -> bool
- Implements the Discrete EKF update equation described by is given by ekf_
h() method innovation innovation covariance , where is given by ekfComputejacobianH() method Kalman gain Updated covariance Updated state estimate . - auto ekfInit() -> bool
- Initializes and resizes the internal buffers of this filter.
- auto ekfInit(const size_t& state_size, const size_t& input_size, const size_t& output_size) -> bool
- Initializes and resizes the internal buffers of this filter.
- void ekfReset()
- Resets the filter flags The filter flags check if the filter was properly initialized, if the initial state was set, if the initial state covariance was set.
-
auto ekfReset(const size_t& state_size,
const size_t& input_size,
const size_t& output_size,
const iDynTree::
Span<double>& x0, const iDynTree:: Span<double>& P0, const iDynTree:: Span<double>& Q, const iDynTree:: Span<double>& R) -> bool - Resets the filter flags, initializes and resizes internal buffers of the filter, and sets initial state, initial state covariance, and system noise and measurement noise covariance matrices.
-
auto ekfSetMeasurementVector(const iDynTree::
Span<double>& y) -> bool - Set measurement vector at every time step the measurement vector size and output size should match.
-
auto ekfSetInputVector(const iDynTree::
Span<double>& u) -> bool - Set input vector at every time step the input vector size and input size should match.
-
auto ekfSetInitialState(const iDynTree::
Span<double>& x0) -> bool - Set initial state the size of x0 and state size should match.
-
auto ekfSetStateCovariance(const iDynTree::
Span<double>& P) -> bool - Set initial state covariance matrix the size of P and (state size*state size) should match.
-
auto ekfSetSystemNoiseCovariance(const iDynTree::
Span<double>& Q) -> bool - Set system noise covariance matrix the size of Q and (state size*state size) should match.
-
auto ekfSetMeasurementNoiseCovariance(const iDynTree::
Span<double>& R) -> bool - Set measurement noise covariance matrix the size of R and (output size*output size) should match.
- void ekfSetStateSize(size_t dim_X)
- Set the state dimensions.
- void ekfSetInputSize(size_t dim_U)
- Set the input dimensions.
- void ekfSetOutputSize(size_t dim_Y)
- Set the ouptut dimensions.
-
auto ekfGetStates(const iDynTree::
Span<double>& x) const -> bool - Get current internal state of the filter the size of x and state size should match.
-
auto ekfGetStateCovariance(const iDynTree::
Span<double>& P) const -> bool - Get state covariance matrix the size of P and (state size*state size) should match.
Protected functions
-
template<typename T>void ignore(T&&)
- function template to ignore unused parameters
Function documentation
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekf_f(const iDynTree:: VectorDynSize& x_k,
const iDynTree:: VectorDynSize& u_k,
iDynTree:: VectorDynSize& xhat_k_plus_one) pure virtual
Describes the state propagation for a given dynamical system If state of the system is denoted by and the control input by , then the system dynamics is given as .
Parameters | |
---|---|
x_k in | state at current time instant |
u_k in | control input at current time instant |
xhat_k_plus_one out | predicted state without any correction from measurements |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekf_h(const iDynTree:: VectorDynSize& xhat_k_plus_one,
iDynTree:: VectorDynSize& zhat_k_plus_one) pure virtual
Describes the measurement model of the system, i.e., how the measurements can be described as a function of states, Given a state of the system described by , what would be the measurement observed from this state .
Parameters | |
---|---|
xhat_k_plus_one in | predicted state of next time instant |
zhat_k_plus_one out | predicted measurement of next time instant |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfComputeJacobianF(iDynTree:: VectorDynSize& x,
iDynTree:: VectorDynSize& u,
iDynTree:: MatrixDynSize& F) pure virtual
Describes the system Jacobian necessary for the propagation of predicted state covariance The analytical Jacobian describing the partial derivative of the system propagation with respect to the state and the system propagation with respect to the input.
Parameters | |
---|---|
x in | system state |
u in | system input |
F out | system Jacobian |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfComputeJacobianH(iDynTree:: VectorDynSize& x,
iDynTree:: MatrixDynSize& H) pure virtual
Describes the measurement Jacobian necessary for computing Kalman gain and updating the predicted state and its covariance The analytical Jacobian describing the partial derivative of the measurement model with respect to the state.
Parameters | |
---|---|
x in | system state |
H out | measurement Jacobian |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfPredict()
Implements the Discrete EKF prediction equation described by is given by the ekf_
Returns | bool true/false if successful or not |
---|
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfUpdate()
Implements the Discrete EKF update equation described by is given by ekf_
Returns | bool true/false if successful or not |
---|
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfInit()
Initializes and resizes the internal buffers of this filter.
Returns | bool true/false if successful or not |
---|
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfInit(const size_t& state_size,
const size_t& input_size,
const size_t& output_size)
Initializes and resizes the internal buffers of this filter.
Parameters | |
---|---|
state_size in | state size |
input_size in | input size |
output_size in | output size |
Returns | bool true/false if successful or not |
void iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfReset()
Resets the filter flags The filter flags check if the filter was properly initialized, if the initial state was set, if the initial state covariance was set.
These three flags are crucial for proper setting up of the filter. The other flags include the checks on whether the input and measurement vectors were updated at every prediction/update step
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfReset(const size_t& state_size,
const size_t& input_size,
const size_t& output_size,
const iDynTree:: Span<double>& x0,
const iDynTree:: Span<double>& P0,
const iDynTree:: Span<double>& Q,
const iDynTree:: Span<double>& R)
Resets the filter flags, initializes and resizes internal buffers of the filter, and sets initial state, initial state covariance, and system noise and measurement noise covariance matrices.
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetMeasurementVector(const iDynTree:: Span<double>& y)
Set measurement vector at every time step the measurement vector size and output size should match.
Parameters | |
---|---|
y in | iDynTree:: |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetInputVector(const iDynTree:: Span<double>& u)
Set input vector at every time step the input vector size and input size should match.
Parameters | |
---|---|
u in | iDynTree:: |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetInitialState(const iDynTree:: Span<double>& x0)
Set initial state the size of x0 and state size should match.
Parameters | |
---|---|
x0 in | iDynTree:: |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetStateCovariance(const iDynTree:: Span<double>& P)
Set initial state covariance matrix the size of P and (state size*state size) should match.
Parameters | |
---|---|
P in | iDynTree:: |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetSystemNoiseCovariance(const iDynTree:: Span<double>& Q)
Set system noise covariance matrix the size of Q and (state size*state size) should match.
Parameters | |
---|---|
Q in | iDynTree:: |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetMeasurementNoiseCovariance(const iDynTree:: Span<double>& R)
Set measurement noise covariance matrix the size of R and (output size*output size) should match.
Parameters | |
---|---|
R in | iDynTree:: |
Returns | bool true/false if successful or not |
void iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetStateSize(size_t dim_X)
Set the state dimensions.
Parameters | |
---|---|
dim_X in | state size |
Returns | bool true/false if successful or not |
void iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetInputSize(size_t dim_U)
Set the input dimensions.
Parameters | |
---|---|
dim_U in | input size |
Returns | bool true/false if successful or not |
void iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfSetOutputSize(size_t dim_Y)
Set the ouptut dimensions.
Parameters | |
---|---|
dim_Y in | output size |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfGetStates(const iDynTree:: Span<double>& x) const
Get current internal state of the filter the size of x and state size should match.
Parameters | |
---|---|
x out | iDynTree:: |
Returns | bool true/false if successful or not |
bool iDynTree:: DiscreteExtendedKalmanFilterHelper:: ekfGetStateCovariance(const iDynTree:: Span<double>& P) const
Get state covariance matrix the size of P and (state size*state size) should match.
Parameters | |
---|---|
P out | iDynTree:: |
Returns | bool true/false if successful or not |