system.h
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2011, Johannes Meyer, TU Darmstadt
00003 // All rights reserved.
00004 
00005 // Redistribution and use in source and binary forms, with or without
00006 // modification, are permitted provided that the following conditions are met:
00007 //     * Redistributions of source code must retain the above copyright
00008 //       notice, this list of conditions and the following disclaimer.
00009 //     * Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //     * Neither the name of the Flight Systems and Automatic Control group,
00013 //       TU Darmstadt, nor the names of its contributors may be used to
00014 //       endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //=================================================================================================
00028 
00029 #ifndef HECTOR_POSE_ESTIMATION_SYSTEM_H
00030 #define HECTOR_POSE_ESTIMATION_SYSTEM_H
00031 
00032 #include <hector_pose_estimation/system_model.h>
00033 #include <hector_pose_estimation/types.h>
00034 #include <hector_pose_estimation/state.h>
00035 #include <hector_pose_estimation/input.h>
00036 #include <hector_pose_estimation/filter.h>
00037 
00038 #include <ros/console.h>
00039 
00040 namespace hector_pose_estimation {
00041 
00042 template <class ConcreteModel> class System_;
00043 
00044 class System
00045 {
00046 public:
00047   System(const std::string& name);
00048   virtual ~System();
00049 
00050   template <class ConcreteModel> static boost::shared_ptr<System_<ConcreteModel> > create(ConcreteModel *model, const std::string& name = "system");
00051 
00052   virtual const std::string& getName() const { return name_; }
00053   virtual void setName(const std::string& name) { name_ = name; }
00054 
00055   virtual SystemModel *getModel() const { return 0; }
00056   virtual int getDimension() const = 0;
00057 
00058   virtual Filter *filter() const { return filter_; }
00059   virtual void setFilter(Filter *filter) { filter_ = filter; }
00060 
00061   virtual bool init(PoseEstimation& estimator, State& state);
00062   virtual void cleanup();
00063   virtual void reset(State& state);
00064 
00065   virtual bool active(const State& state);
00066   virtual SystemStatus getStatusFlags() const { return status_flags_; }
00067 
00068   virtual ParameterList& parameters() { return parameters_; }
00069   virtual const ParameterList& parameters() const { return parameters_; }
00070 
00071   virtual void getPrior(State &state) const;
00072 
00073   virtual bool update(double dt);
00074 
00075   virtual void updated();
00076   virtual bool limitState(State& state);
00077 
00078 protected:
00079   virtual bool updateImpl(double dt) = 0;
00080   virtual bool prepareUpdate(State &state, double dt) { return getModel()->prepareUpdate(state, dt); }
00081   virtual void afterUpdate(State &state) { getModel()->afterUpdate(state); }
00082 
00083 protected:
00084   std::string name_;
00085   ParameterList parameters_;
00086   SystemStatus status_flags_;
00087 
00088   Filter *filter_;
00089 };
00090 
00091 template <class ConcreteModel>
00092 class System_ : public System
00093 {
00094 public:
00095   typedef ConcreteModel Model;
00096   typedef typename traits::Input<ConcreteModel>::Type InputType;
00097   typedef typename traits::Input<ConcreteModel>::Vector InputVector;
00098 
00099   System_(const std::string& name = "system")
00100     : System(name)
00101     , model_(new Model)
00102   {
00103     parameters_.add(model_->parameters());
00104   }
00105 
00106   System_(Model *model, const std::string& name)
00107     : System(name)
00108     , model_(model)
00109   {
00110     parameters_.add(model_->parameters());
00111   }
00112 
00113   virtual ~System_() {}
00114 
00115   virtual Model *getModel() const { return model_.get(); }
00116   virtual int getDimension() const { return model_->getDimension(); }
00117 
00118   virtual Filter *filter() const { return predictor_ ? predictor_->base() : 0; }
00119   virtual const boost::shared_ptr< Filter::Predictor_<Model> >& predictor() const { return predictor_; }
00120   virtual void setFilter(Filter *filter = 0); // implemented in filter/set_filter.h
00121 
00122 protected:
00123   virtual bool updateImpl(double dt);
00124 
00125 private:
00126   boost::shared_ptr<Model> model_;
00127   boost::shared_ptr< Filter::Predictor_<Model> > predictor_;
00128 };
00129 
00130 template <class ConcreteModel>
00131 boost::shared_ptr<System_<ConcreteModel> > System::create(ConcreteModel *model, const std::string& name)
00132 {
00133   return boost::make_shared<System_<ConcreteModel> >(model, name);
00134 }
00135 
00136 } // namespace hector_pose_estimation
00137 
00138 #include "system.inl"
00139 
00140 #endif // HECTOR_POSE_ESTIMATION_SYSTEM_H


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Mon Oct 6 2014 00:24:16