filter.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_H
30 #define HECTOR_POSE_ESTIMATION_FILTER_H
31 
34 
35 #include <map>
36 
37 namespace hector_pose_estimation {
38 
39 class Filter {
40 public:
41  Filter(State &state);
42  virtual ~Filter();
43 
44  virtual std::string getType() const = 0;
45 
46  virtual bool init(PoseEstimation& estimator);
47  virtual void cleanup();
48  virtual void reset();
49 
50  virtual const State& state() const { return state_; }
51  virtual State& state() { return state_; }
52 
53  virtual bool preparePredict(double dt);
54  virtual bool predict(const Systems& systems, double dt);
55  virtual bool predict(const SystemPtr& system, double dt);
56  virtual bool doPredict(double dt);
57 
58  virtual bool prepareCorrect();
59  virtual bool correct(const Measurements& measurements);
60  virtual bool correct(const MeasurementPtr& measurement);
61  virtual bool doCorrect();
62 
63  class Predictor
64  {
65  public:
66  Predictor(Filter *filter) : filter_(filter) {}
67  virtual ~Predictor() {}
68 
69  virtual void reset() { init_ = true; }
70 
71  Filter *base() { return filter_; }
72  const Filter *base() const { return filter_; }
73 
74  State& state() { return filter_->state(); }
75  const State& state() const { return filter_->state(); }
76 
77  protected:
79  bool init_;
80  };
81 
82  template <class ConcreteModel> struct Predictor_ : public Predictor {
83  Predictor_(Filter *filter, ConcreteModel *model) : Predictor(filter), model_(model) { reset(); }
84  virtual ~Predictor_() {}
85 
86  virtual bool predict(double dt) = 0;
87 
88  template <typename Derived> typename Derived::template Predictor_<ConcreteModel> *derived() { return dynamic_cast<typename Derived::template Predictor_<ConcreteModel> *>(this); }
89  template <typename Derived> const typename Derived::template Predictor_<ConcreteModel> *derived() const { return dynamic_cast<const typename Derived::template Predictor_<ConcreteModel> *>(this); }
90 
91  protected:
92  ConcreteModel *model_;
93  };
94 
95  class Corrector
96  {
97  public:
98  Corrector(Filter *filter) : filter_(filter) {}
99  virtual ~Corrector() {}
100 
101  virtual void reset() { init_ = true; }
102 
103  Filter *base() { return filter_; }
104  const Filter *base() const { return filter_; }
105 
106  State& state() { return filter_->state(); }
107  const State& state() const { return filter_->state(); }
108 
109  protected:
111  bool init_;
112  };
113 
114  template <class ConcreteModel> struct Corrector_ : public Corrector {
115  Corrector_(Filter *filter, ConcreteModel *model) : Corrector(filter), model_(model) { reset(); }
116  virtual ~Corrector_() {}
117 
118  virtual bool correct(const typename ConcreteModel::MeasurementVector& y, const typename ConcreteModel::NoiseVariance& R) = 0;
119 
120  virtual typename ConcreteModel::MeasurementVector getResidual() const { return typename ConcreteModel::MeasurementVector(); }
121 
122  template <typename Derived> typename Derived::template Corrector_<ConcreteModel> *derived() { return dynamic_cast<typename Derived::template Corrector_<ConcreteModel> *>(this); }
123  template <typename Derived> const typename Derived::template Corrector_<ConcreteModel> *derived() const { return dynamic_cast<const typename Derived::template Corrector_<ConcreteModel> *>(this); }
124 
125  protected:
126  ConcreteModel *model_;
127  };
128 
129  template <typename Derived> Derived *derived() { return dynamic_cast<Derived *>(this); }
130  template <typename Derived> const Derived *derived() const { return dynamic_cast<const Derived *>(this); }
131 
132  template <typename Derived>
133  struct Factory {
134  Factory(Derived *filter) : filter_(filter) {}
135  template <class ConcreteModel> boost::shared_ptr<Predictor_<ConcreteModel> > addPredictor(ConcreteModel *model) { return boost::static_pointer_cast<Predictor_<ConcreteModel> >(boost::make_shared<typename Derived::template Predictor_<ConcreteModel> >(filter_, model)); }
136  template <class ConcreteModel> boost::shared_ptr<Corrector_<ConcreteModel> > addCorrector(ConcreteModel *model) { return boost::static_pointer_cast<Corrector_<ConcreteModel> >(boost::make_shared<typename Derived::template Corrector_<ConcreteModel> >(filter_, model)); }
137 
138  private:
139  Derived *filter_;
140  };
141  template <typename Derived> static Factory<Derived> factory(Derived *filter) { return Factory<Derived>(filter); }
142 
143 protected:
146 };
147 
148 } // namespace hector_pose_estimation
149 
150 #endif // HECTOR_POSE_ESTIMATION_FILTER_H
boost::shared_ptr< Predictor_< ConcreteModel > > addPredictor(ConcreteModel *model)
Definition: filter.h:135
boost::shared_ptr< Corrector_< ConcreteModel > > addCorrector(ConcreteModel *model)
Definition: filter.h:136
const Derived * derived() const
Definition: filter.h:130
virtual bool preparePredict(double dt)
Definition: filter.cpp:61
TFSIMD_FORCE_INLINE const tfScalar & y() const
static Factory< Derived > factory(Derived *filter)
Definition: filter.h:141
const Filter * base() const
Definition: filter.h:104
virtual bool doPredict(double dt)
Definition: filter.cpp:94
virtual const State & state() const
Definition: filter.h:50
Derived::template Corrector_< ConcreteModel > * derived()
Definition: filter.h:122
const State & state() const
Definition: filter.h:107
virtual bool correct(const Measurements &measurements)
Definition: filter.cpp:105
virtual std::string getType() const =0
const Derived::template Predictor_< ConcreteModel > * derived() const
Definition: filter.h:89
virtual State & state()
Definition: filter.h:51
Derived::template Predictor_< ConcreteModel > * derived()
Definition: filter.h:88
virtual bool predict(const Systems &systems, double dt)
Definition: filter.cpp:66
virtual ConcreteModel::MeasurementVector getResidual() const
Definition: filter.h:120
virtual bool init(PoseEstimation &estimator)
Definition: filter.cpp:47
virtual bool prepareCorrect()
Definition: filter.cpp:100
const Filter * base() const
Definition: filter.h:72
const State & state() const
Definition: filter.h:75
const Derived::template Corrector_< ConcreteModel > * derived() const
Definition: filter.h:123
Corrector_(Filter *filter, ConcreteModel *model)
Definition: filter.h:115
Predictor_(Filter *filter, ConcreteModel *model)
Definition: filter.h:83


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