47 template <
typename TA,
typename TB,
typename TH,
typename TQ,
typename TR>
48 KalmanFilter(
const Eigen::MatrixBase<TA>& A,
const Eigen::MatrixBase<TB>& B,
const Eigen::MatrixBase<TH>& H,
49 const Eigen::MatrixBase<TQ>& Q,
const Eigen::MatrixBase<TR>& R)
50 : A_(A), B_(B), H_(H), Q_(Q), R_(R), m_(TH::RowsAtCompileTime), n_(TA::RowsAtCompileTime), inited(false)
54 static_assert(TA::RowsAtCompileTime == TA::ColsAtCompileTime,
"A should be square matrix");
55 static_assert(TA::RowsAtCompileTime == TH::ColsAtCompileTime,
"H columns should be equal to A columns");
56 static_assert(TB::RowsAtCompileTime == TA::ColsAtCompileTime,
"B rows should be equal to A columns ");
57 static_assert(TQ::RowsAtCompileTime == TA::ColsAtCompileTime && TQ::ColsAtCompileTime == TA::ColsAtCompileTime,
58 "The rows and columns of Q should be equal to the columns of A");
59 static_assert(TR::RowsAtCompileTime == TH::RowsAtCompileTime && TR::ColsAtCompileTime == TH::RowsAtCompileTime,
60 "The rows and columns of Q should be equal to the rows of H");
69 template <
typename T1,
typename T2>
70 void clear(
const Eigen::MatrixBase<T1>& x,
const Eigen::MatrixBase<T2>& P0)
79 template <
typename T1>
80 void clear(
const Eigen::MatrixBase<T1>& x)
89 template <
typename T1>
90 void update(
const Eigen::MatrixBase<T1>& z)
95 template <
typename T1,
typename T2>
96 void update(
const Eigen::MatrixBase<T1>& z,
const Eigen::MatrixBase<T2>& R)
103 K_ = P_new_ * H_.transpose() * ((H_ * P_new_ * H_.transpose() + R_).inverse());
104 x_ = x_ + K_ * (z - H_ * x_);
105 P_ = (I_ - K_ * H_) * P_new_;
108 template <
typename T1>
114 template <
typename T1,
typename T2>
115 void predict(
const Eigen::MatrixBase<T1>& u,
const Eigen::MatrixBase<T2>& Q)
122 x_ = A_ * x_ + B_ * u;
123 P_new_ = A_ * P_ * A_.transpose() + Q_;
133 DMat<T> Q_, R_, P_, P_new_, K_;
Definition kalman_filter.h:45
void update(const Eigen::MatrixBase< T1 > &z, const Eigen::MatrixBase< T2 > &R)
Definition kalman_filter.h:96
KalmanFilter(const Eigen::MatrixBase< TA > &A, const Eigen::MatrixBase< TB > &B, const Eigen::MatrixBase< TH > &H, const Eigen::MatrixBase< TQ > &Q, const Eigen::MatrixBase< TR > &R)
Definition kalman_filter.h:48
void clear(const Eigen::MatrixBase< T1 > &x, const Eigen::MatrixBase< T2 > &P0)
Definition kalman_filter.h:70
void update(const Eigen::MatrixBase< T1 > &z)
Definition kalman_filter.h:90
void predict(const Eigen::MatrixBase< T1 > &u)
Definition kalman_filter.h:109
DVec< T > getState()
Definition kalman_filter.h:126
void predict(const Eigen::MatrixBase< T1 > &u, const Eigen::MatrixBase< T2 > &Q)
Definition kalman_filter.h:115
void clear(const Eigen::MatrixBase< T1 > &x)
Definition kalman_filter.h:80
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition eigen_types.h:146
typename Eigen::Matrix< T, Eigen::Dynamic, 1 > DVec
Definition eigen_types.h:142