measurement_update.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_UPDATE_H
00030 #define HECTOR_POSE_ESTIMATION_MEASUREMENT_UPDATE_H
00031 
00032 #include <boost/type_traits/is_base_of.hpp>
00033 
00034 namespace hector_pose_estimation {
00035 
00036 class MeasurementUpdate
00037 {
00038 public:
00039   MeasurementUpdate() {}
00040   virtual ~MeasurementUpdate() {}
00041 
00042   virtual bool hasVariance() const { return false; }
00043 };
00044 
00045 template <class MeasurementModel>
00046 class Update_ : public MeasurementUpdate {
00047 public:
00048   enum { MeasurementDimension = MeasurementModel::MeasurementDimension };
00049   typedef Update_<MeasurementModel> Type;
00050   typedef typename MeasurementModel::MeasurementVector Vector;
00051   typedef typename MeasurementModel::NoiseVariance Variance;
00052 
00053   Update_()
00054     : has_variance_(false)
00055   {
00056     y_.setZero();
00057   }
00058   Update_(Vector const& y)
00059     : has_variance_(false)
00060   {
00061     *this = y;
00062   }
00063   Update_(double y)
00064     : has_variance_(false)
00065   {
00066     *this = y;
00067   }
00068   template <typename OtherDerived> Update_(const Eigen::MatrixBase<OtherDerived>& other)
00069     : y_(other)
00070     , has_variance_(false)
00071   {}
00072   virtual ~Update_() {}
00073 
00074   virtual Vector &operator=(Vector const& y) {  y_ = y; return y_; }
00075   virtual Vector &operator=(double y) { y_(0) = y; return y_; }
00076 
00077   virtual Vector const &getVector() const { return y_; }
00078 
00079   virtual bool hasVariance() const { return has_variance_; }
00080   virtual Variance const &getVariance() const { return R_; }
00081   virtual void setVariance(Variance const& R) { R_ = R; has_variance_ = true; }
00082 
00083 protected:
00084   Vector y_;
00085   Variance R_;
00086   bool has_variance_;
00087 };
00088 
00089 namespace traits {
00090 
00091 template <class ConcreteModel> struct Update { typedef Update_<ConcreteModel> type; };
00092 
00093   template <class ConcreteModel, class Enable = void>
00094   class UpdateInspector {
00095   public:
00096     UpdateInspector(const typename Update<ConcreteModel>::type& update) : update_(update) {}
00097     typename ConcreteModel::MeasurementVector const& getVector(const State&) { return *static_cast<typename ConcreteModel::MeasurementVector *>(0); }
00098     typename ConcreteModel::NoiseVariance const& getVariance(const State&) { return *static_cast<typename ConcreteModel::NoiseVariance *>(0); }
00099   private:
00100     const typename Update<ConcreteModel>::type& update_;
00101   };
00102 
00103   template <class ConcreteModel>
00104   class UpdateInspector<ConcreteModel, typename boost::enable_if<boost::is_base_of<Update_<ConcreteModel>, typename Update<ConcreteModel>::type> >::type >
00105   {
00106   public:
00107     UpdateInspector(const typename Update<ConcreteModel>::type& update) : update_(update) {}
00108     typename ConcreteModel::MeasurementVector const& getVector(const State&) { return update_.getVector(); }
00109     typename ConcreteModel::NoiseVariance const& getVariance(const State&) { return update_.getVariance(); }
00110   private:
00111     const typename Update<ConcreteModel>::type& update_;
00112   };
00113 
00114 } // namespace traits
00115 
00116 } // namespace hector_pose_estimation
00117 
00118 #endif // HECTOR_POSE_ESTIMATION_MEASUREMENT_UPDATE_H


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