measurement_model.h
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2011, Johannes Meyer and Martin Nowara, 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_MODEL_H
00030 #define HECTOR_POSE_ESTIMATION_MEASUREMENT_MODEL_H
00031 
00032 #include <hector_pose_estimation/model.h>
00033 #include <hector_pose_estimation/substate.h>
00034 #include <hector_pose_estimation/input.h>
00035 
00036 namespace hector_pose_estimation {
00037 
00038 class MeasurementModel : public Model {
00039 public:
00040   virtual ~MeasurementModel() {}
00041 
00042   virtual int getDimension() const = 0;
00043   virtual bool hasSubsystem() const { return false; }
00044 
00045   virtual SystemStatus getStatusFlags() { return SystemStatus(0); }
00046   virtual bool active(const State& state) { return !(state.getSystemStatus() & STATUS_ALIGNMENT); }
00047 
00048   virtual bool prepareUpdate(State& state, const MeasurementUpdate& update) { return true; }
00049   virtual void afterUpdate(State& state) {}
00050 };
00051 
00052 template <class Derived, int _Dimension, int _SubDimension = 0> class MeasurementModel_;
00053 
00054 namespace traits {
00055 
00056   template <int _Dimension, int _SubDimension>
00057   struct MeasurementModel {
00058     enum { StateDimension = State::Dimension };
00059     typedef typename State::Vector StateVector;
00060 //    typedef SymmetricMatrix_<StateDimension> StateVariance;
00061     typedef typename State::VectorSegment StateVectorSegment;
00062     typedef typename State::CovarianceBlock StateCovarianceBlock;
00063     typedef typename State::ConstVectorSegment ConstStateVectorSegment;
00064     typedef typename State::ConstCovarianceBlock ConstStateCovarianceBlock;
00065 
00066     enum { MeasurementDimension = _Dimension };
00067     typedef ColumnVector_<MeasurementDimension> MeasurementVector;
00068     typedef SymmetricMatrix_<MeasurementDimension> NoiseVariance;
00069     typedef Matrix_<MeasurementDimension,StateDimension> MeasurementMatrix;
00070     typedef Matrix_<State::Covariance::RowsAtCompileTime,MeasurementDimension> GainMatrix;
00071 
00072     enum { SubDimension = _SubDimension };
00073     struct HasSubSystem : public boost::integral_constant<bool, (_SubDimension > 0)> {};
00074     typedef SubState_<SubDimension> SubState;
00075     typedef typename SubState::Ptr SubStatePtr;
00076     typedef typename SubState::Vector SubStateVector;
00077     // typedef SymmetricMatrix_<SubDimension> SubStateVariance;
00078     typedef typename SubState::VectorSegment SubStateVectorSegment;
00079     typedef typename SubState::CovarianceBlock SubStateCovarianceBlock;
00080     typedef typename SubState::ConstVectorSegment ConstSubStateVectorSegment;
00081     typedef typename SubState::ConstCovarianceBlock ConstSubStateCovarianceBlock;
00082     typedef Matrix_<MeasurementDimension,SubDimension> SubMeasurementMatrix;
00083   };
00084 
00085   #define MEASUREMENT_MODEL_TRAIT(_Dimension, _SubDimension) \
00086     typedef typename traits::MeasurementModel<_Dimension, _SubDimension> trait; \
00087     \
00088     enum { StateDimension = trait::StateDimension }; \
00089     typedef typename trait::StateVector StateVector; \
00090     typedef typename trait::StateVectorSegment StateVectorSegment; \
00091     typedef typename trait::StateCovarianceBlock StateCovarianceBlock; \
00092     \
00093     enum { MeasurementDimension = _Dimension }; \
00094     typedef typename trait::MeasurementVector MeasurementVector; \
00095     typedef typename trait::NoiseVariance NoiseVariance; \
00096     typedef typename trait::MeasurementMatrix MeasurementMatrix; \
00097     typedef typename trait::GainMatrix GainMatrix; \
00098     \
00099     enum { InputDimension = traits::Input<Derived>::Dimension }; \
00100     typedef typename traits::Input<Derived>::Type InputType; \
00101     typedef typename traits::Input<Derived>::Vector InputVector; \
00102     typedef Matrix_<MeasurementDimension,InputDimension> InputMatrix; \
00103     \
00104     typedef typename trait::HasSubSystem HasSubSystem; \
00105     enum { SubDimension = _SubDimension }; \
00106     typedef typename trait::SubState SubState; \
00107     typedef typename trait::SubStatePtr SubStatePtr; \
00108     typedef typename trait::SubStateVector SubStateVector; \
00109     typedef typename trait::SubStateVectorSegment SubStateVectorSegment; \
00110     typedef typename trait::SubStateCovarianceBlock SubStateCovarianceBlock; \
00111     typedef typename trait::ConstSubStateVectorSegment ConstSubStateVectorSegment; \
00112     typedef typename trait::ConstSubStateCovarianceBlock ConstSubStateCovarianceBlock; \
00113     typedef typename trait::SubMeasurementMatrix SubMeasurementMatrix; \
00114 
00115 } // namespace traits
00116 
00117 template <class Derived, int _Dimension, int _SubDimension>
00118 class MeasurementModel_ : public MeasurementModel {
00119 public:
00120   MEASUREMENT_MODEL_TRAIT(_Dimension, _SubDimension)
00121   virtual ~MeasurementModel_() {}
00122 
00123   virtual int getDimension() const { return trait::MeasurementDimension; }
00124   virtual bool hasSubSystem() const { return trait::HasSubSystem::value; }
00125 
00126   Derived *derived() { return static_cast<Derived *>(this); }
00127   const Derived *derived() const { return static_cast<const Derived *>(this); }
00128 
00129   SubState& sub(State& state) const { return *state.getSubState<SubDimension>(this); }
00130   const SubState& sub(const State& state) const { return *state.getSubState<SubDimension>(this); }
00131 
00132   virtual void getExpectedValue(MeasurementVector& y_pred, const State& state) {}
00133   virtual void getStateJacobian(MeasurementMatrix& C, const State& state, bool init) {}
00134   virtual void getInputJacobian(InputMatrix& D, const State& state, bool init) {}
00135   virtual void getMeasurementNoise(NoiseVariance& R, const State& state, bool init) {}
00136 
00137   // variant for MeasurementModels that use a SubSystem
00138   virtual void getStateJacobian(MeasurementMatrix& C0, SubMeasurementMatrix& C1, const State& state, bool init) {}
00139 
00140   virtual void limitError(MeasurementVector& error) {}
00141 
00142   virtual const MeasurementVector* getFixedMeasurementVector() { return 0; }
00143 };
00144 
00145 } // namespace hector_pose_estimation
00146 
00147 #endif // HECTOR_POSE_ESTIMATION_MEASUREMENT_MODEL_H


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