ekf.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2013, Johannes Meyer, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef HECTOR_POSE_ESTIMATION_FILTER_EKF_H
30 #define HECTOR_POSE_ESTIMATION_FILTER_EKF_H
31 
33 
34 namespace hector_pose_estimation {
35 namespace filter {
36 
37 class EKF : public Filter
38 {
39 public:
40  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 
42  EKF(State &state);
43  virtual ~EKF();
44 
45  virtual std::string getType() const { return "EKF"; }
46 
47  virtual bool init(PoseEstimation &estimator);
48  virtual bool preparePredict(double dt);
49  virtual bool predict(const SystemPtr& system, double dt);
50  virtual bool doPredict(double dt);
51 
52  class Predictor
53  {
54  public:
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56 
57  Predictor(EKF *filter)
58  : filter_(filter)
59  , x_diff(filter->state().getVectorDimension())
60  , A(filter->state().getCovarianceDimension(), filter->state().getCovarianceDimension())
61  , Q(filter->state().getCovarianceDimension(), filter->state().getCovarianceDimension())
62  {
63  x_diff.setZero();
64  A.setZero();
65  Q.setZero();
66  }
67  virtual ~Predictor() {}
68  virtual bool predict(double dt) = 0;
69 
70  protected:
72 
73  public:
77  };
78 
79  template <class ConcreteModel, typename Enabled = void>
80  class Predictor_ : public Filter::template Predictor_<ConcreteModel>, public Predictor
81  {
82  public:
83  typedef ConcreteModel Model;
84  typedef typename Filter::template Predictor_<ConcreteModel> Base;
85  using Filter::template Predictor_<ConcreteModel>::state;
86 
87  Predictor_(EKF *filter, Model *model)
88  : Base(filter, model)
89  , Predictor(filter)
90  {}
91  virtual ~Predictor_() {}
92 
93  virtual bool predict(double dt);
94  };
95 
96  class Corrector
97  {
98  public:
99  Corrector(EKF *filter) : filter_(filter) {}
100  virtual ~Corrector() {}
101 
102  protected:
104  };
105 
106  template <class ConcreteModel, typename Enabled = void>
107  class Corrector_ : public Filter::template Corrector_<ConcreteModel>, public Corrector
108  {
109  public:
110  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
111 
112  typedef ConcreteModel Model;
113  typedef typename Filter::template Corrector_<ConcreteModel> Base;
114  using Filter::template Corrector_<ConcreteModel>::state;
115 
116  Corrector_(EKF *filter, Model *model)
117  : Base(filter, model)
118  , Corrector(filter)
119  , y_pred(model->getDimension())
120  , error(model->getDimension())
121  , C(model->getDimension(), filter->state().getCovarianceDimension())
122  , CP(model->getDimension(), filter->state().getCovarianceDimension())
123  , S(model->getDimension(), model->getDimension())
124  , K(filter->state().getCovarianceDimension(), model->getDimension())
125  , update(filter->state().getCovarianceDimension())
126  {
127  y_pred.setZero();
128  error.setZero();
129  C.setZero();
130  CP.setZero();
131  S.setZero();
132  K.setZero();
133  update.setZero();
134  }
135  virtual ~Corrector_() {}
136 
137  virtual bool correct(const typename ConcreteModel::MeasurementVector& y, const typename ConcreteModel::NoiseVariance& R);
138  virtual typename ConcreteModel::MeasurementVector getResidual() const { return error; }
139 
140  public:
141  typename Model::MeasurementVector y_pred;
142  typename Model::MeasurementVector error;
143  typename Model::MeasurementMatrix C;
145  typename Model::NoiseVariance S;
146  typename Model::GainMatrix K;
147  typename Model::UpdateVector update;
148  };
149 
150 public:
154 };
155 
156 } // namespace filter
157 } // namespace hector_pose_estimation
158 
159 #include "ekf.inl"
160 
161 #endif // HECTOR_POSE_ESTIMATION_FILTER_EKF_H
hector_pose_estimation::filter::EKF::EKF
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EKF(State &state)
Definition: ekf.cpp:41
hector_pose_estimation::filter::EKF::Predictor_::predict
virtual bool predict(double dt)
filter.h
hector_pose_estimation::filter::EKF::preparePredict
virtual bool preparePredict(double dt)
Definition: ekf.cpp:56
boost::shared_ptr
hector_pose_estimation::filter::EKF
Definition: ekf.h:37
hector_pose_estimation::filter::EKF::Corrector_::update
Model::UpdateVector update
Definition: ekf.h:147
hector_pose_estimation::filter::EKF::Predictor::Predictor
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Predictor(EKF *filter)
Definition: ekf.h:57
hector_pose_estimation::State
Definition: state.h:42
hector_pose_estimation::filter::EKF::Predictor_::Predictor_
Predictor_(EKF *filter, Model *model)
Definition: ekf.h:87
hector_pose_estimation::filter::EKF::Predictor::x_diff
State::Vector x_diff
Definition: ekf.h:74
hector_pose_estimation::filter::EKF::Predictor_::~Predictor_
virtual ~Predictor_()
Definition: ekf.h:91
hector_pose_estimation::filter::EKF::Corrector_::K
Model::GainMatrix K
Definition: ekf.h:146
hector_pose_estimation::filter::EKF::Corrector_
Definition: ekf.h:107
hector_pose_estimation::filter::EKF::Corrector_::CP
Matrix_< ConcreteModel::MeasurementDimension, Dynamic >::type CP
Definition: ekf.h:144
hector_pose_estimation::filter::EKF::Q
State::Covariance Q
Definition: ekf.h:153
hector_pose_estimation::filter::EKF::Predictor::Q
State::Covariance Q
Definition: ekf.h:76
hector_pose_estimation::filter::EKF::Corrector::Corrector
Corrector(EKF *filter)
Definition: ekf.h:99
hector_pose_estimation::filter::EKF::Corrector_::getResidual
virtual ConcreteModel::MeasurementVector getResidual() const
Definition: ekf.h:138
hector_pose_estimation::filter::EKF::Corrector_::Model
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef ConcreteModel Model
Definition: ekf.h:112
hector_pose_estimation::filter::EKF::Predictor::A
State::SystemMatrix A
Definition: ekf.h:75
hector_pose_estimation::Filter
Definition: filter.h:39
hector_pose_estimation::filter::EKF::Corrector_::C
Model::MeasurementMatrix C
Definition: ekf.h:143
hector_pose_estimation
Definition: collection.h:39
hector_pose_estimation::filter::EKF::Corrector::~Corrector
virtual ~Corrector()
Definition: ekf.h:100
hector_pose_estimation::filter::EKF::Predictor
Definition: ekf.h:52
hector_pose_estimation::Matrix_
Definition: matrix.h:72
Base
hector_pose_estimation::filter::EKF::Predictor::predict
virtual bool predict(double dt)=0
hector_pose_estimation::Filter::state
virtual const State & state() const
Definition: filter.h:50
hector_pose_estimation::State::Covariance
SymmetricMatrix Covariance
Definition: state.h:45
hector_pose_estimation::filter::EKF::Predictor::~Predictor
virtual ~Predictor()
Definition: ekf.h:67
hector_pose_estimation::filter::EKF::Predictor_::Model
ConcreteModel Model
Definition: ekf.h:83
hector_pose_estimation::filter::EKF::~EKF
virtual ~EKF()
Definition: ekf.cpp:45
hector_pose_estimation::filter::EKF::Corrector_::correct
virtual bool correct(const typename ConcreteModel::MeasurementVector &y, const typename ConcreteModel::NoiseVariance &R)
hector_pose_estimation::filter::EKF::doPredict
virtual bool doPredict(double dt)
Definition: ekf.cpp:74
hector_pose_estimation::filter::EKF::x_diff
State::Vector x_diff
Definition: ekf.h:151
hector_pose_estimation::Model
Definition: model.h:38
hector_pose_estimation::filter::EKF::Corrector_::Corrector_
Corrector_(EKF *filter, Model *model)
Definition: ekf.h:116
hector_pose_estimation::filter::EKF::getType
virtual std::string getType() const
Definition: ekf.h:45
hector_pose_estimation::filter::EKF::Corrector_::S
Model::NoiseVariance S
Definition: ekf.h:145
hector_pose_estimation::filter::EKF::Corrector_::error
Model::MeasurementVector error
Definition: ekf.h:142
hector_pose_estimation::filter::EKF::Predictor::filter_
EKF * filter_
Definition: ekf.h:71
hector_pose_estimation::filter::EKF::Predictor_::Base
Filter::template Predictor_< ConcreteModel > Base
Definition: ekf.h:84
hector_pose_estimation::PoseEstimation
Definition: pose_estimation.h:60
hector_pose_estimation::filter::EKF::Corrector_::y_pred
Model::MeasurementVector y_pred
Definition: ekf.h:141
hector_pose_estimation::State::Vector
ColumnVector Vector
Definition: state.h:44
hector_pose_estimation::State::SystemMatrix
Matrix SystemMatrix
Definition: state.h:46
hector_pose_estimation::filter::EKF::Corrector_::Base
Filter::template Corrector_< ConcreteModel > Base
Definition: ekf.h:113
hector_pose_estimation::filter::EKF::Corrector_::~Corrector_
virtual ~Corrector_()
Definition: ekf.h:135
hector_pose_estimation::filter::EKF::init
virtual bool init(PoseEstimation &estimator)
Definition: ekf.cpp:48
hector_pose_estimation::filter::EKF::Corrector
Definition: ekf.h:96
hector_pose_estimation::filter::EKF::A
State::SystemMatrix A
Definition: ekf.h:152
hector_pose_estimation::filter::EKF::Predictor_
Definition: ekf.h:80
hector_pose_estimation::filter::EKF::predict
virtual bool predict(const SystemPtr &system, double dt)
Definition: ekf.cpp:64
hector_pose_estimation::filter::EKF::Corrector::filter_
EKF * filter_
Definition: ekf.h:103


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Wed Mar 2 2022 00:24:40