system.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, 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_SYSTEM_H
30 #define HECTOR_POSE_ESTIMATION_SYSTEM_H
31 
37 
38 #include <ros/console.h>
39 
40 namespace hector_pose_estimation {
41 
42 template <class ConcreteModel> class System_;
43 
44 class System
45 {
46 public:
47  System(const std::string& name);
48  virtual ~System();
49 
50  template <class ConcreteModel> static boost::shared_ptr<System_<ConcreteModel> > create(ConcreteModel *model, const std::string& name = "system");
51 
52  virtual const std::string& getName() const { return name_; }
53  virtual void setName(const std::string& name) { name_ = name; }
54 
55  virtual SystemModel *getModel() const { return 0; }
56 
57  virtual Filter *filter() const = 0;
58  virtual Filter::Predictor *predictor() const = 0;
59  virtual void setFilter(Filter *filter) = 0;
60 
61  virtual bool init(PoseEstimation& estimator, State& state);
62  virtual void cleanup();
63  virtual void reset(State& state);
64 
65  virtual bool active(const State& state);
66  virtual SystemStatus getStatusFlags() const { return status_flags_; }
67 
68  virtual ParameterList& parameters() { return parameters_; }
69  virtual const ParameterList& parameters() const { return parameters_; }
70 
71  virtual void getPrior(State &state) const;
72 
73  virtual bool update(double dt);
74 
75  virtual void updated();
76  virtual bool limitState(State& state);
77 
78 protected:
79  virtual bool updateImpl(double dt) = 0;
80  virtual bool prepareUpdate(State &state, double dt) { return getModel()->prepareUpdate(state, dt); }
81  virtual void afterUpdate(State &state) { getModel()->afterUpdate(state); }
82 
83 protected:
84  std::string name_;
87 };
88 
89 template <class ConcreteModel>
90 class System_ : public System
91 {
92 public:
93  typedef ConcreteModel Model;
96 
97  System_(const std::string& name = "system")
98  : System(name)
99  , model_(new Model)
100  {
101  parameters_.add(model_->parameters());
102  }
103 
104  System_(Model *model, const std::string& name)
105  : System(name)
106  , model_(model)
107  {
108  parameters_.add(model_->parameters());
109  }
110 
111  virtual ~System_() {}
112 
113  virtual void reset(State& state) {
114  System::reset(state);
115  if (predictor()) predictor()->reset();
116  }
117 
118  virtual Model *getModel() const { return model_.get(); }
119 
120  virtual Filter *filter() const { return predictor_ ? predictor_->base() : 0; }
121  virtual Filter::Predictor_<Model> *predictor() const { return predictor_.get(); }
122  virtual void setFilter(Filter *filter = 0); // implemented in filter/set_filter.h
123 
124 protected:
125  virtual bool updateImpl(double dt);
126 
127 private:
130 };
131 
132 template <class ConcreteModel>
133 boost::shared_ptr<System_<ConcreteModel> > System::create(ConcreteModel *model, const std::string& name)
134 {
135  return boost::make_shared<System_<ConcreteModel> >(model, name);
136 }
137 
138 } // namespace hector_pose_estimation
139 
140 #include "system.inl"
141 
142 #endif // HECTOR_POSE_ESTIMATION_SYSTEM_H
System(const std::string &name)
Definition: system.cpp:34
virtual void setName(const std::string &name)
Definition: system.h:53
virtual Filter::Predictor_< Model > * predictor() const
Definition: system.h:121
virtual bool update(double dt)
Definition: system.cpp:71
virtual void reset(State &state)
Definition: system.cpp:59
virtual void setFilter(Filter *filter)=0
virtual const std::string & getName() const
Definition: system.h:52
static boost::shared_ptr< System_< ConcreteModel > > create(ConcreteModel *model, const std::string &name="system")
Definition: system.h:133
boost::shared_ptr< Filter::Predictor_< Model > > predictor_
Definition: system.h:129
System_(const std::string &name="system")
Definition: system.h:97
System_(Model *model, const std::string &name)
Definition: system.h:104
virtual void reset(State &state)
Definition: system.h:113
ParameterList & add(const std::string &key, T &value, const T &default_value)
Definition: parameters.h:148
virtual Filter * filter() const =0
virtual SystemStatus getStatusFlags() const
Definition: system.h:66
virtual void getPrior(State &state) const
Definition: system.cpp:43
virtual Filter::Predictor * predictor() const =0
virtual bool init(PoseEstimation &estimator, State &state)
Definition: system.cpp:48
virtual ParameterList & parameters()
Definition: system.h:68
traits::Input< ConcreteModel >::Type InputType
Definition: system.h:94
virtual bool active(const State &state)
Definition: system.cpp:65
virtual SystemModel * getModel() const
Definition: system.h:55
traits::Input< ConcreteModel >::Vector InputVector
Definition: system.h:95
unsigned int SystemStatus
Definition: types.h:70
virtual bool prepareUpdate(State &state, double dt)
Definition: system.h:80
boost::shared_ptr< Model > model_
Definition: system.h:128
ParameterList parameters_
Definition: system.h:85
virtual bool prepareUpdate(State &state, double dt)
Definition: system_model.h:52
virtual void afterUpdate(State &state)
Definition: system_model.h:53
virtual void afterUpdate(State &state)
Definition: system.h:81
virtual Model * getModel() const
Definition: system.h:118
SystemStatus status_flags_
Definition: system.h:86
virtual Filter * filter() const
Definition: system.h:120
virtual bool limitState(State &state)
Definition: system.cpp:85
virtual bool updateImpl(double dt)=0
virtual const ParameterList & parameters() const
Definition: system.h:69


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