00001 /** 00002 * @file ObstaclesModel.h 00003 * 00004 * Declaration of class ObstaclesModel 00005 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a> 00006 */ 00007 00008 #ifndef __ObstaclesModel_h_ 00009 #define __ObstaclesModel_h_ 00010 00011 00012 #include "Tools/Streams/InOut.h" 00013 #include "Tools/Math/Common.h" 00014 #include "Tools/Debugging/Debugging.h" 00015 00016 #include "Representations/Perception/ObstaclesPercept.h" 00017 00018 /** 00019 * A class describing the distance to obstacles around the robot, 00020 */ 00021 class ObstaclesModel 00022 { 00023 public: 00024 ObstaclesModel(); 00025 ~ObstaclesModel(); 00026 00027 /** copies another ObstaclesModel to this one */ 00028 void operator = (const ObstaclesModel& other); 00029 00030 enum Directions{ back, backRight, right, frontRight, front, frontLeft, left, backLeft, numberOfDirections}; 00031 enum SearchDirections{searchLeft, searchLeftAndRight, searchRight}; 00032 enum { numOfSectors = 90 , maxDistance = 1500}; 00033 00034 /** 00035 * return the center angle of a given sector 00036 */ 00037 static double getAngleOfSector(int sector) 00038 { 00039 // if(sector < numOfSectors && 0 <= sector) 00040 // { 00041 return -pi + ((double)sector + 0.5) * pi2 / numOfSectors; 00042 // } 00043 // else 00044 // { 00045 // OUTPUT(idText, text, "sector out of range"); 00046 // return 0; 00047 // } 00048 } 00049 00050 /** the frame number when perceived */ 00051 unsigned long frameNumber; 00052 00053 void setFrameNumber(unsigned long frameNumber) {this->frameNumber = frameNumber;} 00054 00055 /** the distance to the closest obstacle in an angular sector */ 00056 int distance[numOfSectors]; 00057 00058 /** */ 00059 ObstaclesPercept::ObstacleType obstacleType[numOfSectors]; 00060 00061 /** the distance to the closest obstacle in a rectangular corridor in front of the robot */ 00062 int corridorInFront; 00063 00064 00065 /** returns the distance to the closest obstacle 00066 * in the corridor specified by angle and width */ 00067 double getDistanceInCorridor(double angle, double width) const; 00068 00069 /** returns the angle of the closest free sector with angle sizeOfSector 00070 * relative to angle. Free means free up to minDistance */ 00071 double getAngleOfNextFreeSector(double sizeOfSector, double angle, int minDistance) const; 00072 00073 /** returns the angle of the closest free with angle sizeOfSector 00074 * relative to angle. Free means free up to minDistance */ 00075 double getAngleOfNextFreeSectorLeft(double sizeOfSector, double angle, int minDistance) const; 00076 double getAngleOfNextFreeSectorRight(double sizeOfSector, double angle, int minDistance) const; 00077 00078 /** Calculates the angle with the farsest distance to an obstacle between the front direction and the angle. 00079 * Returns the distance. 00080 */ 00081 // int getBestAngleBetweenFrontAndDestination(double sizeOfSector, double angle, double& bestAngle) const; 00082 00083 /** 00084 * returns the distance to the closest obstacle 00085 * in one of the major directions defined above */ 00086 int getDistanceInMajorDirection(Directions direction) const; 00087 00088 /** 00089 * return the distance to the closest obstacle 00090 * in a given direction and a given opening angle */ 00091 int getDistanceInDirection(double direction, double openingAngle) const; 00092 00093 /** 00094 * sums up all distances in a sector specified by direction and opening angle; 00095 * the maxDist(ance) specifies what the maximum distance should be when 00096 * adding up (you don't want really big single values to distort the sum) */ 00097 double getTotalFreeSpaceInSector(double direction, double openingAngle, double maxDist) const; 00098 00099 /** Calculates the angle with the closest distance to an obstacle. 00100 * Returns the distance. 00101 */ 00102 int getMinimalDistanceInRange(double centerAngle, double openingAngle, double& angleWithMinimalDistance) const; 00103 00104 /** Calculates the angle with the closest distance to an obstacle of a certain obstacle type. 00105 * Returns the distance. 00106 */ 00107 int getMinimalDistanceInRange(double centerAngle, double openingAngle, double& angleWithMinimalDistance, ObstaclesPercept::ObstacleType obstacleType) const; 00108 00109 /** Calculates the percentage of sectors with obstacles that are closer than the specified distance in the specified range. 00110 */ 00111 double getPercentageOfLowDistanceObstaclesInRange(double centerAngle, double openingAngle, int maxDistance) const; 00112 00113 /** Calculates the angle with the farsest distance to an obstacle. 00114 * Returns the angle. 00115 */ 00116 double getAngleOfLargeGapInRange(double centerAngle, double openingAngle, SearchDirections searchDirection) const; 00117 00118 /** Calculates the angle with the farsest distance to an obstacle. 00119 * Returns the angle. 00120 */ 00121 double getAngleOfLargeGapInRange2(double centerAngle, double openingAngle, SearchDirections searchDirection) const; 00122 00123 /** 00124 * return the corresponding sector to a given angle 00125 */ 00126 static int getSectorFromAngle(double angle) 00127 { 00128 return (int)((normalize(angle) + pi) / pi2 * numOfSectors); 00129 } 00130 00131 enum{ownGoal = 0, opponentGoal = 1}; 00132 bool angleToFreePartOfGoalWasDetermined[2]; 00133 double angleToFreePartOfGoal[2]; 00134 double widthOfFreePartOfGoal[2]; 00135 double distanceToFreePartOfGoal[2]; 00136 00137 bool angleToNextFreeTeammateWasDetermined; 00138 double angleToNextFreeTeammate; 00139 double distanceToNextFreeTeammate; 00140 00141 /** 00142 * last value of the body psd sensor (if present) 00143 */ 00144 double bodyPSD; 00145 }; 00146 00147 /** 00148 * Streaming operator that reads a ObstaclesModel from a stream. 00149 * @param stream The stream from which is read. 00150 * @param obstaclesModel The ObstaclesModel object. 00151 * @return The stream. 00152 */ 00153 In& operator>>(In& stream,ObstaclesModel& obstaclesModel); 00154 00155 /** 00156 * Streaming operator that writes a ObstaclesModel to a stream. 00157 * @param stream The stream to write on. 00158 * @param obstaclesModel The ObstaclesModel object. 00159 * @return The stream. 00160 */ 00161 Out& operator<<(Out& stream, const ObstaclesModel& obstaclesModel); 00162 00163 00164 #endif //__ObstaclesModel_h_ 00165 00166 /* 00167 * Change log : 00168 * 00169 * $Log: ObstaclesModel.h,v $ 00170 * Revision 1.3 2004/07/02 15:57:00 thomas 00171 * fix comment of function-signature 00172 * 00173 * Revision 1.2 2004/06/16 14:43:51 risler 00174 * added obstacles symbols 00175 * added symbol obstacles.opponent-close-to-ball 00176 * 00177 * Revision 1.1.1.1 2004/05/22 17:25:15 cvsadm 00178 * created new repository GT2004_WM 00179 * 00180 * Revision 1.7 2004/03/16 14:00:21 juengel 00181 * Integrated Improvments from "Günne" 00182 * -ATH2004ERS7Behavior 00183 * -ATHHeadControl 00184 * -KickSelectionTable 00185 * -KickEditor 00186 * 00187 * Revision 1.6 2004/03/10 14:16:33 risler 00188 * body psd value added to PSDPercept and ObstaclesModel 00189 * 00190 * Revision 1.2 2004/03/15 17:11:40 hoffmann 00191 * - added ATH2004HeadControl 00192 * - added ATH2004LEDControl 00193 * - headmotiontester shows "tilt2" 00194 * - motion process updates odometry while no new robotPose is received, added to motion request 00195 * - some ui adjustments 00196 * - added member function to "field" to find out if robot is in own penalty area for use in the obstacles locator 00197 * 00198 * Revision 1.5 2004/03/01 11:45:49 juengel 00199 * Moved enum ObstacleType to class ObstaclesPercept. 00200 * 00201 * Revision 1.4 2004/02/28 13:56:13 juengel 00202 * Added ObstacleType. 00203 * Reduced number of sectors to 60. 00204 * 00205 * Revision 1.3 2004/01/19 14:55:23 dueffert 00206 * all frameNumbers (and not only some of them) are unsigned long now 00207 * 00208 * Revision 1.2 2003/11/14 19:02:25 goehring 00209 * frameNumber added 00210 * 00211 * Revision 1.1 2003/10/07 10:07:01 cvsadm 00212 * Created GT2004 (M.J.) 00213 * 00214 * Revision 1.2 2003/07/03 18:13:35 dassler 00215 * Adding two Methods: 00216 * getAngleOfNextFreeSectorLeft 00217 * getAngleOfNextFreeSectorRight 00218 * 00219 * Copy of getAngleOfNextFreeSector 00220 * 00221 * Revision 1.1.1.1 2003/07/02 09:40:22 cvsadm 00222 * created new repository for the competitions in Padova from the 00223 * tamara CVS (Tuesday 2:00 pm) 00224 * 00225 * removed unused solutions 00226 * 00227 * Revision 1.18 2003/06/29 08:40:17 roefer 00228 * Warnings removed 00229 * 00230 * Revision 1.17 2003/06/27 15:10:15 juengel 00231 * Added getAngleOfLargeGapInRange2 which uses minimum instead of sum. 00232 * 00233 * Revision 1.16 2003/06/27 13:17:57 jhoffman 00234 * work on obstacle avoider challenge, 00235 * added headcontrolmode, 00236 * added method needed to determine empty space, 00237 * updatet drawing method to reflect actual corridor size 00238 * 00239 * Revision 1.15 2003/06/26 12:35:25 juengel 00240 * getAngleOfLargeGapInRange has search direction. 00241 * 00242 * Revision 1.14 2003/06/21 12:55:41 juengel 00243 * Added getPercentageOfLowDistanceObstaclesInRange. 00244 * 00245 * Revision 1.13 2003/06/20 20:13:01 juengel 00246 * Renamed some methods. 00247 * 00248 * Revision 1.12 2003/06/20 13:59:17 juengel 00249 * Added minimalDistanceInRange. 00250 * 00251 * Revision 1.11 2003/06/19 12:10:43 juengel 00252 * Added getBestAngle 00253 * 00254 * Revision 1.10 2003/06/18 18:30:43 juengel 00255 * no message 00256 * 00257 * Revision 1.9 2003/06/17 20:01:22 juengel 00258 * Renamed getNextFreeSector to getAngleOfNextFreeSector. 00259 * 00260 * Revision 1.8 2003/06/05 08:14:28 juengel 00261 * Added getDistanceInCorridor and getNextFreeSector. 00262 * 00263 * Revision 1.7 2003/06/03 15:50:04 risler 00264 * added getDistanceInDirection 00265 * minor optimizations 00266 * 00267 * Revision 1.6 2003/05/26 08:29:57 juengel 00268 * Added angleToFreePartOfGoal and angle to nextFreeTeammate. 00269 * 00270 * Revision 1.5 2003/05/15 00:56:48 risler 00271 * added functions for sector to angle mapping to ObstaclesModel 00272 * sector to angle mapping unified 00273 * added rule AvoidObstacles 00274 * 00275 * Revision 1.4 2003/05/14 13:08:38 risler 00276 * removed DefaultObstaclesLocator 00277 * renamed MicroSectorsObstaclesLocator to DefaultObstaclesLocator 00278 * ObstaclesModel contains increased number of sectors 00279 * DefaultObstaclesLocator clean up 00280 * 00281 * Revision 1.3 2003/04/14 16:01:41 loetzsch 00282 * ATH after GermanOpen CVS merge: 00283 * added corridor to obstacle model 00284 * 00285 * Revision 1.2 2003/04/10 14:14:47 Jan Hoffmann 00286 * added corridor to obstacle model 00287 * 00288 * Revision 1.1.1.1 2003/04/09 14:22:16 loetzsch 00289 * started Aibo Team Humboldt's GermanOpen CVS 00290 * 00291 * Revision 1.2 2003/03/11 11:29:20 juengel 00292 * Added data and constructor 00293 * 00294 * Revision 1.1 2003/03/10 13:52:30 juengel 00295 * Added ObstaclesModel 00296 * 00297 */