00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __SlamSelfLocator_h_
00011 #define __SlamSelfLocator_h_
00012
00013 #include "../SelfLocator.h"
00014 #include "../LinesTables2004.h"
00015 #include "SlamSelfLocatorSample.h"
00016 #include "SlamSampleTemplateGenerator.h"
00017 #include "SlamLineCrossingsTable.h"
00018 #include "Tools/Debugging/GenericDebugData.h"
00019 #include "Tools/ColorClasses.h"
00020 #include "Tools/Math/Geometry.h"
00021 #include "Tools/TRingBufferWithSum.h"
00022
00023
00024 class SlamSelfLocator : public SelfLocator, public LinesTables2004
00025 {
00026
00027 public:
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 static double quasiZero,
00038 maximumTrust,
00039
00040
00041 translationNoise,
00042 rotationNoise,
00043 movedDistWeight,
00044 movedAngleWeight,
00045 majorDirTransWeight,
00046 minorDirTransWeight,
00047
00048 headHeight,
00049
00050
00051 linePointZAngleVariance,
00052 linePointZAngleMotionDependentVariance,
00053 linePointYAngleVariance,
00054 linePointYAngleMotionDependentVariance,
00055 linePointZAngleMotionDependency,
00056 linePointYAngleMotionDependency,
00057
00058 crossingZAngleVariance,
00059 crossingZAngleMotionDependentVariance,
00060 crossingYAngleVariance,
00061 crossingYAngleMotionDependentVariance,
00062 crossingZAngleMotionDependency,
00063 crossingYAngleMotionDependency,
00064
00065 centerCircleZAngleVariance,
00066 centerCircleZAngleMotionDependentVariance,
00067 centerCircleYAngleVariance,
00068 centerCircleYAngleMotionDependentVariance,
00069 centerCircleOrientationAngleVariance,
00070 centerCircleOrientationAngleMotionDependentVariance,
00071 centerCircleZAngleMotionDependency,
00072 centerCircleYAngleMotionDependency,
00073 centerCircleOrientationAngleMotionDependency,
00074
00075 flagZAngleVariance,
00076 flagZAngleMotionDependentVariance,
00077 flagYAngleVariance,
00078 flagYAngleMotionDependentVariance,
00079 flagZAngleMotionDependency,
00080 flagYAngleMotionDependency,
00081
00082 goalZAngleVariance,
00083 goalZAngleMotionDependentVariance,
00084 goalYAngleVariance,
00085 goalYAngleMotionDependentVariance,
00086 goalZAngleMotionDependency,
00087 goalYAngleMotionDependency,
00088
00089 linePointWeight,
00090 linePointZAngleTrust,
00091 linePointYAngleTrust,
00092
00093 crossingWeight,
00094 crossingZAngleTrust,
00095 crossingYAngleTrust,
00096
00097 centerCircleWeight,
00098 centerCircleZAngleTrust,
00099 centerCircleYAngleTrust,
00100 centerCircleOrientationAngleTrust,
00101
00102 flagWeight,
00103 flagZAngleTrust,
00104 flagYAngleTrust,
00105
00106 goalWeight,
00107 goalZAngleTrust,
00108 goalYAngleTrust;
00109
00110 enum{
00111 SAMPLES_MAX = 100,
00112 POSE_SPACE_GRID = 10,
00113
00114
00115
00116 OBS_TABLE_X_FIELD_LINE = LinesPercept::field,
00117 OBS_TABLE_Y_FIELD_LINE = LinesPercept::numberOfLineTypes,
00118
00119 HEAD_HEIGHT_SMOOTHING_FRAMENUMBER = 5,
00120
00121 NUM_OF_CALCULATED_POSES = 3
00122 };
00123
00124 SampleSet<SlamSelfLocatorSample, SAMPLES_MAX> sampleSet;
00125 bool teamColorBlue;
00126
00127
00128
00129
00130
00131
00132 SlamSelfLocator(const SelfLocatorInterfaces& interfaces);
00133
00134
00135
00136
00137 virtual void execute();
00138 virtual bool handleMessage(InMessage& message);
00139
00140
00141 private:
00142
00143
00144
00145
00146
00147
00148 class Cell
00149 {
00150 public:
00151 int count;
00152 SlamSelfLocatorSample* first;
00153
00154
00155
00156
00157
00158 Cell() {count = 0; first = 0;}
00159 };
00160
00161
00162
00163
00164 enum FlagSides{
00165 LEFT_SIDE_OF_FLAG = 1,
00166 RIGHT_SIDE_OF_FLAG = -1
00167 };
00168
00169 Pose2D lastOdometry, lastOdometry2;
00170 unsigned timeStamp;
00171 bool observationUpdateDone;
00172 double speed;
00173
00174 double averagePerceptTypeProb[SlamSelfLocatorSample::numberOfPerceptTypes];
00175
00176 SlamSampleTemplateGenerator sampleTemplateGenerator;
00177 LinesPercept::LineType types[LinesPercept::numberOfLineTypes];
00178 int numberOfTypes;
00179
00180 SlamLineCrossingsTable lineCrossingsTable;
00181
00182 TRingBufferWithSum<double,HEAD_HEIGHT_SMOOTHING_FRAMENUMBER> headHeightBuffer;
00183
00184 bool odometryPoseResetted;
00185 Pose2D odometryPose;
00186 RobotPose candidates[NUM_OF_CALCULATED_POSES];
00187
00188
00189 SlamSelfLocatorSample* testSample;
00190 Vector2<double> lastModelCrossing, lastSeenCrossing;
00191 SlamLineCrossingsTable::CrossingClass lastSeenCrossingClass;
00192 Pose2D lastSeenCenterCircle;
00193
00194
00195
00196
00197
00198
00199
00200
00201 double sigmoid(double d) const {return exp(- d * d);}
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 void motionUpdate(const Pose2D& odometry,const Pose2D& camera,bool noise);
00212
00213
00214 void updateByNotSeenFlag(Flag::FlagType type);
00215
00216 void updateByNotSeenGoal(colorClass goalColor);
00217
00218
00219
00220
00221
00222
00223
00224 void updateByFlag(const Vector2<double>& flagFieldPosition,
00225 FlagSides sideOfFlag,
00226 double measuredBearing);
00227
00228
00229
00230
00231
00232
00233 void updateByGoalPost(const Vector2<double>& goalPost,
00234 double measuredBearing);
00235
00236
00237
00238
00239
00240
00241 void landmarksObservationUpdate(const LandmarksPercept& landmarksPercept);
00242
00243
00244
00245
00246 SlamLineCrossingsTable::CrossingClass getCrossingClassification(const LinesPercept::LineCrossingPoint& point);
00247
00248
00249
00250 void updateByCenterCircle(const LinesPercept::CenterCircle& centerCircle);
00251
00252
00253
00254
00255 void updateByCrossing(const LinesPercept::LineCrossingPoint& point);
00256
00257
00258
00259
00260
00261 void updateByPoint(const LinesPercept::LinePoint& point,SlamSelfLocatorSample::PerceptType type);
00262
00263
00264
00265 void updateByEstimatedDirection();
00266
00267
00268
00269
00270
00271 void lineObservationUpdate(const LinesPercept& linesPercept);
00272
00273
00274
00275
00276
00277
00278
00279 double calcAveragePerceptTypeProbabilities();
00280
00281
00282
00283
00284 void resample();
00285
00286 double calcDistributionValidity();
00287
00288
00289
00290
00291
00292 RobotPose calcPoseFromSubCube(Cell poseSpace[POSE_SPACE_GRID][POSE_SPACE_GRID][POSE_SPACE_GRID], int x, int y, int r);
00293
00294
00295
00296
00297
00298
00299 void calcPose(Pose2D& pose,double& validity);
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 void draw(const Pose2D& pose,Drawings::Color color) const;
00310
00311
00312
00313
00314
00315
00316 void draw(const Vector2<int>& point,LinesPercept::LineType type) const;
00317
00318
00319
00320
00321
00322 void updateVariancesBySpeed(double speed);
00323
00324 };
00325
00326 #endif //SlamSelfLocator.h