00001
00002
00003 #ifndef SLAM_SEGMENT_ANCHOR_PLUCKER_FEATURE_HPP
00004 #define SLAM_SEGMENT_ANCHOR_PLUCKER_FEATURE_HPP
00005
00006 #include "slam/feature.hpp"
00007 #include "slam/featureModel.hpp"
00008 #include "slam/segmentFeature.hpp"
00009
00010 namespace jafar {
00011 namespace slam {
00012
00013 class SegAnchorPluckerFeatureModel;
00014
00022 class SegmentAnchorFeature : public BaseFeature {
00023
00024 public:
00025
00026 std::string debugObs;
00027
00029 double s1;
00031 double s2;
00032
00034 bool ENLARGE;
00035
00036 SegmentAnchorFeature(unsigned int id, FeatureModel& model, std::size_t sizeObs, Observation::ObservationType typeObs_);
00037 virtual ~SegmentAnchorFeature();
00038
00040 SegAnchorPluckerFeatureModel* segapmodel;
00041
00042 jblas::vec_range const& x0() const {return *p_x0;}
00043 jblas::vec_range& x0() {return *p_x0;}
00044 jblas::vec_range const& u() const {return *p_u;}
00045 jblas::vec_range& u() {return *p_u;}
00046 jblas::vec_range const& n() const {return *p_n;}
00047 jblas::vec_range& n() {return *p_n;}
00048
00049
00050 void setFlagEnlarge() {ENLARGE=true;}
00051
00052 virtual void setState(jblas::vec& x_, jblas::sym_mat& P_);
00053
00054 jblas::vec3 getExt1() const;
00055 jblas::sym_mat getExt1Cov() const;
00056 jblas::vec3 getExt2() const;
00057 jblas::sym_mat getExt2Cov() const;
00058 jblas::mat getExt1Jac() const;
00059 jblas::mat getExt2Jac() const;
00060
00061 static void setConstraintAlpha(double alpha) {p_constraintAlpha = alpha;}
00062 static double getConstraintAlpha() {return p_constraintAlpha;}
00063 static void setConstraintMaxNbTimesApplied(int maxNbTimesApplied) {p_constraintMaxNbTimesApplied = maxNbTimesApplied;}
00064 static int getConstraintMaxNbTimesApplied() {return p_constraintMaxNbTimesApplied;}
00065 static void setFlagPlucklerConstraint(bool pluckerConstraint) {ENABLE_PLUCKER_CONSTRAINT=pluckerConstraint;}
00066
00067
00068 protected:
00069
00070 virtual void writeLogHeader(jafar::kernel::DataLogger& log) const;
00071 virtual void writeLogData(jafar::kernel::DataLogger& log) const;
00072
00073 private:
00074
00076 jblas::vec_range* p_x0;
00077
00081 jblas::vec_range* p_n;
00082
00084 jblas::vec_range* p_u;
00085
00086
00088 void computeExt(double s_, jblas::vec3& ext) const;
00089
00091 void computeExtJac(double s_, jblas::mat& J) const;
00092
00094 void computeExtCov(double s_, jblas::sym_mat& extCov) const;
00095
00096 static double p_constraintAlpha;
00097 static int p_constraintMaxNbTimesApplied;
00098 static bool ENABLE_PLUCKER_CONSTRAINT;
00099
00100
00101 };
00102
00103
00104 std::ostream& operator <<(std::ostream& s, const jafar::slam::SegmentAnchorFeature& f);
00105
00112 class SegAnchorPluckerFeatureModel : public FeatureModel {
00113 public:
00114
00115 jblas::mat JunanchorPl;
00116
00117 SegAnchorPluckerFeatureModel();
00118 ~SegAnchorPluckerFeatureModel();
00119
00120
00121 void toFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec& xRes);
00122
00123 void toFrameJac(const jblas::vec& frame_, const jblas::vec& x_);
00124
00125 void fromFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec& xRes);
00126 void fromFrame(jblas::vec const& frame_, jblas::vec const& x_, jblas::vec_range& xRes);
00127
00128 void fromFrameJac(const jblas::vec& frame_, const jblas::vec& x_);
00129
00131 void computePlucker(jblas::vec const& x, jblas::vec& L);
00132 void computePluckerJac(jblas::vec const& x);
00133 void computePluckerJac(jblas::vec const& x, jblas::vec& L, jblas::mat& L_al);
00134
00135 void computeMergeState( const jblas::vec& x_, jblas::vec& mergeX_ , jblas::mat& jac );
00136
00138 void computeAnchorPlucker(jblas::vec const& L, jblas::vec const& x0, jblas::vec& aL);
00139 void computeAnchorPluckerJac(jblas::vec const& L, jblas::vec const& x0, jblas::vec& aL, jblas::mat& AL_l, jblas::mat& AL_x0);
00140
00141
00142 };
00143
00144
00150 class ImageAnchorPluckerFeatureObserveModel : public FeatureObserveModel {
00151
00152 protected:
00153
00155 SegAnchorPluckerFeatureModel& segAnchorPluckerFeatureModel;
00156
00158 jafar::camera::CameraPinhole camera;
00160 jblas::mat33 Pl;
00162 jblas::mat33 Plinv;
00163
00165 jblas::vec2 beta;
00167 jblas::mat22 covar_beta;
00168
00170 jblas::mat JbBeta;
00171
00172
00173 boost::tuple<double,double> computeExtremitiesAbscissa(SegmentAnchorFeature const& segFeature_,
00174 geom::T3DEuler const& robotPose_,
00175 SegmentObservation const& obs_) const;
00176
00177 void segmentExtremitiesPluckerLines(SegmentObservation const& segObs_,
00178 jblas::vec& lineExt1Sensor,
00179 jblas::vec& lineExt2Sensor) const;
00180
00181 static boost::tuple<double, double, double> pluckerLinesDistance(jblas::vec const& line1_,
00182 jblas::vec const& line2_);
00183
00184 jblas::vec const& predictObservationInSensorFrame(const jblas::vec& feature_);
00185
00186 void predictObservationInSensorFrameJac(const jblas::vec& feature_);
00187
00188 jblas::vec inverseObservationInSensorFrame(Observation const& obs_);
00189
00190 void inverseObservationInSensorFrameJac(Observation const& obs_);
00191
00193 jblas::sym_mat p_pixCov;
00194
00195 public:
00196
00197 ImageAnchorPluckerFeatureObserveModel(SegAnchorPluckerFeatureModel& featureModel_, jafar::camera::CameraPinhole const& camera_);
00198
00199 ~ImageAnchorPluckerFeatureObserveModel();
00200
00201 Observation::ObservationType typeObs() const {return Observation::SEGMENTAP_IMAGE;}
00202
00203 void setPixCov(jblas::vec const& pixCov_, double stabilizingFactor = 1.0);
00204
00207 void initInternalState(BaseFeature& feature, jafar::geom::T3DEuler const& robotPose_, Observation const& obs_) const;
00208
00211 void updateInternalState(BaseFeature& feature, jafar::geom::T3DEuler const& robotPose_, Observation const& obs_) const;
00212
00216 void postInitCovariance(jblas::sym_mat_range & P, jblas::mat const& Jx);
00217
00228 void predictExtObs(jblas::vec_range const& pose, jblas::sym_mat_range const& poseCov,
00229 jblas::vec3 const& ext, jblas::sym_mat const& extCov,
00230 jblas::vec& zPredExt, jblas::sym_mat& zPredExtCov);
00236 void predictExtObsJac(jblas::vec_range const& pose, jblas::vec3 const Ext, jblas::vec& eInImage, jblas::mat& JeR, jblas::mat& JeExt);
00237
00239 virtual jblas::vec const& computeInnovation(jblas::vec const& z_, jblas::vec const& zPred_);
00240
00244 static jblas::vec2 extToImageModel(jblas::vec const& ext1,jblas::vec const& ext2);
00245
00250 static void extToImageModelJac(jblas::vec const& ext1, jblas::vec const& ext2, jblas::mat& J);
00251
00252
00255 virtual void computeSensorR(Observation const& obs);
00256
00257
00262 void setup(double beta0 = 0, double beta1 = 0, double sigma_beta = 0.5);
00263
00264
00265
00266 };
00267
00268 }}
00269
00270 #endif // SLAM_SEG_INV_DEPTH_FEATURE_HPP