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:
71  EKF *filter_;
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:
103  EKF *filter_;
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
Filter::template Corrector_< ConcreteModel > Base
Definition: ekf.h:113
Matrix_< ConcreteModel::MeasurementDimension, Dynamic >::type CP
Definition: ekf.h:144
SymmetricMatrix Covariance
Definition: state.h:45
State::SystemMatrix A
Definition: ekf.h:152
virtual bool doPredict(double dt)
Definition: ekf.cpp:74
TFSIMD_FORCE_INLINE const tfScalar & y() const
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef ConcreteModel Model
Definition: ekf.h:112
virtual const State & state() const
Definition: filter.h:50
virtual bool init(PoseEstimation &estimator)
Definition: ekf.cpp:48
virtual bool preparePredict(double dt)
Definition: ekf.cpp:56
virtual bool correct(const Measurements &measurements)
Definition: filter.cpp:105
Filter::template Predictor_< ConcreteModel > Base
Definition: ekf.h:84
virtual std::string getType() const
Definition: ekf.h:45
Model::MeasurementVector y_pred
Definition: ekf.h:141
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EKF(State &state)
Definition: ekf.cpp:41
virtual ConcreteModel::MeasurementVector getResidual() const
Definition: ekf.h:138
Model::MeasurementVector error
Definition: ekf.h:142
Corrector_(EKF *filter, Model *model)
Definition: ekf.h:116
Predictor_(EKF *filter, Model *model)
Definition: ekf.h:87
virtual bool predict(const SystemPtr &system, double dt)
Definition: ekf.cpp:64
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Predictor(EKF *filter)
Definition: ekf.h:57


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Thu Feb 18 2021 03:29:30