Apollo 10.0
自动驾驶开放平台
apollo::common::math::KalmanFilter< T, XN, ZN, UN > 模板类 参考

Implements a discrete-time Kalman filter. 更多...

#include <kalman_filter.h>

apollo::common::math::KalmanFilter< T, XN, ZN, UN > 的协作图:

Public 成员函数

 KalmanFilter ()
 Constructor which defers initialization until the initial state distribution parameters are set (with SetStateEstimate), typically on the first observation
 
void SetStateEstimate (const Eigen::Matrix< T, XN, 1 > &x, const Eigen::Matrix< T, XN, XN > &P)
 Sets the initial state belief distribution.
 
 KalmanFilter (const Eigen::Matrix< T, XN, 1 > &x, const Eigen::Matrix< T, XN, XN > &P)
 Constructor which fully initializes the Kalman filter
 
virtual ~KalmanFilter ()
 Destructor
 
void SetTransitionMatrix (const Eigen::Matrix< T, XN, XN > &F)
 Changes the system transition function under zero control.
 
void SetTransitionNoise (const Eigen::Matrix< T, XN, XN > &Q)
 Changes the covariance matrix of the transition noise.
 
void SetObservationMatrix (const Eigen::Matrix< T, ZN, XN > &H)
 Changes the observation matrix, which maps states to observations.
 
void SetObservationNoise (const Eigen::Matrix< T, ZN, ZN > &R)
 Changes the covariance matrix of the observation noise.
 
void SetStateCovariance (const Eigen::Matrix< T, XN, XN > &P)
 Changes the covariance matrix of current state belief distribution.
 
void SetControlMatrix (const Eigen::Matrix< T, XN, UN > &B)
 Changes the control matrix in the state transition rule.
 
const Eigen::Matrix< T, XN, XN > & GetTransitionMatrix () const
 Get the system transition function under zero control.
 
const Eigen::Matrix< T, XN, XN > & GetTransitionNoise () const
 Get the covariance matrix of the transition noise.
 
const Eigen::Matrix< T, ZN, XN > & GetObservationMatrix () const
 Get the observation matrix, which maps states to observations.
 
const Eigen::Matrix< T, ZN, ZN > & GetObservationNoise () const
 Get the covariance matrix of the observation noise.
 
const Eigen::Matrix< T, XN, UN > & GetControlMatrix () const
 Get the control matrix in the state transition rule.
 
void Predict (const Eigen::Matrix< T, UN, 1 > &u=Eigen::Matrix< T, UN, 1 >::Zero())
 Updates the state belief distribution given the control input u.
 
void Correct (const Eigen::Matrix< T, ZN, 1 > &z)
 Updates the state belief distribution given an observation z.
 
Eigen::Matrix< T, XN, 1 > GetStateEstimate () const
 Gets mean of our current state belief distribution
 
Eigen::Matrix< T, XN, XN > GetStateCovariance () const
 Gets covariance of our current state belief distribution
 
std::string DebugString () const
 Gets debug string containing detailed information about the filter.
 
bool IsInitialized () const
 Get initialization state of the filter
 

详细描述

template<typename T, unsigned int XN, unsigned int ZN, unsigned int UN>
class apollo::common::math::KalmanFilter< T, XN, ZN, UN >

Implements a discrete-time Kalman filter.

参数
XNdimension of state
ZNdimension of observations
UNdimension of controls

在文件 kalman_filter.h50 行定义.

构造及析构函数说明

◆ KalmanFilter() [1/2]

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
apollo::common::math::KalmanFilter< T, XN, ZN, UN >::KalmanFilter ( )
inline

Constructor which defers initialization until the initial state distribution parameters are set (with SetStateEstimate), typically on the first observation

在文件 kalman_filter.h57 行定义.

57 {
58 F_.setIdentity();
59 Q_.setZero();
60 H_.setIdentity();
61 R_.setZero();
62 B_.setZero();
63
64 x_.setZero();
65 P_.setZero();
66 y_.setZero();
67 S_.setZero();
68 K_.setZero();
69 }

