measurement.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_MEASUREMENT_H
00030 #define HECTOR_POSE_ESTIMATION_MEASUREMENT_H
00031 
00032 #include <hector_pose_estimation/measurement_model.h>
00033 #include <hector_pose_estimation/measurement_update.h>
00034 #include <hector_pose_estimation/types.h>
00035 #include <hector_pose_estimation/queue.h>
00036 #include <hector_pose_estimation/filter.h>
00037 
00038 namespace hector_pose_estimation {
00039 
00040 template <class ConcreteModel> class Measurement_;
00041 
00042 class Measurement
00043 {
00044 public:
00045   Measurement(const std::string& name);
00046   virtual ~Measurement();
00047 
00048   template <class ConcreteModel> static boost::shared_ptr<Measurement_<ConcreteModel> > create(ConcreteModel *model, const std::string& name);
00049 
00050   virtual const std::string& getName() const { return name_; }
00051   void setName(const std::string& name) { name_ = name; }
00052 
00053   virtual MeasurementModel* getModel() const { return 0; }
00054   virtual int getDimension() const { return 0; }
00055 
00056   virtual Filter *filter() const { return filter_; }
00057   virtual void setFilter(Filter *filter) { filter_ = filter; }
00058 
00059   virtual bool init(PoseEstimation& estimator, State& state);
00060   virtual void cleanup();
00061   virtual void reset(State& state);
00062 
00063   virtual ParameterList& parameters() { return parameters_; }
00064   virtual const ParameterList& parameters() const { return parameters_; }
00065 
00066   virtual void add(const MeasurementUpdate &update);
00067   virtual bool process();
00068   virtual bool update(const MeasurementUpdate &update);
00069 
00070   bool enabled() const { return enabled_; }
00071   void enable() { enabled_ = true; }
00072   void disable() { enabled_ = false; status_flags_ = 0; }
00073 
00074   virtual bool active(const State& state);
00075   virtual SystemStatus getStatusFlags() const { return status_flags_; }
00076 
00077   void setTimeout(double timeout) { timeout_ = timeout; }
00078   double getTimeout() const { return timeout_; }
00079 
00080   void setMinInterval(double min_interval) { min_interval_ = min_interval; }
00081   double getMinInterval() const { return min_interval_; }
00082 
00083   void increase_timer(double dt);
00084   bool timedout() const;
00085 
00086 protected:
00087   virtual Queue& queue() = 0;
00088   virtual bool updateImpl(const MeasurementUpdate &update) { return false; }
00089 
00090   virtual bool onInit(PoseEstimation& estimator) { return true; } // currently unsed...
00091   virtual void onReset() { }
00092   virtual void onCleanup() { } // currently unsed...
00093 
00094 protected:
00095   std::string name_;
00096   ParameterList parameters_;
00097   SystemStatus status_flags_;
00098 
00099   bool enabled_;
00100   double min_interval_;
00101 
00102   double timeout_;
00103   double timer_;
00104 
00105   Filter *filter_;
00106 };
00107 
00108 template <class ConcreteModel>
00109 class Measurement_ : public Measurement {
00110 public:
00111   typedef ConcreteModel Model;
00112   typedef typename traits::Update<ConcreteModel>::type Update;
00113 
00114   enum { MeasurementDimension = Model::MeasurementDimension };
00115   typedef typename Model::MeasurementVector MeasurementVector;
00116   typedef typename Model::NoiseVariance NoiseVariance;
00117 
00118   Measurement_(const std::string& name)
00119     : Measurement(name)
00120     , model_(new Model)
00121   {
00122     parameters_.add(model_->parameters());
00123   }
00124 
00125   Measurement_(Model *model, const std::string& name)
00126     : Measurement(name)
00127     , model_(model)
00128   {
00129     parameters_.add(model_->parameters());
00130   }
00131 
00132   virtual ~Measurement_() {
00133   }
00134 
00135   virtual Model* getModel() const { return model_.get(); }
00136   virtual int getDimension() const { return MeasurementDimension; }
00137 
00138   virtual Filter *filter() const { return corrector_ ? corrector_->base() : 0; }
00139   virtual const boost::shared_ptr< Filter::Corrector_<Model> >& corrector() const { return corrector_; }
00140   virtual void setFilter(Filter *filter = 0); // implemented in filter/set_filter.h
00141 
00142   virtual bool init(PoseEstimation& estimator, State& state) {
00143     if (!Measurement::init(estimator, state)) return false;
00144     model_->getMeasurementNoise(R_, state, true);
00145     return true;
00146   }
00147 
00148   virtual void reset(State& state) {
00149     model_->getMeasurementNoise(R_, state, true);
00150     Measurement::reset(state);
00151     if (corrector()) corrector()->reset();
00152   }
00153 
00154   virtual MeasurementVector const& getVector(const Update &update, const State &state) {
00155     const MeasurementVector *fixed = getModel()->getFixedMeasurementVector();
00156     if (fixed) return *fixed;
00157     return traits::UpdateInspector<ConcreteModel>(update).getVector(state);
00158   }
00159 
00160   virtual NoiseVariance const& getVariance(const Update &update, const State &state) {
00161     if (update.hasVariance()) return traits::UpdateInspector<ConcreteModel>(update).getVariance(state);
00162     model_->getMeasurementNoise(R_, state, false);
00163     return R_;
00164   }
00165 
00166   virtual void setNoiseVariance(NoiseVariance const& R) {
00167 //    if (!R_) R_.reset(new NoiseVariance);
00168     R_ = R;
00169   }
00170 
00171 protected:
00172   virtual bool updateImpl(const MeasurementUpdate &update);
00173   virtual bool prepareUpdate(State &state, const Update &update) { return getModel()->prepareUpdate(state, update); }
00174   virtual void afterUpdate(State &state) { getModel()->afterUpdate(state); }
00175 
00176 protected:
00177   boost::shared_ptr<Model> model_;
00178   NoiseVariance R_;
00179 
00180   Queue_<Update> queue_;
00181   virtual Queue& queue() { return queue_; }
00182 
00183   boost::shared_ptr< Filter::Corrector_<Model> > corrector_;
00184 };
00185 
00186 template <class ConcreteModel>
00187 boost::shared_ptr<Measurement_<ConcreteModel> > Measurement::create(ConcreteModel *model, const std::string& name)
00188 {
00189   return boost::make_shared<Measurement_<ConcreteModel> >(model, name);
00190 }
00191 
00192 } // namespace hector_pose_estimation
00193 
00194 #include "measurement.inl"
00195 
00196 #endif // HECTOR_POSE_ESTIMATION_MEASUREMENT_H


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Fri Aug 28 2015 10:59:54