00001
00002
00003 #ifndef SLAM_BEARING_ONLY_FEATURE_HPP
00004 #define SLAM_BEARING_ONLY_FEATURE_HPP
00005
00006 #include <vector>
00007 #include <list>
00008
00009 #include "boost/tuple/tuple.hpp"
00010
00011 #include "kernel/jafarMacro.hpp"
00012
00013 #include "jmath/jblas.hpp"
00014 #include "jmath/gaussianVector.hpp"
00015
00016 #include "slam/slamException.hpp"
00017 #include "slam/observation.hpp"
00018 #include "slam/feature.hpp"
00019 #include "slam/featureModel.hpp"
00020
00021 namespace jafar {
00022 namespace slam {
00023
00024
00029 class InitStateMember : public jafar::jmath::WeightedGaussianVector {
00030
00031 public:
00032
00034 double l;
00035
00037 double sprtL;
00038
00039 std::vector<jafar::jmath::GaussianVector> initParams;
00040
00041 jafar::jmath::GaussianVector zPred;
00042
00043 InitStateMember(const jblas::vec& x_, const jblas::sym_mat& P_,
00044 double w_,
00045 std::size_t sizeObs) :
00046 WeightedGaussianVector(x_,P_,w_),
00047 l(0.0),
00048 sprtL(0.0),
00049 initParams(0),
00050 zPred(sizeObs)
00051 {}
00052
00053 InitStateMember(const jblas::vec& x_, const jblas::sym_mat& P_,
00054 double w_,
00055 jafar::jmath::GaussianVector const& param1,
00056 std::size_t sizeObs) :
00057 WeightedGaussianVector(x_,P_,w_),
00058 l(0.0),
00059 sprtL(0.0),
00060 initParams(1),
00061 zPred(sizeObs)
00062 {
00063 initParams[0] = param1;
00064 }
00065
00066
00067 InitStateMember(const jblas::vec& x_, const jblas::sym_mat& P_,
00068 double w_,
00069 jafar::jmath::GaussianVector const& param1,
00070 jafar::jmath::GaussianVector const& param2,
00071 std::size_t sizeObs) :
00072 WeightedGaussianVector(x_,P_,w_),
00073 l(0.0),
00074 sprtL(0.0),
00075 initParams(2),
00076 zPred(sizeObs)
00077 {
00078 initParams[0] = param1;
00079 initParams[1] = param2;
00080 }
00081
00082 };
00083
00084 std::ostream& operator <<(std::ostream& s, const InitStateMember& ism);
00085
00090 class InitFeature {
00091
00092 private:
00093
00094 unsigned int m_id;
00095 unsigned int m_robotId;
00096 public:
00097
00098 BaseFeature::FrameIndexesType frameIndexes;
00099
00100 typedef std::map<unsigned int, Observation*> InitObsType;
00101 InitObsType initObs;
00102
00103 jblas::vec previousInitPose;
00104 jblas::vec deltaPose;
00105 jblas::sym_mat deltaPoseCov;
00106
00108 typedef std::list<InitStateMember*> InitStateType;
00109 InitStateType initState;
00110
00111 double baselineMax;
00112
00113 InitFeature(unsigned int id, unsigned int robotId, std::size_t sizeRobotPose);
00114 virtual ~InitFeature();
00115
00116 unsigned int id() const {return m_id;}
00117 unsigned int robotId() const {return m_robotId;}
00118
00119 unsigned int getRefFrameIndex() const;
00120 Observation const& getRefObservation() const;
00121
00122 void addInitObservation(unsigned int frameIndex,
00123 jblas::vec_range const& refPose,
00124 Observation* obs);
00125 void removeInitObservation(unsigned int frameIndex);
00126 bool hasInitObservation(unsigned int frameIndex) const;
00127
00128 InitStateMember const& getBestInitStateMember() const;
00129
00130 void clearInit();
00131
00132 void clearInitStateZPred();
00133
00134 void normalizeInitState();
00135
00136 protected:
00137
00138 virtual void writeLogHeader(jafar::kernel::DataLogger& log) const;
00139 virtual void writeLogData(jafar::kernel::DataLogger& log) const;
00140
00141 };
00142
00143 std::ostream& operator <<(std::ostream& s, const InitFeature& f_);
00144
00145
00150 class BearingOnlyFeatureObserveModel : public BaseFeatureObserveModel {
00151
00152 protected:
00153
00155 double m_doUpdateTh;
00156
00158 double m_eraseHypothesisTh;
00159
00161 static double kSigmaToBeta(double alpha, double kSigma);
00162
00163 static void basicUniformGaussianSum(double min, double max,
00164 double sigma, double kSigma,
00165 std::list<jafar::jmath::GaussianVector>& gaussianSum);
00166
00167 static void geometricUniformGaussianSum(double alpha, double beta,
00168 double sMin, double sMax,
00169 std::list<jafar::jmath::WeightedGaussianVector>& gaussianSum);
00170
00174 void boPointsGeometricGaussianSum(jblas::vec const& d_, jblas::sym_mat const& dCov_,
00175 double alpha_, double beta_,
00176 double sMin_, double sMax_,
00177 InitFeature::InitStateType& gaussianSum);
00178
00179 public:
00180
00181 BearingOnlyFeatureObserveModel(FeatureModel& model, std::size_t sizeObs_);
00182 ~BearingOnlyFeatureObserveModel();
00183
00184 void setup(double doUpdateTh = 8, double eraseHypothesisTh = 20) {
00185 m_doUpdateTh = doUpdateTh;
00186 m_eraseHypothesisTh = eraseHypothesisTh;
00187 }
00188
00189 double eraseHypothesisTh() const {return m_eraseHypothesisTh;}
00190
00195 void initState(InitFeature& feature_,
00196 Observation const& obs_,
00197 double dMin_, double dMax_);
00198
00199 virtual void initStateInSensorFrame(InitFeature& feature_,
00200 Observation const& obs_,
00201 double dMin_, double dMax_) = 0;
00202
00203 bool doUpdateInitState(jblas::vec const& closestMemberState, jblas::vec const& deltaPose);
00204
00205 };
00206
00212 class InfFeatureObserveModel : public FeatureObserveModel {
00213
00214 public:
00215
00216 InfFeatureObserveModel(FeatureModel& model, std::size_t sizeObs_);
00217
00218 virtual ~InfFeatureObserveModel() {}
00219
00220 void setBaselineTh(double baselineTh) {m_baselineTh = baselineTh;}
00221 double getBaselineTh() const {return m_baselineTh;}
00222
00226 double computeBaseline(jblas::vec const& poseRef, Observation const& obsRef,
00227 jblas::vec_range const& poseCur) const;
00228
00229 private:
00230
00231 double m_baselineTh;
00232
00233 protected:
00234
00238 virtual double computeBaselineInSensorFrame(jblas::vec_range const& deltaPose,
00239 Observation const& obsRef) const = 0;
00240
00241 };
00242
00243 }
00244 }
00245
00246 #endif // SLAM_BEARING_ONLY_FEATURE_HPP