◆ KalmanFilter() [2/2]

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
apollo::common::math::KalmanFilter< T, XN, ZN, UN >::KalmanFilter ( const Eigen::Matrix< T, XN, 1 > &  x,
const Eigen::Matrix< T, XN, XN > &  P 
)
inline

Constructor which fully initializes the Kalman filter

参数
xMean of the state belief distribution
PCovariance of the state belief distribution

在文件 kalman_filter.h89 行定义.

91 : KalmanFilter() {
92 SetStateEstimate(x, P);
93 }
KalmanFilter()
Constructor which defers initialization until the initial state distribution parameters are set (with...
void SetStateEstimate(const Eigen::Matrix< T, XN, 1 > &x, const Eigen::Matrix< T, XN, XN > &P)
Sets the initial state belief distribution.

◆ ~KalmanFilter()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
virtual apollo::common::math::KalmanFilter< T, XN, ZN, UN >::~KalmanFilter ( )
inlinevirtual

Destructor

在文件 kalman_filter.h98 行定义.

98{}

成员函数说明

◆ Correct()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::Correct ( const Eigen::Matrix< T, ZN, 1 > &  z)
inline

Updates the state belief distribution given an observation z.

参数
zObservation

在文件 kalman_filter.h265 行定义.

266 {
267 ACHECK(is_initialized_);
268 y_ = z - H_ * x_;
269
270 S_ = static_cast<Eigen::Matrix<T, ZN, ZN>>(H_ * P_ * H_.transpose() + R_);
271
272 K_ = static_cast<Eigen::Matrix<T, XN, ZN>>(P_ * H_.transpose() *
273 PseudoInverse<T, ZN>(S_));
274
275 x_ = x_ + K_ * y_;
276
277 P_ = static_cast<Eigen::Matrix<T, XN, XN>>(
278 (Eigen::Matrix<T, XN, XN>::Identity() - K_ * H_) * P_);
279}
#define ACHECK(cond)
Definition log.h:80

◆ DebugString()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
std::string apollo::common::math::KalmanFilter< T, XN, ZN, UN >::DebugString ( ) const
inline

Gets debug string containing detailed information about the filter.

返回
Debug string

在文件 kalman_filter.h282 行定义.

282 {
283 Eigen::IOFormat clean_fmt(4, 0, ", ", " ", "[", "]");
284 std::stringstream ss;
285 ss << "F = " << F_.format(clean_fmt) << "\n"
286 << "B = " << B_.format(clean_fmt) << "\n"
287 << "H = " << H_.format(clean_fmt) << "\n"
288 << "Q = " << Q_.format(clean_fmt) << "\n"
289 << "R = " << R_.format(clean_fmt) << "\n"
290 << "x = " << x_.format(clean_fmt) << "\n"
291 << "P = " << P_.format(clean_fmt) << "\n";
292 return ss.str();
293}

◆ GetControlMatrix()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
const Eigen::Matrix< T, XN, UN > & apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetControlMatrix ( ) const
inline

Get the control matrix in the state transition rule.

返回
Control matrix

在文件 kalman_filter.h175 行定义.

175{ return B_; }

◆ GetObservationMatrix()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
const Eigen::Matrix< T, ZN, XN > & apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetObservationMatrix ( ) const
inline

Get the observation matrix, which maps states to observations.

返回
Observation matrix

在文件 kalman_filter.h161 行定义.

161{ return H_; }

◆ GetObservationNoise()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
const Eigen::Matrix< T, ZN, ZN > & apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetObservationNoise ( ) const
inline

Get the covariance matrix of the observation noise.

返回
Covariance matrix

在文件 kalman_filter.h168 行定义.

168{ return R_; }

◆ GetStateCovariance()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
Eigen::Matrix< T, XN, XN > apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetStateCovariance ( ) const
inline

Gets covariance of our current state belief distribution

返回
Covariance matrix

在文件 kalman_filter.h204 行定义.

204{ return P_; }

◆ GetStateEstimate()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
Eigen::Matrix< T, XN, 1 > apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetStateEstimate ( ) const
inline

Gets mean of our current state belief distribution

返回
State vector

在文件 kalman_filter.h197 行定义.

197{ return x_; }

◆ GetTransitionMatrix()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
const Eigen::Matrix< T, XN, XN > & apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetTransitionMatrix ( ) const
inline

Get the system transition function under zero control.

返回
Transition matrix.

在文件 kalman_filter.h147 行定义.

147{ return F_; }

◆ GetTransitionNoise()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
const Eigen::Matrix< T, XN, XN > & apollo::common::math::KalmanFilter< T, XN, ZN, UN >::GetTransitionNoise ( ) const
inline

Get the covariance matrix of the transition noise.

返回
Covariance matrix

在文件 kalman_filter.h154 行定义.

154{ return Q_; }

◆ IsInitialized()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
bool apollo::common::math::KalmanFilter< T, XN, ZN, UN >::IsInitialized ( ) const
inline

Get initialization state of the filter

返回
True if the filter is initialized

在文件 kalman_filter.h217 行定义.

217{ return is_initialized_; }

◆ Predict()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::Predict ( const Eigen::Matrix< T, UN, 1 > &  u = Eigen::Matrix<T, UN, 1>::Zero())
inline

Updates the state belief distribution given the control input u.

参数
uControl input (by default, zero)

在文件 kalman_filter.h255 行定义.

256 {
257 ACHECK(is_initialized_);
258
259 x_ = F_ * x_ + B_ * u;
260
261 P_ = F_ * P_ * F_.transpose() + Q_;
262}

◆ SetControlMatrix()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetControlMatrix ( const Eigen::Matrix< T, XN, UN > &  B)
inline

Changes the control matrix in the state transition rule.

参数
BNew control matrix

在文件 kalman_filter.h140 行定义.

140{ B_ = B; }

◆ SetObservationMatrix()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetObservationMatrix ( const Eigen::Matrix< T, ZN, XN > &  H)
inline

Changes the observation matrix, which maps states to observations.

参数
HNew observation matrix

在文件 kalman_filter.h119 行定义.

119{ H_ = H; }

◆ SetObservationNoise()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetObservationNoise ( const Eigen::Matrix< T, ZN, ZN > &  R)
inline

Changes the covariance matrix of the observation noise.

参数
RNew covariance matrix

在文件 kalman_filter.h126 行定义.

126{ R_ = R; }

◆ SetStateCovariance()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetStateCovariance ( const Eigen::Matrix< T, XN, XN > &  P)
inline

Changes the covariance matrix of current state belief distribution.

参数
PNew state covariance matrix

在文件 kalman_filter.h133 行定义.

133{ P_ = P; }

◆ SetStateEstimate()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetStateEstimate ( const Eigen::Matrix< T, XN, 1 > &  x,
const Eigen::Matrix< T, XN, XN > &  P 
)
inline

Sets the initial state belief distribution.

参数
xMean of the state belief distribution
PCovariance of the state belief distribution

在文件 kalman_filter.h77 行定义.

78 {
79 x_ = x;
80 P_ = P;
81 is_initialized_ = true;
82 }

◆ SetTransitionMatrix()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetTransitionMatrix ( const Eigen::Matrix< T, XN, XN > &  F)
inline

Changes the system transition function under zero control.

参数
FNew transition matrix

在文件 kalman_filter.h105 行定义.

105{ F_ = F; }

◆ SetTransitionNoise()

template<typename T , unsigned int XN, unsigned int ZN, unsigned int UN>
void apollo::common::math::KalmanFilter< T, XN, ZN, UN >::SetTransitionNoise ( const Eigen::Matrix< T, XN, XN > &  Q)
inline

Changes the covariance matrix of the transition noise.

参数
QNew covariance matrix

在文件 kalman_filter.h112 行定义.

112{ Q_ = Q; }

该类的文档由以下文件生成: