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