RIT VEXU Core API
Loading...
Searching...
No Matches
KalmanFilter< STATES, INPUTS, OUTPUTS > Class Template Reference

#include <kalman_filter.h>

Public Member Functions

 KalmanFilter (LinearSystem< STATES, INPUTS, OUTPUTS > &plant, const StateVector &state_stddevs, const OutputVector &measurement_stddevs)
 
 KalmanFilter (const StateMatrix &A, const InputMatrix &B, const EMat< OUTPUTS, STATES > &C, const EMat< OUTPUTS, INPUTS > &D, const StateVector &state_stddevs, const OutputVector &measurement_stddevs)
 
StateMatrix P () const
 
void set_P (const StateMatrix &P)
 
const StateVector & xhat () const
 
double xhat (int i) const
 
void set_xhat (const StateVector &xhat)
 
void set_xhat (int i, double value)
 
void reset ()
 
void predict (const InputVector &u, const double &dt)
 
void correct (const OutputVector &y, const InputVector &u)
 
void correct (const OutputVector &y, const InputVector &u, const EMat< OUTPUTS, OUTPUTS > &R)
 
template<int ROWS>
void correct (const EVec< ROWS > &y, const InputVector &u, const EMat< ROWS, STATES > &C, const EMat< ROWS, INPUTS > &D, const EMat< ROWS, ROWS > &R)
 

Detailed Description

template<int STATES, int INPUTS, int OUTPUTS>
class KalmanFilter< STATES, INPUTS, OUTPUTS >

Kalman filters combine predictions from a model and measurements to estimate a system's true state.

Each call of predict moves the state forward in time according to the matrix A, and the covariance has white noise Q added.

Each call of correct applies a measurement which moves the state more toward the true state, and it reduces the state covariance.

To read more about Kalman filters read: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

Template Parameters
STATESDimension of the state vector.
INPUTSDimension of the control input vector.
OUTPUTSDimension of the measurement vector.

Constructor & Destructor Documentation

◆ KalmanFilter() [1/2]

template<int STATES, int INPUTS, int OUTPUTS>
KalmanFilter< STATES, INPUTS, OUTPUTS >::KalmanFilter ( LinearSystem< STATES, INPUTS, OUTPUTS > & plant,
const StateVector & state_stddevs,
const OutputVector & measurement_stddevs )
inline

Constructs a Kalman filter.

Parameters
plantThe linear system the filter tracks.
state_stddevsThe standard deviations of the states.
measurement_stddevsThe standard deviations of the measurements.

◆ KalmanFilter() [2/2]

template<int STATES, int INPUTS, int OUTPUTS>
KalmanFilter< STATES, INPUTS, OUTPUTS >::KalmanFilter ( const StateMatrix & A,
const InputMatrix & B,
const EMat< OUTPUTS, STATES > & C,
const EMat< OUTPUTS, INPUTS > & D,
const StateVector & state_stddevs,
const OutputVector & measurement_stddevs )
inline

Constructs a Kalman filter.

Parameters
AThe state matrix.
BThe input matrix.
CThe measurement matrix.
DThe feedthrough matrix.
state_stddevsThe standard deviations of the states.
measurement_stddevsThe standard deviations of the measurements.

Member Function Documentation

◆ correct() [1/3]

template<int STATES, int INPUTS, int OUTPUTS>
template<int ROWS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::correct ( const EVec< ROWS > & y,
const InputVector & u,
const EMat< ROWS, STATES > & C,
const EMat< ROWS, INPUTS > & D,
const EMat< ROWS, ROWS > & R )
inline

Correct the state estimate using the measurements in y, custom measurement and feedthrough matrices, and custom measurement measurement noise. This is useful for when a different set of measurements are being applied than what the plant defines.

Parameters
yThe vector of measurements.
uThe control input used in the last predict step.
CThe measurement matrix to use for this step.
DThe feedthrough matrix to use for this step.
RThe measurement noise matrix to use for this step.

◆ correct() [2/3]

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::correct ( const OutputVector & y,
const InputVector & u )
inline

Correct the state estimate using the measurements in y.

Parameters
yThe vector of measurements.
uThe control input used in the last predict step.

◆ correct() [3/3]

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::correct ( const OutputVector & y,
const InputVector & u,
const EMat< OUTPUTS, OUTPUTS > & R )
inline

Correct the state estimate using the measurements in y, and custom measurement noise matrix. This is useful for when the noise in the measurements vary.

Parameters
yThe vector of measurements.
uThe control input used in the last predict step.
RThe measurement noise matrix to use for this step.

◆ P()

template<int STATES, int INPUTS, int OUTPUTS>
StateMatrix KalmanFilter< STATES, INPUTS, OUTPUTS >::P ( ) const
inline

Returns the covariance matrix P.

◆ predict()

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::predict ( const InputVector & u,
const double & dt )
inline

Projects the state into the future by dt seconds with control input u.

Parameters
uThe control input.
dtThe timestep in seconds.

◆ reset()

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::reset ( )
inline

Resets the filter.

◆ set_P()

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::set_P ( const StateMatrix & P)
inline

Set the current covariance matrix P.

Parameters
PThe covariance matrix P.

◆ set_xhat() [1/2]

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::set_xhat ( const StateVector & xhat)
inline

Set the current state estimate x-hat.

◆ set_xhat() [2/2]

template<int STATES, int INPUTS, int OUTPUTS>
void KalmanFilter< STATES, INPUTS, OUTPUTS >::set_xhat ( int i,
double value )
inline

Set one element of the current state estimate x-hat.

Parameters
iRow of x-hat.

◆ xhat() [1/2]

template<int STATES, int INPUTS, int OUTPUTS>
const StateVector & KalmanFilter< STATES, INPUTS, OUTPUTS >::xhat ( ) const
inline

Returns the current state estimate x-hat.

◆ xhat() [2/2]

template<int STATES, int INPUTS, int OUTPUTS>
double KalmanFilter< STATES, INPUTS, OUTPUTS >::xhat ( int i) const
inline

Returns one element of the current state estimate x-hat.

Parameters
iRow of x-hat.

The documentation for this class was generated from the following file: