00001
00012 #ifndef KALMANFILTER_HPP_
00013 #define KALMANFILTER_HPP_
00014
00015 #include "rtslam/rtSlam.hpp"
00016 #include "jmath/ixaxpy.hpp"
00017 #include "jmath/ublasExtra.hpp"
00018 #include "rtslam/innovation.hpp"
00019
00020 namespace jafar {
00021 namespace rtslam {
00022 using namespace jblas;
00023
00024
00029 class ExtendedKalmanFilterIndirect {
00030 private:
00031 size_t size_;
00032
00033
00034
00035
00036 private:
00037 vec x_;
00038 sym_mat P_;
00039
00040 #if STATS
00041 private:
00042 double sum_innov_;
00043 double max_innov_;
00044 unsigned n_innov_;
00045 bool first_innov_;
00046 #endif
00047
00048 public:
00049
00050 mat K;
00051 mat PJt_tmp;
00052
00053 ExtendedKalmanFilterIndirect(size_t _size);
00054
00055 size_t size(){
00056 return size_;
00057 }
00058 jblas::vec & x() {
00059 return x_;
00060 }
00061 jblas::sym_mat & P() {
00062 return P_;
00063 }
00064 double & x(size_t i) {
00065 return x_(i);
00066 }
00067 double & P(size_t i, size_t j) {
00068 return P_(i, j);
00069 }
00070
00071 #if STATS
00072 double avg_innov() { return sum_innov_ / n_innov_; }
00073 double max_innov() { return max_innov_; }
00074 #endif
00075
00076
00094 void predict(const ind_array & iax, const mat & F_v, const ind_array & iav, const mat & F_u, const sym_mat & U);
00095
00111 void predict(const ind_array & iax, const mat & F_v, const ind_array & iav, const sym_mat & Q);
00112
00123 void initialize(const ind_array & iax, const mat & G_rs, const ind_array & ia_rs, const ind_array & ia_l, const mat & G_y, const sym_mat & R);
00124
00137 void initialize(const ind_array & iax, const mat & G_v, const ind_array & ia_rs, const ind_array & ia_l, const mat & G_y, const sym_mat & R, const mat & G_n, const sym_mat & N);
00138
00147 void reparametrize(const ind_array & iax, const mat & J_l, const ind_array & ia_old, const ind_array & ia_new);
00148
00158 void computeKalmanGain(const ind_array & ia_x, Innovation & inn, const mat & INN_rsl, const ind_array & ia_rsl);
00159
00180 void correct(const ind_array & iax, Innovation & inn, const mat & INN_rsl, const ind_array & ia_rsl, bool correct_P = true);
00181
00182 protected:
00183
00184 vec stackedInnovation_x;
00185 sym_mat stackedInnovation_P;
00186 sym_mat stackedInnovation_iP;
00187
00188 struct StackedCorrection
00189 {
00190 StackedCorrection(Innovation & inn, const mat & INN_rsl, const ind_array & ia_rsl):
00191 inn(inn), INN_rsl(INN_rsl), ia_rsl(ia_rsl)
00192 {
00193
00194 }
00195 Innovation inn;
00196 mat INN_rsl;
00197 ind_array ia_rsl;
00198 };
00199
00200 typedef std::list<StackedCorrection> CorrectionList;
00201
00202 struct CorrectionStack
00203 {
00204 CorrectionList stack;
00205 size_t inn_size;
00206
00207 CorrectionStack() { clear(); }
00208 void clear() { inn_size = 0; stack.clear(); }
00209 };
00210 CorrectionStack corrStack;
00211
00212 public:
00213 void stackCorrection(Innovation & inn, const mat & INN_rsl, const ind_array & ia_rsl);
00214 void correctAllStacked(const ind_array & iax, bool correct_P = true);
00215 void clearStack();
00216
00217 };
00218
00219 }
00220 }
00221
00222 #endif