Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/SelfLocator/GT2005StableSelfLocator/GT2005StableSelfLocator.h

Go to the documentation of this file.
00001 /**
00002 * @file Modules/SelfLocator/GT2005StableSelfLocator.h
00003 * 
00004 * This file contains a class for self-localization based on the Monte Carlo approach 
00005 * using goals, landmarks and field lines.
00006 *
00007 * @author 
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     /*------------------------------ public variables ---------------------------------*/
00029 
00030     // parameter prepared for evolution
00031 
00032     // motion update parameters not yet adapted
00033 
00034     // observation update parameters
00035     // trust = weight / (variance)
00036 
00037     static double quasiZero,
00038                   maximumTrust,
00039       
00040       
00041                   translationNoise,
00042                   rotationNoise,
00043                   movedDistWeight,
00044                   movedAngleWeight,
00045                   majorDirTransWeight,
00046                   minorDirTransWeight,
00047 
00048                   headHeight,               // is calculated dynamically
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,                          /**< maximum number of samples */
00113       POSE_SPACE_GRID = 10,                       /**< quantization of the pose space */
00114 
00115    /** in the original 04 observation table LinesPercept::field is a x directed line and
00116         LinesPercept::numberOfLineTypes is a y directed line */
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;    /**< the sampleSet */
00126     bool teamColorBlue;
00127 
00128     /*------------------------------ public methods -----------------------------------*/
00129     /** 
00130     * Constructor.
00131     * @param interfaces The paramters of the SelfLocator module.
00132     */
00133     GT2005StableSelfLocator(const SelfLocatorInterfaces& interfaces);
00134       
00135     /**
00136     * The function executes the module.
00137     */
00138     virtual void execute();
00139     virtual bool handleMessage(InMessage& message);
00140 
00141 
00142   private:
00143 
00144   /* ------------------------- private classes here --------------------- */
00145 
00146     /**
00147     * The class represents a cell in a cube that is used to determine the largest sample cluster.
00148     */
00149     class Cell
00150     {
00151       public:
00152         int count;                  /**< The number of samples in this cube. */
00153         GT2005StableSelfLocatorSample* first;       /**< The first sample in this cube. */
00154         
00155       /**
00156       * Constructor.
00157       * preinititalize first with 0 to enshure correct end of queue detection
00158       */
00159       Cell() {count = 0; first = 0;}
00160     };
00161 
00162 
00163 /* ----------------------------------- private variables here ----------------------------------*/
00164 
00165 
00166     enum FlagSides{
00167       LEFT_SIDE_OF_FLAG = 1,                    /**< flag indicating a position on the left side of a flag */
00168       RIGHT_SIDE_OF_FLAG = -1                   /**< flag indicating a position on the right side of a flag */
00169     };
00170 
00171     Pose2D lastOdometry, lastOdometry2;                       /**< the last Odometry, used to calculate the delta_odometry */
00172     unsigned timeStamp;                                       /**< timestap */
00173     bool observationUpdateDone;                               /**< a flag indicating if an observation update was done during the current run of execute */
00174     double speed;                                             /**< current robot speed */
00175 
00176     double averagePerceptTypeProb[GT2005StableSelfLocatorSample::numberOfPerceptTypes]; /**< the average probability for each PerceptType and all Samples*/
00177 
00178     GT2005StableSampleTemplateGenerator sampleTemplateGenerator;                        /**< this class encapsules template generation */
00179     LinesPercept::LineType types[LinesPercept::numberOfLineTypes];            /**< types and number of types are needed for the template generator */
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     /** testing and debugging stuff */
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 /* ----------------------------------- private methods here ------------------------------------*/
00206 
00207     /**
00208     * The function distributes the parameter in a Gaussian way.
00209     * @param d A value that should be distributed.
00210     * @return A transformation of d according to a Gaussian curve.
00211     */
00212     double sigmoid(double d) const {return exp(- d * d);}
00213 
00214     /** 
00215     * The function updates the samples by the odometry offset.
00216     * @param odometry The motion since the last call to this function.
00217     * @param camera The camera offset.
00218     * @param noise Dermines whether some additional noise is added to the sample poses.
00219     *
00220     * enhance maybe by replacing bool noise by a noisefunction?
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     * The function updates the samples by a single edge of a flag recognized.
00231     * @param flagFieldPosition The position of the flag.
00232     * @param sideOfFlag The side of the flag that was seen.
00233     * @param measuredBearing The bearing, under which the edge was seen.
00234     */
00235     void updateByFlag(const Vector2<double>& flagFieldPosition,
00236             FlagSides sideOfFlag,
00237             double measuredBearing);
00238     
00239     /** 
00240     * The function updates the samples by a single goal post recognized.
00241     * @param goalPost The position of the goal post.
00242     * @param measuredBearing The bearing, under which the goal post was seen.
00243     */
00244     void updateByGoalPost(const Vector2<double>& goalPost,
00245               double measuredBearing);
00246 
00247     /** 
00248     * The function updates the samples by the recognized landmarks (goal, flag..)
00249     * triggers updateByFlag and updateByGoalPost
00250     * @param landmarksPercept The landmarksPercept
00251     */
00252     void landmarksObservationUpdate(const LandmarksPercept& landmarksPercept);
00253 
00254 
00255     /**calculates the CrossingClass out of the classification (side1..side4) in the LinesPercept
00256     */
00257     GT2005StableLineCrossingsTable::CrossingClass getCrossingClassification(const LinesPercept::LineCrossingPoint& point);
00258 
00259     /** observationUpdate by the center circle
00260     */
00261     void updateByCenterCircle(const LinesPercept::CenterCircle& centerCircle);
00262 
00263     /** observationUpdate using the linecrossing percept
00264     *   @param relative position of the linecrossing
00265     */
00266     void updateByCrossing(const LinesPercept::LineCrossingPoint& point);
00267     /**
00268     * does an observationupdate with a point on the field (line or goal)
00269     * @param point a point on a line
00270     * @param type the type of the line
00271     */
00272     void updateByPoint(const LinesPercept::LinePoint& point,GT2005StableSelfLocatorSample::PerceptType type);
00273 
00274     /** 
00275     * The function updates the samples by recognized lines
00276     * @param linesPercept The LinesPercept
00277     */
00278     void lineObservationUpdate(const LinesPercept& linesPercept);
00279 
00280     /**
00281     * Calculates the average possibility for each perceptType and all samples
00282     * and returns the product over all averages.
00283     * contains the part of the gt04 resampling method that calculates
00284     * @return product over all average percepttype-probabilities
00285     */
00286     double calcAveragePerceptTypeProbabilities();
00287 
00288     /**
00289     * redistibution of the sampleSet according to the probabilities of the samples
00290     */
00291     void resample();
00292 
00293     
00294     double calcDistributionValidity();
00295 
00296     /**
00297     * The function calculates a Pose by averaging the sample poses in a sub cube of
00298     * the pose-room
00299     */
00300     RobotPose calcPoseFromSubCube(Cell poseSpace[POSE_SPACE_GRID][POSE_SPACE_GRID][POSE_SPACE_GRID], int x, int y, int r);
00301 
00302     /**
00303     * The function determines the most probable pose from the sample distribution.
00304     * @param pose The pose is returned to this variable.
00305     * @param validity The validity of the pose is returned to this variable.
00306     */
00307     void calcPose(Pose2D& pose,double& validity);
00308 
00309 
00310   // Debug drawings completely taken from gt04
00311 
00312     /**
00313     * The function draws an arrow to a debug drawing.
00314     * @param pose The position and direction of the arrow.
00315     * @param color The color of the arrow.
00316     */
00317     void draw(const Pose2D& pose,Drawings::Color color) const;
00318   
00319     /**
00320     * The function draws a point of a line percept.
00321     * @param point The relative position in field coordinates.
00322     * @param type The line type of the point.
00323     */
00324     void draw(const Vector2<int>& point,LinesPercept::LineType type) const;
00325 
00326     /**
00327     * The function calculates the variances and trust values 
00328     * from the current speed
00329     */
00330     void updateVariancesBySpeed(double speed);
00331 
00332 };
00333 
00334 #endif //GT2005StableSelfLocator.h

Generated on Mon Mar 20 21:59:56 2006 for GT2005 by doxygen 1.3.6