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>
70 void clear(
const Eigen::MatrixBase<T1>& x)
79 template <
typename T1>
80 void update(
const Eigen::MatrixBase<T1>& z)
85 template <
typename T1,
typename T2>
86 void update(
const Eigen::MatrixBase<T1>& z,
const Eigen::MatrixBase<T2>& R)
93 K_ = P_new_ * H_.transpose() * ((H_ * P_new_ * H_.transpose() + R_).inverse());
94 x_ = x_ + K_ * (z - H_ * x_);
95 P_ = (I_ - K_ * H_) * P_new_;
98 template <
typename T1>
99 void predict(
const Eigen::MatrixBase<T1>& u)
104 template <
typename T1,
typename T2>
105 void predict(
const Eigen::MatrixBase<T1>& u,
const Eigen::MatrixBase<T2>& Q)
112 x_ = A_ * x_ + B_ * u;
113 P_new_ = A_ * P_ * A_.transpose() + Q_;
123 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:86
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 update(const Eigen::MatrixBase< T1 > &z)
Definition kalman_filter.h:80
void predict(const Eigen::MatrixBase< T1 > &u)
Definition kalman_filter.h:99
DVec< T > getState()
Definition kalman_filter.h:116
void predict(const Eigen::MatrixBase< T1 > &u, const Eigen::MatrixBase< T2 > &Q)
Definition kalman_filter.h:105
void clear(const Eigen::MatrixBase< T1 > &x)
Definition kalman_filter.h:70
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