00001
00002
00003 #ifndef SLAM_FEATURE_MODEL_HPP
00004 #define SLAM_FEATURE_MODEL_HPP
00005
00006 #include <map>
00007
00008 #include "jmath/jblas.hpp"
00009 #include "jmath/gaussianVector.hpp"
00010
00011 #include "geom/t3dEuler.hpp"
00012
00013 #include "filter/observeModel.hpp"
00014
00015 #include "slam/observation.hpp"
00016
00017 namespace jafar {
00018 namespace slam {
00019
00020
00021 class BaseFeature;
00022
00027 class FeatureModel {
00028 std::size_t m_sizeMergeState;
00029 public:
00030
00037 jblas::mat Jx;
00038
00045 jblas::mat Jframe;
00046
00047 FeatureModel(std::size_t sizeRobotPose, std::size_t sizeState, std::size_t sizeMergeState) :
00048 m_sizeMergeState(sizeMergeState),
00049 Jx(sizeState, sizeState),
00050 Jframe(sizeState, sizeRobotPose)
00051 {}
00052
00053 virtual ~FeatureModel() {}
00054
00055 std::size_t sizeState() {return Jx.size1();}
00056 std::size_t sizeRobotPose() {return Jframe.size2();}
00057 std::size_t sizeMergeState() { return m_sizeMergeState; }
00058
00062 virtual void toFrame(const jblas::vec& frame_, const jblas::vec& x, jblas::vec& xRes) = 0;
00063
00066 virtual void toFrameJac(jblas::vec const& frame_, jblas::vec const& x_) = 0;
00067
00071 virtual void fromFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec& xRes) = 0;
00073 virtual void fromFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec_range& xRes) = 0;
00074
00077 virtual void fromFrameJac(const jblas::vec& frame_, const jblas::vec& x_) = 0;
00078
00079
00080
00081
00082
00083
00084 virtual void computeMergeState( const jblas::vec& x_, jblas::vec& mergeX_, jblas::mat& jac ) = 0;
00085 };
00086
00087
00088
00089
00090
00091
00099 class BaseFeatureObserveModel : public jafar::filter::BlockObserveModel {
00100
00101 public:
00102
00103 FeatureModel& featureModel;
00104
00106 BaseFeatureObserveModel(FeatureModel& featureModel, std::size_t sizeObs_);
00107
00109 BaseFeatureObserveModel(FeatureModel& featureModel_, std::size_t sizeObs_, std::size_t sizeObsInit_);
00111 BaseFeatureObserveModel(FeatureModel& featureModel_, std::size_t sizeObs_, std::size_t sizeObsInit_, std::size_t sizeInnovation_, std::size_t sizePrediction);
00112
00113 virtual ~BaseFeatureObserveModel();
00114
00115 std::size_t sizeRobotPose() const {return sizeState1();};
00116 std::size_t sizeState() const {return sizeState2();};
00117
00118 virtual Observation::ObservationType typeObs() const = 0;
00119
00122 jblas::sym_mat RInit;
00123
00124 jafar::geom::T3D const& robotToSensor() const {return *m_robotToSensor;}
00125
00128 void setRobotToSensor(jafar::geom::T3DEuler const& robotToSensor_);
00130 virtual jblas::sym_mat const& getR() const {
00131 if (robotToSensor().hasCov())
00132 return featureR;
00133 else
00134 return R;
00135 }
00136
00137
00139 std::size_t sizeObsInit(){
00140 return p_sizeObsInit;
00141 }
00142
00145 virtual jblas::sym_mat const& getRInit() const {
00146 return RInit;
00147 }
00148
00152 virtual void computeR(Observation const& obs);
00153
00156 virtual void computeRInit(Observation const& obs);
00157
00158
00162 virtual void computeSensorR(Observation const& obs) {}
00163
00164
00166 virtual void computeSensorRInit(Observation const& obs) {
00167 computeSensorR(obs);
00168 RInit = R;
00169 }
00170
00171
00177 virtual jblas::vec const& predictObservation(const jblas::vec_range& robotPose_,
00178 const jblas::vec_range& feature_);
00179
00184 virtual void predictObservationJac(const jblas::vec_range& robotPose_,
00185 const jblas::vec_range& feature_);
00186
00190 virtual void initInternalState(BaseFeature& feature,
00191 jafar::geom::T3DEuler const& robotPose_,
00192 Observation const& obs_) const {}
00193
00197 virtual void updateInternalState(BaseFeature& feature,
00198 jafar::geom::T3DEuler const& robotPose_,
00199 Observation const& obs_) const {}
00200
00203 jafar::jmath::GaussianVector zPred;
00204
00205
00206 protected:
00210 void computePredictObservationJac(const jblas::vec_range& robotPose_,
00211 const jblas::vec_range& feature_, jblas::mat& J1, jblas::mat& J2);
00213 jblas::mat JobsSensor;
00214
00217 jafar::geom::T3D* m_robotToSensor;
00218
00220 jblas::mat JobsRobotToSensor;
00221
00225 jblas::sym_mat featureR;
00226
00228 std::size_t p_sizeObsInit;
00229
00233 virtual jblas::vec const& predictObservationInSensorFrame(jblas::vec const& featureInSensorFrame_) = 0;
00234
00237 virtual void predictObservationInSensorFrameJac(jblas::vec const& featureInSensorFrame_) = 0;
00238
00239 };
00240
00241
00242
00243
00244
00245
00251 class FeatureObserveModel : public BaseFeatureObserveModel {
00252
00253 public:
00254
00260 jblas::mat JinvObs;
00261
00262 FeatureObserveModel(FeatureModel& model, std::size_t sizeObs_);
00263
00264 FeatureObserveModel(FeatureModel& model, std::size_t sizeObs_, std::size_t sizeObsInit_);
00265 FeatureObserveModel(FeatureModel& model, std::size_t sizeObs_, std::size_t sizeObsInit_, std::size_t sizeInnovation_, std::size_t sizePrediction_);
00266
00267 virtual ~FeatureObserveModel();
00268
00272
00273
00274
00275
00276 jblas::vec inverseObservation(Observation const& obs_);
00277
00278 void inverseObservationJac(Observation const& obs_);
00279
00280 virtual void postInitCovariance(jblas::sym_mat_range & P,jblas::mat const& Jfeature) {};
00281
00282
00283 protected:
00284
00285
00286
00287
00288
00289
00290
00291
00294 virtual jblas::vec inverseObservationInSensorFrame(Observation const& obs_) = 0;
00295
00297 virtual void inverseObservationInSensorFrameJac(Observation const& obs_) = 0;
00298
00299 };
00300
00301 }
00302 }
00303
00304
00305 #endif // SLAM_FEATURE_MODEL_HPP