00001 /** 00002 * @file BB2004Calibrator.h 00003 * 00004 * Definition of class BB2004Calibrator. 00005 * 00006 * @author <a href="mailto:roefer@tzi.de">Thomas Röfer</a> 00007 */ 00008 00009 #ifndef __BB2004Calibrator_h_ 00010 #define __BB2004Calibrator_h_ 00011 00012 #include "Modules/SensorBehaviorControl/SensorBehaviorControl.h" 00013 #include "Modules/ImageProcessor/GT2004ImageProcessor/GT2004ImageProcessor.h" 00014 #include "Modules/SelfLocator/LinesTables2004.h" 00015 #include "Tools/RingBuffer.h" 00016 #include "Tools/Evolution/BB2004Evo.h" 00017 00018 /** 00019 * @class CalibrationIndividual 00020 * 00021 * The class represents an individual for a set of walking parameters. 00022 */ 00023 class CalibrationIndividual : public BBIndividual 00024 { 00025 private: 00026 enum 00027 { 00028 numOfGenes = 7 /**< The number of genes of the individual. */ 00029 }; 00030 static double geneScale[numOfGenes]; /**< An array that estimates the range of value of a certain gene. */ 00031 double genes[numOfGenes]; /**< The genes. */ 00032 double fitness; /**< The fitness of this individual. */ 00033 00034 public: 00035 /** 00036 * Constructor. 00037 */ 00038 CalibrationIndividual() {fitness = 1;} 00039 00040 /** 00041 * The function initializes the current individual with another one. 00042 * @param initial The other individual the current one is initialized with. 00043 */ 00044 virtual void init(const BBIndividual& initial); 00045 00046 /** 00047 * The function interpolates between the current individual and another one. 00048 * The result is stored in the current individual. 00049 * @param other The other individual the current one is interpolated with. 00050 */ 00051 virtual void interpolate(const BBIndividual& other); 00052 00053 /** 00054 * The function extrapolates between the current individual and another one. 00055 * @param other The other individual the current one is extrapolated with. 00056 */ 00057 virtual void extrapolate(const BBIndividual& other); 00058 00059 /** 00060 * The function mutates the current individual. 00061 */ 00062 virtual void mutate(); 00063 00064 /** 00065 * The function returns the fitness of the individual. 00066 * @return The fitness as a number >= 0. A higher result means a higher fitness. 00067 */ 00068 virtual double getFitness() const {return fitness;} 00069 00070 /** 00071 * The function sets the fitness of the individual. 00072 * @param fitness The fitness. 00073 */ 00074 void setFitness(double fitness) {this->fitness = fitness;} 00075 00076 /** 00077 * The function copies the genes into the calibration parameters. 00078 */ 00079 void select() const; 00080 00081 /** 00082 * The function prints the genes. 00083 */ 00084 void dump() const; 00085 }; 00086 00087 /** 00088 * @class BB2004Calibrator 00089 * The class calibrates the correction values for the camera matrix. 00090 */ 00091 class BB2004Calibrator : public SensorBehaviorControl, public LinesTables2004 00092 { 00093 public: 00094 /** 00095 * Constructor. 00096 * @param interfaces The parameters of the BB2004Calibrator module. 00097 */ 00098 BB2004Calibrator(const SensorBehaviorControlInterfaces& interfaces); 00099 00100 /** 00101 * The function executes the module. 00102 */ 00103 virtual void execute(); 00104 00105 /** 00106 * The function handles messages sent to the module. 00107 * @param message A message. 00108 * @return Was the message handled by this module? 00109 */ 00110 virtual bool handleMessage(InMessage& message); 00111 00112 private: 00113 CameraMatrix cameraMatrix; /**< The camera matrix that will be set for the image processor. */ 00114 RobotPose robotPose; /**< A dummy robot pose for the image processor. */ 00115 BallModel ballModel; /**< A dummy ball model for the image processor. */ 00116 PlayerPoseCollection playerPoseCollection; /**< A dummy player pose collection for the image processor. */ 00117 RobotState robotState; /**< A dummy robot state for the image processor. */ 00118 CalibrationRequest calibrationRequest; /**< A dummy calibration request for the image processor. */ 00119 LandmarksPercept landmarksPercept; /**< A dummy landmark percept for the image processor. */ 00120 BallPercept ballPercept; /**< A dummy ball percept for the image processor. */ 00121 LinesPercept linesPercept; /**< The lines percept that will be returned by image processor. */ 00122 EdgesPercept edgesPercept; /**< The edges percept that will be returned by image processor. */ 00123 PlayersPercept playersPercept; /**< A dummy players percept for the image processor. */ 00124 ObstaclesPercept obstaclesPercept; /**< A dummy obstacles percept for the image processor. */ 00125 SpecialPercept specialPercept; /**< A dummy special percept for the image processor. */ 00126 GT2004ImageProcessor imageProcessor; /**< The standard image processor used for calibration. */ 00127 RingBuffer<SensorData, 16> buffer; /**< A buffer for the sensor data of the previous 16 frames. */ 00128 Image imageBuffer; /**< A buffer for the previous image. */ 00129 enum 00130 { 00131 #ifdef _WIN32 00132 numOfIndividuals = 100, /**< The number of individuals in the population. */ 00133 #else 00134 numOfIndividuals = 15, /**< The number of individuals in the population. */ 00135 #endif 00136 waitPerGeneration = 10000 /**< The time to wait per generation in ms. */ 00137 }; 00138 BBPopulation<CalibrationIndividual> population; /**< The population of individuals. */ 00139 Vector2<double> fitness[numOfIndividuals]; /**< The accumulated (temporary) fitnesses of the individuals. */ 00140 int evolutions, /**< A counter for the number of evolutions. */ 00141 count[numOfIndividuals]; /**< Variables that count how many fitnesses have been accumulated in "fitnesses". */ 00142 unsigned timeStamp; /**< The beginning of the current evaluation of the individuals. */ 00143 00144 /** 00145 * The function performs a single evolution step. 00146 * @param sensorData The sensor data with the same time stamp as the image in "imageBuffer". 00147 */ 00148 void evolve(const SensorData& sensorData); 00149 }; 00150 #endif// __BB2004Calibrator_h_ 00151 00152 /* 00153 * Change log : 00154 * 00155 * $Log: BB2004Calibrator.h,v $ 00156 * Revision 1.5 2004/09/08 14:39:03 wachter 00157 * - Fixed some doxygen-errors 00158 * 00159 * Revision 1.4 2004/07/16 07:19:32 roefer 00160 * LinesTables removed (it was replaced by LinesTables2004) 00161 * 00162 * Revision 1.3 2004/06/15 10:58:27 thomas 00163 * added edge-specialist, edges-percept, debug-drawings etc. (not yet called from image-processor) 00164 * 00165 * Revision 1.2 2004/05/22 22:52:02 juengel 00166 * Renamed ballP_osition to ballModel. 00167 * 00168 * Revision 1.1.1.1 2004/05/22 17:20:52 cvsadm 00169 * created new repository GT2004_WM 00170 * 00171 * Revision 1.8 2004/05/04 13:56:55 tim 00172 * added GT2004ImageProcessor 00173 * 00174 * Revision 1.7 2004/04/09 11:35:52 roefer 00175 * Bremen Byters German Open check-in 00176 * 00177 * Revision 1.6 2004/03/13 17:20:43 roefer 00178 * Different parameters for simulation and real robot 00179 * 00180 * Revision 1.5 2004/03/13 17:14:36 roefer 00181 * Different parameters for simulation and real robot 00182 * 00183 * Revision 1.4 2004/03/11 00:06:18 roefer 00184 * Parameter tuning 00185 * 00186 * Revision 1.3 2004/03/10 07:59:26 roefer 00187 * New head control mode 00188 * 00189 * Revision 1.2 2004/03/08 02:11:49 roefer 00190 * Interfaces should be const 00191 * 00192 * Revision 1.1 2004/03/04 23:00:54 roefer 00193 * Added (so far empty) BB2004Calibrator 00194 * 00195 */