00001
00002
00003 #ifndef SIMU_SENSOR_HPP
00004 #define SIMU_SENSOR_HPP
00005
00006 #include "jmath/jblas.hpp"
00007 #include "jmath/random.hpp"
00008
00009 #include "camera/cameraPinhole.hpp"
00010 #include "camera/cameraBarreto.hpp"
00011
00012 #include "slam/feature.hpp"
00013 #include "slam/segmentFeature.hpp"
00014 #include "slam/observation.hpp"
00015 #include "simu/environment.hpp"
00016
00017 namespace jafar {
00018 namespace slam {
00019 class SegmentObservationsSelector;
00020 }
00021 namespace simu {
00022
00027 class Sensor {
00028
00029 public:
00030
00031 jblas::vec z;
00032 jblas::vec noiseCov;
00033
00034 Sensor(const jblas::vec& noiseCov_,
00035 bool doAddNoise = false, unsigned int randomSeed = 1,
00036 double noiseFactor = 1.0, unsigned int sensorId_ = 0) :
00037 z(noiseCov_.size()),
00038 noiseCov(noiseCov_),
00039 p_doAddNoise(doAddNoise),
00040 noise(jblas::zero_vec(noiseCov_.size()), noiseFactor*noiseFactor*noiseCov_, randomSeed),
00041 sensorId(sensorId_)
00042 {}
00043
00044 Sensor(const jblas::vec& noiseCov_, std::size_t zSize,
00045 bool doAddNoise = false, unsigned int randomSeed = 1,
00046 double noiseFactor = 1.0, unsigned int sensorId_ = 0) :
00047 z(zSize),
00048 noiseCov(noiseCov_),
00049 p_doAddNoise(doAddNoise),
00050 noise(jblas::zero_vec(noiseCov_.size()), noiseFactor*noiseFactor*noiseCov_, randomSeed),
00051 sensorId(sensorId_)
00052 {}
00053
00054
00055 virtual ~Sensor() {}
00056 public:
00057 jblas::vec noiseStdDev() const;
00058
00059 protected:
00060
00061 bool p_doAddNoise;
00062
00063 jafar::jmath::MultiDimNormalDistribution noise;
00064 unsigned int sensorId;
00065 };
00066
00071 class SensorRobot : public Sensor {
00072 public:
00073 double range;
00074 double apertureH;
00075 double apertureV;
00076 const Robot& robot;
00077 SensorRobot( Robot& _robot, double range_, double apertureH_, double apertureV_, const jblas::vec& noiseCov_,
00078 bool doAddNoise = false, unsigned int randomSeed = 1,
00079 double noiseFactor = 1.0) : Sensor(noiseCov_, doAddNoise, randomSeed, noiseFactor),
00080 range(range_), apertureH(apertureH_), apertureV(apertureV_), robot(_robot)
00081 {}
00082 bool isInRange( const Robot& _robot2 ) const;
00083 jafar::slam::Observation* observe( const Robot& _robot2);
00084 };
00085
00090 class SensorPoint : public Sensor {
00091
00092 public:
00093
00094 SensorPoint(const jblas::vec& noiseCov_,
00095 bool doAddNoise = false, unsigned int randomSeed = 1,
00096 double noiseFactor = 1.0, unsigned int sensorId_ = 0) :
00097 Sensor(noiseCov_, doAddNoise, randomSeed, noiseFactor, sensorId_)
00098 {}
00099
00100 virtual ~SensorPoint() {}
00101
00102 virtual bool isInRange( const jblas::vec& sensor_, const Point& feature_) const = 0;
00103
00104 virtual jafar::slam::Observation* observe(const jblas::vec& sensor_,
00105 const Point& feature_, unsigned int _robotId) = 0;
00106 };
00107
00108
00109
00113 class SensorPointSimple : public SensorPoint {
00114
00115 public:
00116
00117 double range;
00118 double apertureH;
00119 double apertureV;
00120
00121 SensorPointSimple(double range_, double apertureH_, double apertureV_, const jblas::vec& noiseCov_,
00122 bool doAddNoise = false, unsigned int randomSeed = 1,
00123 double noiseFactor = 1.0, unsigned int sensorId_ = 0) :
00124 SensorPoint(noiseCov_, doAddNoise, randomSeed, noiseFactor, sensorId_),
00125 range(range_), apertureH(apertureH_), apertureV(apertureV_)
00126 {}
00127
00128 ~SensorPointSimple() {}
00129
00131 double getApertureH() const {return apertureH;}
00132
00134 double getApertureV() const {return apertureV;}
00135
00136 bool isInRange(const jblas::vec& sensor_, const Point& feature_) const;
00137
00138 };
00139
00145 class SensorPointCartesian : public SensorPointSimple {
00146
00147 public :
00148
00149 SensorPointCartesian(double dRange_, double thetaRange_, double phiRange_, const jblas::vec& noiseCov_,
00150 bool doAddNoise = false, unsigned int randomSeed = 1, double noiseFactor = 1.0, unsigned int sensorId_ = 0);
00151 ~SensorPointCartesian();
00152
00153 jafar::slam::Observation* observe(const jblas::vec& sensor_,
00154 const Point& feature_, unsigned int _robotId);
00155 };
00156
00160 class SensorPointPolar : public SensorPointSimple {
00161
00162 public :
00163
00164 SensorPointPolar(double dRange_, double thetaRange_,double phiRange_, const jblas::vec& noiseCov_,
00165 bool doAddNoise = false, unsigned int randomSeed = 1,
00166 double noiseFactor = 1.0, unsigned int sensorId_ = 0);
00167 ~SensorPointPolar();
00168
00169 jafar::slam::Observation* observe(const jblas::vec& sensor_,
00170 const Point& feature_, unsigned int _robotId);
00171 };
00172
00178 class SensorPointBearing : public SensorPointSimple {
00179
00180 public :
00181
00182 SensorPointBearing(double dRange_, double thetaRange_,double phiRange_, const jblas::vec& noiseCov_,
00183 bool doAddNoise = false, unsigned int randomSeed = 1,
00184 double noiseFactor = 1.0, unsigned int sensorId_ = 0);
00185 ~SensorPointBearing();
00186
00187 jafar::slam::Observation* observe(const jblas::vec& sensor_,
00188 const Point& feature_, unsigned int _robotId);
00189
00190 friend std::ostream& operator <<(std::ostream& s, const SensorPointSimple& sensor_);
00191 };
00192
00193 std::ostream& operator <<(std::ostream& s, const SensorPointSimple& sensor_);
00194
00200 class SensorPointImage : public SensorPoint {
00201
00202 public :
00203
00204 jafar::camera::CameraPinhole camera;
00205 double range;
00206
00207 SensorPointImage(jafar::camera::CameraPinhole const& camera_,
00208 double dRange_,
00209 const jblas::vec& noiseCov_,
00210 bool doAddNoise = false, unsigned int randomSeed = 1,
00211 double noiseFactor = 1.0, unsigned int sensorId_ = 0);
00212
00213 ~SensorPointImage();
00214
00216 double getApertureH() const {return camera.getApertureU();}
00217
00219 double getApertureV() const {return camera.getApertureV();}
00220
00221 bool isInRange(const jblas::vec& sensor_, const Point& feature_) const;
00222
00223 jafar::slam::Observation* observe(const jblas::vec& sensor_,
00224 const Point& feature_, unsigned int _robotId);
00225
00226 protected :
00227
00228 friend std::ostream& operator <<(std::ostream& s, const SensorPointImage& sensor_);
00229
00230 };
00231
00232 std::ostream& operator <<(std::ostream& s, const SensorPointImage& sensor_);
00233
00234
00240 class SensorPointOmniImage : public SensorPoint {
00241
00242 public :
00243
00244 jafar::camera::CameraParabolicBarreto camera;
00245 double range;
00246
00247 SensorPointOmniImage(jafar::camera::CameraParabolicBarreto const& camera_,
00248 double dRange_,
00249 const jblas::vec& noiseCov_,
00250 bool doAddNoise = false, unsigned int randomSeed = 1,
00251 double noiseFactor = 1.0, unsigned int sensorId_ = 0);
00252
00253 ~SensorPointOmniImage();
00254
00255 bool isInRange(const jblas::vec& sensor_, const Point& feature_) const;
00256
00257 jafar::slam::Observation* observe(const jblas::vec& sensor_,
00258 const Point& feature_, unsigned int _robotId);
00259
00260 protected :
00261
00262 friend std::ostream& operator <<(std::ostream& s, const SensorPointOmniImage& sensor_);
00263
00264 };
00265
00266 std::ostream& operator <<(std::ostream& s, const SensorPointOmniImage& sensor_);
00267
00273 class SensorSegmentImage : public Sensor {
00274
00275 public :
00276
00278 double minSegmentSize;
00279
00280 jafar::camera::CameraPinhole camera;
00281 double range;
00282
00283 slam::Observation::ObservationType type;
00284
00285 SensorSegmentImage(jafar::camera::CameraPinhole const& camera_,
00286 double dRange_,
00287 jblas::vec const& noiseCov_,
00288 double minSegmentSize_,
00289 bool doAddNoise = false, unsigned int randomSeed = 1,
00290 double noiseFactor = 1.0, unsigned int sensorId_ = 0,
00291 slam::Observation::ObservationType type_ = slam::Observation::SEGMENT_IMAGE);
00292
00293 SensorSegmentImage(jafar::camera::CameraPinhole const& camera_,
00294 double dRange_,
00295 jblas::vec const& noiseCov_,
00296 std::size_t zSize_,
00297 double minSegmentSize_,
00298 bool doAddNoise=false, unsigned int randomSeed = 1,
00299 double noiseFactor = 1.0, unsigned int sensorId_ = 0,
00300 slam::Observation::ObservationType type_ = slam::Observation::SEGMENT_IMAGE);
00301
00302 virtual ~SensorSegmentImage();
00303
00304
00305
00306
00307
00308
00309
00310 virtual bool isInRange(jblas::vec const& sensor_, Segment const& seg_) const;
00311
00312
00313
00314 virtual jafar::slam::Observation* observe(jblas::vec const& sensor_,
00315 Segment const& seg_, unsigned int _robotId);
00316
00317 void setSegmentObservationsSelector(slam::SegmentObservationsSelector* _selector);
00318 protected :
00319 jafar::slam::SegmentObservationsSelector* m_obsevationsSelector;
00320
00324 virtual bool findVisibleExtremities(jblas::vec3 const& ext1_, jblas::vec3 const& ext2_,
00325 jblas::vec2& pix1, jblas::vec2& pix2,
00326 double step = 0.1) const;
00327
00328
00329 friend std::ostream& operator <<(std::ostream& s, const SensorSegmentImage& sensor_);
00330
00331 };
00332
00333 std::ostream& operator <<(std::ostream& s, const jafar::simu::SensorSegmentImage& sensor_);
00334
00340 class SensorSegmentStereoImage : public SensorSegmentImage {
00341
00342 public :
00343
00344 jafar::camera::StereoBench stereoBench;
00345
00346 jafar::jmath::NormalDistribution dispNoise;
00347
00348 SensorSegmentStereoImage(jafar::camera::StereoBench const& stereoBench_,
00349 double dRange_,
00350 jblas::vec const& noiseCov_,
00351 double const& noiseDisp_,
00352 double minSegmentSize_,
00353 bool doAddNoise = false, unsigned int randomSeed = 1,
00354 double noiseFactor = 1.0, unsigned int sensorId_ = 0);
00355
00356 ~SensorSegmentStereoImage();
00357
00358 bool isInRange(jblas::vec const& sensor_, Segment const& seg_) const;
00359
00360 jafar::slam::Observation* observe(jblas::vec const& sensor_,
00361 Segment const& seg_, unsigned int _robotId);
00362
00363 protected :
00364
00365 bool findVisibleExtremities(jblas::vec3 const& ext1_, jblas::vec3 const& ext2_,
00366 jblas::vec2& pix1, jblas::vec2& pix2, double& disp1, double& disp2,
00367 double step = 0.1) const;
00368
00369
00370
00371 friend std::ostream& operator <<(std::ostream& s, const SensorSegmentStereoImage& sensor_);
00372
00373 };
00374
00375 std::ostream& operator <<(std::ostream& s, const jafar::simu::SensorSegmentImage& sensor_);
00376
00377 }
00378 }
00379
00380
00381 #endif // SIMU_SENSOR_HPP