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

Modules/SelfLocator/GT2004SelfLocator.h

Go to the documentation of this file.
00001 /**
00002 * @file Modules/SelfLocator/GT2004SelfLocator.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 <A href=mailto:roefer@tzi.de>Thomas Röfer</A>
00008 */
00009 
00010 #ifndef __GT2004SelfLocator_h_
00011 #define __GT2004SelfLocator_h_
00012 
00013 #include "SelfLocator.h"
00014 #include "LinesTables2004.h"
00015 
00016 #include "DistanceToBorderEstimator.h"
00017 
00018 /**
00019 * The class implements a lines-based Monte Carlo self-localization.
00020 */
00021 class GT2004SelfLocator : public SelfLocator, public LinesTables2004
00022 {
00023   private:
00024     /** A class that can estimate the distance to the border */
00025     DistanceToBorderEstimator distanceToBorderEstimator;
00026     
00027     /**
00028     * The class represents a sample.
00029     */
00030     class Sample : public PoseSample
00031     {
00032       public:
00033         enum 
00034         {
00035           numberOfQualities = LinesPercept::numberOfLineTypes + 1
00036         };
00037         Pose2D camera; /**< Temporary representing the pose of the camera. */
00038         double quality[numberOfQualities]; /**< The quality of the sample, i.e. a lowpass filtered probability. */
00039         Sample* next; /**< The next sample in the cell cube. */
00040     
00041         /**
00042         * Constructor.
00043         */
00044         Sample();
00045 
00046         /**
00047         * Constructor.
00048         * @param pose The pose of the sample.
00049         * @param quality The quality of the sample.
00050         */
00051         Sample(const Pose2D& pose,const double* quality);
00052 
00053         double getQuality() const {return probability;}
00054 
00055         void updateQuality(const double* average);
00056 
00057         void setProbability(LinesPercept::LineType type,double value);
00058 
00059         bool isValid() const {return probability != 2;}
00060     };
00061   
00062     /**
00063     * The class represents a cell in a cube that is used to determine the largest sample cluster.
00064     */
00065     class Cell
00066     {
00067     public:
00068       int count; /**< The number of samples in this cube. */
00069       Sample* first; /**< The first sample in this cube. */
00070     
00071       /**
00072 
00073       * Constructor.
00074       */
00075       Cell() {count = 0; first = 0;}
00076     };
00077 
00078 
00079     enum
00080     {
00081       SAMPLES_MAX = 100, /**< The number of samples. */
00082       GRID_MAX = 10, /**< The number of cells in one dimension. */
00083       FLAGS_MAX = 3 /**< The size of the flag buffer. */
00084     };
00085   
00086     enum FlagSides
00087     {
00088       LEFT_SIDE_OF_FLAG = 1, /**< A marker for left edges of flags. */
00089       RIGHT_SIDE_OF_FLAG = -1 /**< A marker for right edges of flags. */
00090     };
00091   
00092     SampleSet<Sample, SAMPLES_MAX> sampleSet; /**< The sample set. */
00093     Pose2D lastOdometry, /**< The state of the odometry at the previous call of this module. */
00094            lastOdometry2,
00095            templates[SAMPLES_MAX]; /**< Templates for poses replacing bad samples. */
00096     Flag flags[FLAGS_MAX]; /**< A buffer for previously seen flags. */
00097     int numOfFlags, /**< The number of flags in the buffer. */
00098         numOfTemplates, /**< The number of templates generated. */
00099         nextTemplate; /**< The next template delivered. */
00100     int randomFactor; /**< A factor that is increased if more templates are required. */
00101     LinesPercept::LineType types[LinesPercept::numberOfLineTypes];
00102     int numberOfTypes;
00103     bool sensorUpdated; /**< Did any update of the samples by a sensor reading happen? */
00104     double average[Sample::numberOfQualities];
00105     unsigned timeStamp;
00106     double speed;
00107 
00108     /**
00109     * The function distributes the parameter in a Gaussian way.
00110     * @param d A value that should be distributed.
00111     * @return A transformation of d according to a Gaussian curve.
00112     */
00113     double sigmoid(double d) const {return exp(- d * d);}
00114   
00115     /** 
00116     * The function updates the samples by the odometry offset.
00117     * @param odometry The motion since the last call to this function.
00118     * @param camera The camera offset.
00119     * @param noise Dermines whether some additional noise is added to the sample poses.
00120     */
00121     void updateByOdometry(const Pose2D& odometry,const Pose2D& camera,bool noise);
00122   
00123     /** 
00124     * The function updates the samples by a single line point recognized.
00125     * @param point The relative offset of the point.
00126     * @param type The type of the point.
00127     */
00128     void updateByPoint(const LinesPercept::LinePoint& point,LinesPercept::LineType type);
00129   
00130     /** 
00131     * The function updates the samples by a single edge of a flag recognized.
00132     * @param flag The position of the flag.
00133     * @param sideOfFlag The side of the flag that was seen.
00134     * @param measuredBearing The bearing, under which the edge was seen.
00135     */
00136     void updateByFlag(const Vector2<double>& flag,
00137                       FlagSides sideOfFlag,
00138                       double measuredBearing);
00139   
00140     /** 
00141     * The function updates the samples by a single goal post recognized.
00142     * @param goalPost The position of the goal post.
00143     * @param measuredBearing The bearing, under which the goal post was seen.
00144     */
00145     void updateByGoalPost(const Vector2<double>& goalPost,
00146                           double measuredBearing);
00147   
00148     /**
00149     * The function re-distributes the samples according to their probabilities.
00150     */
00151     void resample();
00152   
00153     /**
00154     * The function determines the most probable pose from the sample distribution.
00155     * @param pose The pose is returned to this variable.
00156     * @param validity The validity of the pose is returned to this variable.
00157     */
00158     void calcPose(Pose2D& pose,double& validity);
00159   
00160     /**
00161     * The function adds a flag to the buffer.
00162     * @param flag The new flag.
00163     */
00164     void addFlag(const Flag& flag);
00165   
00166     /**
00167     * The function calculates the current pose of the robot from three bearings.
00168     * @param dir0 The bearing on the first landmark.
00169     * @param dir1 The bearing on the second landmark.
00170     * @param dir2 The bearing on the third landmark.
00171     * @param mark0 The position of the first landmark.
00172     * @param mark1 The position of the second landmark.
00173     * @param mark2 The position of the third landmark.
00174     * @param cameraOffset The offset of the camera relative to the body center.
00175     * @param resultingPose The calculated pose is returned to this variable.
00176     * @return Was the function successful?
00177     */
00178     bool poseFromBearings(double dir0,double dir1,double dir2,
00179                           const Vector2<double>& mark0,
00180                           const Vector2<double>& mark1,
00181                           const Vector2<double>& mark2,
00182                           const Vector2<double>& cameraOffset,
00183                           Pose2D& resultingPose) const;
00184   
00185     /**
00186     * The function calculates the up to two current poses of the robot from two bearings and a distance.
00187     * @param dir0 The bearing on the first landmark.
00188     * @param dir1 The bearing on the second landmark.
00189     * @param dist The distance of the first landmark.
00190     * @param mark0 The position of the first landmark.
00191     * @param mark1 The position of the second landmark.
00192     * @param cameraOffset The offset of the camera relative to the body center.
00193     * @param resultingPose1 One calculated pose is returned to this variable.
00194     * @param resultingPose2 A second calculated pose is returned to this variable.
00195     * @return The number of poses calculated?
00196     */
00197     int poseFromBearingsAndDistance(double dir0,double dir1,
00198                                     double dist,
00199                                     const Vector2<double>& mark0,
00200                                     const Vector2<double>& mark1,
00201                                     const Vector2<double>& cameraOffset,
00202                                     Pose2D& resultingPose1,
00203                                     Pose2D& resultingPose2) const;
00204   
00205     /**
00206     * The function determines a pair of landmark positions and bearings from a landmarks percept.
00207     * @param landmarksPercept The landmarks percept.
00208     * @param i The index of the entry in the percept.
00209     * @param mark The position of the mark is returned here.
00210     * @param dir The bearing on the mark is returned to this variable.
00211     * @param dist The distance of the mark is returned to this variable.
00212     * @return returns true if getting the bearing was successful.
00213     */
00214     bool getBearing(const LandmarksPercept& landmarksPercept,int i,
00215                     Vector2<double>& mark,
00216                     double& dir,double& dist) const;
00217   
00218     /**
00219     * The function generates pose templates from a landmark percept.
00220     * The pose templates can be used to initialize new samples.
00221     * @param landmarksPercept The landmarks percept.
00222     * @param odometry The odometry offset since the last call of this function.
00223     */
00224     void generatePoseTemplates(const LandmarksPercept& landmarksPercept,
00225                                const Pose2D& odometry);
00226  
00227     /**
00228     * The function returns the next pose template or a random one if no templates were determined.
00229     * @return A new sample.
00230     */
00231     Sample getTemplate();
00232 
00233     /**
00234     * The function creates a random sample inside the field boundaries.
00235     * @return The random sample.
00236     */
00237     //Sample getTemplate() const;
00238   
00239     /**
00240     * The function draws an arrow to a debug drawing.
00241     * @param pose The position and direction of the arrow.
00242     * @param color The color of the arrow.
00243     */
00244     void draw(const Pose2D& pose,Drawings::Color color) const;
00245   
00246     /**
00247     * The function draws a point of a line percept.
00248     * @param point The relative position in field coordinates.
00249     * @param type The line type of the point.
00250     */
00251     void draw(const Vector2<int>& point,LinesPercept::LineType type) const;
00252 
00253   public:
00254     /** 
00255     * Constructor.
00256     * @param interfaces The paramters of the SelfLocator module.
00257     */
00258     GT2004SelfLocator(const SelfLocatorInterfaces& interfaces);
00259     
00260     /**
00261      * The function executes the module.
00262      */
00263     virtual void execute();
00264     virtual bool handleMessage(InMessage& message);
00265 
00266     static double paramUp, // step size for increasing qualities
00267                   paramDown, // step size for decreasing qualities
00268                   paramDelay, // factor
00269                   paramHeight, // hypothetic height of head
00270                   paramZ, // sharpness of Gauss for rotational errors 
00271                   paramY, // sharpness of Gauss for translational errors
00272                   paramR, // sharpness of Gauss for rotational errors
00273                   paramTrans, // maximum translational shift if quality is bad
00274                   paramRot; // maximum rotational shift if quality is bad
00275 };
00276 
00277 #endif// __GT2004SelfLocator_h_
00278 
00279 /*
00280 * Change log :
00281 * 
00282 * $Log: GT2004SelfLocator.h,v $
00283 * Revision 1.4  2004/06/28 09:48:14  roefer
00284 * SelfLocator
00285 *
00286 * Revision 1.3  2004/06/24 18:26:38  roefer
00287 * Lines table redesign, should not influence the performance of GT2003SL
00288 *
00289 * Revision 1.2  2004/06/17 13:10:56  roefer
00290 * Different lines table for GT2004SL
00291 *
00292 * Revision 1.1  2004/06/17 11:24:04  roefer
00293 * Added RGIP and GT2004SL
00294 *
00295 */

Generated on Thu Sep 23 19:57:31 2004 for GT2004 by doxygen 1.3.6