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 bool init(PoseEstimation& estimator, Measurement &measurement, State& state) { return true; }
00043   virtual int getDimension() const = 0;
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> class MeasurementModel_;
00053 
00054 namespace traits {
00055 
00056   template <class Derived, int _Dimension = Derived::MeasurementDimension>
00057   struct MeasurementModel {
00058     enum { MeasurementDimension = _Dimension };
00059     typedef ColumnVector_<MeasurementDimension> MeasurementVector;
00060     typedef SymmetricMatrix_<MeasurementDimension> NoiseVariance;
00061     typedef Matrix_<MeasurementDimension,Dynamic> MeasurementMatrix;
00062     typedef Matrix_<State::Covariance::RowsAtCompileTime,MeasurementDimension> GainMatrix;
00063     typedef ColumnVector_<State::Covariance::RowsAtCompileTime> UpdateVector;
00064 
00065     enum { InputDimension = traits::Input<Derived>::Dimension };
00066     typedef typename traits::Input<Derived>::Type InputType;
00067     typedef typename traits::Input<Derived>::Vector InputVector;
00068     typedef Matrix_<MeasurementDimension,InputDimension> InputMatrix;
00069   };
00070 
00071   #define MEASUREMENT_MODEL_TRAIT(Derived, _Dimension) \
00072     typedef typename traits::MeasurementModel<Derived, _Dimension> trait; \
00073     \
00074     enum { MeasurementDimension = _Dimension }; \
00075     typedef typename trait::MeasurementVector MeasurementVector; \
00076     typedef typename trait::NoiseVariance NoiseVariance; \
00077     typedef typename trait::MeasurementMatrix MeasurementMatrix; \
00078     typedef typename trait::GainMatrix GainMatrix; \
00079     typedef typename trait::UpdateVector UpdateVector; \
00080     \
00081     enum { InputDimension = trait::InputDimension }; \
00082     typedef typename trait::InputType InputType; \
00083     typedef typename trait::InputVector InputVector; \
00084     typedef typename trait::InputMatrix InputMatrix; \
00085 
00086 } // namespace traits
00087 
00088 template <class Derived, int _Dimension>
00089 class MeasurementModel_ : public MeasurementModel {
00090 public:
00091   MEASUREMENT_MODEL_TRAIT(Derived, _Dimension)
00092   virtual ~MeasurementModel_() {}
00093 
00094   virtual int getDimension() const { return trait::MeasurementDimension; }
00095 
00096   Derived *derived() { return static_cast<Derived *>(this); }
00097   const Derived *derived() const { return static_cast<const Derived *>(this); }
00098 
00099   virtual void getExpectedValue(MeasurementVector& y_pred, const State& state);
00100   virtual void getStateJacobian(MeasurementMatrix& C, const State& state, bool init = true);
00101   virtual void getInputJacobian(InputMatrix& D, const State& state, bool init = true);
00102   virtual void getMeasurementNoise(NoiseVariance& R, const State& state, bool init = true);
00103 
00104   virtual void limitError(MeasurementVector& error) {}
00105 
00106   virtual const MeasurementVector* getFixedMeasurementVector() const { return 0; }
00107 };
00108 
00109 template <class Derived, int _Dimension>
00110 void MeasurementModel_<Derived, _Dimension>::getExpectedValue(MeasurementVector& y_pred, const State& state)
00111 {
00112   y_pred.setZero();
00113 }
00114 
00115 template <class Derived, int _Dimension>
00116 void MeasurementModel_<Derived, _Dimension>::getStateJacobian(MeasurementMatrix& C, const State& state, bool init)
00117 {
00118   if (init) C.setZero();
00119 }
00120 
00121 template <class Derived, int _Dimension>
00122 void MeasurementModel_<Derived, _Dimension>::getInputJacobian(InputMatrix& D, const State& state, bool init)
00123 {
00124   if (init) D.setZero();
00125 }
00126 
00127 template <class Derived, int _Dimension>
00128 void MeasurementModel_<Derived, _Dimension>::getMeasurementNoise(NoiseVariance& R, const State& state, bool init)
00129 {
00130   if (init) R.setZero();
00131 }
00132 
00133 } // namespace hector_pose_estimation
00134 
00135 #endif // HECTOR_POSE_ESTIMATION_MEASUREMENT_MODEL_H


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