00001
00002
00003 #ifndef SLAM_SEGMENT_INV_DEPTH_FEATURE_HPP
00004 #define SLAM_SEGMENT_INV_DEPTH_FEATURE_HPP
00005
00006 #include "jmath/jblas.hpp"
00007
00008 #include "camera/cameraBarreto.hpp"
00009
00010 #include "slam/feature.hpp"
00011 #include "slam/featureModel.hpp"
00012 #include "slam/segmentFeature.hpp"
00013
00014 namespace jafar {
00015 namespace slam {
00016
00017 class SegInvDepthFeatureModel;
00018
00026 class SegmentIDFeature : public BaseFeature {
00027
00028 public:
00029
00030 std::string debugObs;
00031
00033 double s1;
00035 double s2;
00036
00038 bool ENLARGE;
00039
00040 SegmentIDFeature(unsigned int id, FeatureModel& model, std::size_t sizeObs, Observation::ObservationType typeObs_);
00041 virtual ~SegmentIDFeature();
00042
00043 SegInvDepthFeatureModel* segidmodel;
00044
00045 void setFlagEnlarge() {ENLARGE=true;}
00046
00047 virtual void setState(jblas::vec& x_, jblas::sym_mat& P_);
00048
00049 jblas::vec3 getExt1() const;
00050 jblas::sym_mat getExt1Cov() const;
00051 jblas::vec3 getExt2() const;
00052 jblas::sym_mat getExt2Cov() const;
00053 jblas::mat getExt1Jac() const;
00054 jblas::mat getExt2Jac() const;
00055
00056 protected:
00057
00058 virtual void writeLogHeader(jafar::kernel::DataLogger& log) const;
00059 virtual void writeLogData(jafar::kernel::DataLogger& log) const;
00060
00061 private:
00062
00064 void computeExt(double s_, jblas::vec3& ext) const;
00065
00067 void computeExtJac(double s_, jblas::mat& J) const;
00068
00070 void computeExtCov(double s_, jblas::sym_mat& extCov) const;
00071
00072 };
00073
00074
00075 std::ostream& operator <<(std::ostream& s, const jafar::slam::SegmentIDFeature& f);
00076
00084 class SegInvDepthFeatureModel : public FeatureModel {
00085 public:
00086
00087 jblas::mat J3dPoints;
00088
00089 SegInvDepthFeatureModel();
00090 ~SegInvDepthFeatureModel();
00091
00092
00093 void toFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec& xRes);
00094
00095 void toFrameJac(const jblas::vec& frame_, const jblas::vec& x_);
00096
00097 void fromFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec& xRes);
00098 void fromFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec_range& xRes);
00099
00100 void fromFrameJac(const jblas::vec& frame_, const jblas::vec& x_);
00101
00102 void compute3dPoints(jblas::vec const& x, jblas::vec& p, jblas::vec& q);
00103 void compute3dPointsJac(jblas::vec const& x);
00104 void compute3dPointsJac(jblas::vec const& x, jblas::vec& p, jblas::vec& q, jblas::mat& Pt_id);
00105
00106
00107 void computeMergeState( const jblas::vec& x_, jblas::vec& mergeX_ , jblas::mat& jac );
00108
00109 };
00110
00111
00117 class ImageSegInvDepthFeatureObserveModel : public FeatureObserveModel {
00118
00119 protected:
00120
00122 double m_id0;
00124 double m_sigmaId0;
00125
00126 jafar::camera::CameraPinhole camera;
00127
00128 SegInvDepthFeatureModel& segInvDepthFeatureModel;
00129
00130 jblas::vec const& predictObservationInSensorFrame(const jblas::vec& feature_);
00131
00132 void predictObservationInSensorFrameJac(const jblas::vec& feature_);
00133
00134
00135
00136
00137
00138 jblas::vec inverseObservationInSensorFrame(Observation const& obs_);
00139
00140 void inverseObservationInSensorFrameJac(Observation const& obs_);
00141
00143 jblas::sym_mat p_pixCov;
00144
00145 public:
00146
00147 ImageSegInvDepthFeatureObserveModel(SegInvDepthFeatureModel& featureModel_, jafar::camera::CameraPinhole const& camera_);
00148
00149 ~ImageSegInvDepthFeatureObserveModel();
00150
00151 Observation::ObservationType typeObs() const {return Observation::SEGMENTID_IMAGE;}
00152
00153 void setPixCov(jblas::vec const& pixCov_, double stabilizingFactor = 1.0);
00154
00155
00156
00157
00158
00161 void initInternalState(BaseFeature& feature, jafar::geom::T3DEuler const& robotPose_, Observation const& obs_) const;
00162
00165 void updateInternalState(BaseFeature& feature, jafar::geom::T3DEuler const& robotPose_, Observation const& obs_) const;
00166
00167 void postInitCovariance(jblas::sym_mat_range & P, jblas::mat const& Jfeature);
00168
00179 void predictExtObs(jblas::vec_range const& pose, jblas::sym_mat_range const& poseCov,
00180 jblas::vec3 const& ext, jblas::sym_mat const& extCov,
00181 jblas::vec& zPredExt, jblas::sym_mat& zPredExtCov);
00187 void predictExtObsJac(jblas::vec_range const& pose, jblas::vec3 const Ext, jblas::vec& eInImage, jblas::mat& JeR, jblas::mat& JeExt);
00188
00189
00191 virtual jblas::vec const& computeInnovation(jblas::vec const& z_, jblas::vec const& zPred_);
00192
00196 static jblas::vec2 extToImageModel(jblas::vec const& ext1,jblas::vec const& ext2);
00197
00202 static void extToImageModelJac(jblas::vec const& ext1, jblas::vec const& ext2, jblas::mat& J);
00203
00204
00207 virtual void computeSensorR(Observation const& obs);
00208
00210 virtual void computeSensorRInit(Observation const& obs);
00211
00212
00213 void setup(double id0 = 0.5, double sigmaId0 = 0.5);
00214
00215
00216 };
00217
00218 }}
00219
00220 #endif // SLAM_SEG_INV_DEPTH_FEATURE_HPP