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

Representations/Perception/LandmarksPercept.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Representations/Perception/LandmarksPercept.cpp
00003  *
00004  * Contains the implementation of class LandmarksPercept.
00005  *
00006  * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A>
00007  * @author <A href=mailto:asbre01@tzi.de>Andreas Sztybryc</A>
00008  */ 
00009 
00010 #include "Tools/Streams/InOut.h"
00011 #include "Tools/FieldDimensions.h"
00012 #include "LandmarksPercept.h"
00013 
00014 
00015 enum FlagType
00016 {
00017   pinkAboveYellow, pinkAboveSkyblue, 
00018   yellowAbovePink, skyblueAbovePink
00019 };
00020     
00021 colorClass Flag::getLowerColor() const
00022 {
00023   switch(type)
00024   {
00025     case pinkAboveYellow:
00026       return yellow;
00027     case pinkAboveSkyblue:
00028       return skyblue;
00029     default:
00030       return pink;
00031   }
00032 }
00033 
00034 colorClass Flag::getUpperColor() const
00035 {
00036   switch(type)
00037   {
00038     case yellowAbovePink:
00039       return yellow;
00040     case skyblueAbovePink:
00041       return skyblue;
00042     default:
00043       return pink;
00044   }
00045 }
00046 
00047 LandmarksPercept::LandmarksPercept()
00048 {
00049   reset(0);  
00050 }
00051 
00052 void LandmarksPercept::reset(unsigned long frameNumber)
00053 {  
00054   this->frameNumber = frameNumber;
00055   numberOfFlags = numberOfGoals = 0;
00056 }
00057 
00058 void LandmarksPercept::addFlag(Flag::FlagType type, 
00059                                const Vector2<double>& position,
00060                                const ConditionalBoundary& boundary)
00061 {
00062   if(numberOfFlags < 4)
00063   {
00064     flags[numberOfFlags].type = type;
00065     flags[numberOfFlags].position = position;
00066     (ConditionalBoundary&) flags[numberOfFlags++] = boundary;
00067   }
00068 }
00069 
00070 
00071 
00072 void LandmarksPercept::addFlag
00073 (
00074  Flag::FlagType type,
00075  bool ownTeamColorIsBlue,
00076  const ConditionalBoundary& boundary
00077  )
00078 {
00079   if(numberOfFlags < 4)
00080   {
00081     Vector2<double> flagPosition;
00082 
00083     int flip = ownTeamColorIsBlue ? -1 : 1;
00084 
00085     switch (type)
00086     {
00087     case Flag::pinkAboveYellow:
00088       flagPosition.x = xPosBackFlags * flip;
00089       flagPosition.y = yPosRightFlags * flip;
00090       break;
00091     case Flag::pinkAboveSkyblue:
00092       flagPosition.x = xPosFrontFlags * flip;
00093       flagPosition.y = yPosRightFlags * flip;
00094       break;
00095     case Flag::yellowAbovePink:
00096       flagPosition.x = xPosBackFlags * flip;
00097       flagPosition.y = yPosLeftFlags * flip;
00098       break;
00099     case Flag::skyblueAbovePink:
00100       flagPosition.x = xPosFrontFlags * flip;
00101       flagPosition.y = yPosLeftFlags * flip;
00102       break;
00103     }
00104 
00105     flags[numberOfFlags].type = type;
00106     flags[numberOfFlags].position = flagPosition;
00107     (ConditionalBoundary&) flags[numberOfFlags++] = boundary;
00108   }
00109 }
00110 
00111 void LandmarksPercept::estimateOffsetForFlags
00112 (
00113  const Vector2<double>& cameraOffset
00114  )
00115 {
00116   for(int i = 0; i < numberOfFlags; ++i)
00117   {
00118     Flag& flag = flags[i];
00119 
00120     /** @todo improve, isOnBorder(flag.x.?) not checked */
00121     double distance;
00122     double direction = flag.x.getCenter();
00123 
00124     if(!flag.isOnBorder(flag.y.min) && !flag.isOnBorder(flag.y.max))
00125     {
00126       if(flag.y.min != flag.y.max)
00127       {
00128         distance = flagHeight / (tan(flag.y.max) - tan(flag.y.min)) + flagRadius;
00129         flag.distanceValidity = 0.8;
00130       }
00131       else
00132       {
00133         distance = 4500;
00134         flag.distanceValidity = 0.05;
00135       }
00136     }
00137     else
00138     {
00139       distance = flagRadius / sin(flag.x.getSize() / 2);
00140       if(!flag.isOnBorder(flag.x.min) && !flag.isOnBorder(flag.x.max)) // Flag touches no vertical border
00141         flag.distanceValidity = 0.7;
00142       else
00143         flag.distanceValidity = 0.2;
00144     }
00145 
00146     if(!flag.isOnBorder(flag.x.min) && !flag.isOnBorder(flag.x.max)) // Flag touches no vertical border
00147       flag.angleValidity = 0.8;
00148     else
00149       flag.angleValidity = 0.7;
00150     
00151     Pose2D p = Pose2D(cameraOffset) + Pose2D(direction) 
00152                        + Pose2D(Vector2<double>(distance,0));
00153 //    flag.distance = p.translation.abs();
00154 //    flag.angle = atan2(p.translation.y,p.translation.x);
00155 
00156       flag.distance = p.translation.abs();
00157       flag.angle = direction;
00158     
00159        
00160     if (flag.distance > 6000)
00161     {
00162       flag.distance = 6000;
00163       flag.distanceValidity=0; // flags far away are meassured very bad
00164     }
00165     else if (flag.distance > 3000) 
00166       flag.distanceValidity*=0.5; // flags medium far away are meassured medium bad
00167   }
00168 }
00169 
00170 void LandmarksPercept::addGoal(colorClass color,
00171                                const Vector2<double>& leftPost,
00172                                const Vector2<double>& rightPost,
00173                                const ConditionalBoundary& boundary)
00174 {
00175   if(numberOfGoals < 2)
00176   {
00177     goals[numberOfGoals].color = color;
00178     goals[numberOfGoals].leftPost = leftPost;
00179     goals[numberOfGoals].rightPost = rightPost;
00180     (ConditionalBoundary&) goals[numberOfGoals++] = boundary;
00181   }
00182 }
00183 
00184 void LandmarksPercept::addGoal
00185 (
00186  colorClass color,
00187  bool ownTeamColorIsBlue,
00188  const ConditionalBoundary& boundary
00189  )
00190 {
00191   if(numberOfGoals < 2)
00192   {
00193     int flip = ownTeamColorIsBlue ? -1 : 1;
00194     Vector2<double>leftGoalPost, rightGoalPost;
00195     switch (color)
00196     {
00197     case yellow:
00198       leftGoalPost.x = xPosOwnGoalpost * flip;
00199       leftGoalPost.y = yPosRightGoal * flip;
00200       rightGoalPost.x = xPosOwnGoalpost * flip;
00201       rightGoalPost.y = yPosLeftGoal * flip;
00202       break;
00203     case skyblue:
00204       leftGoalPost.x = xPosOpponentGoalpost * flip;
00205       leftGoalPost.y = yPosLeftGoal * flip;
00206       rightGoalPost.x = xPosOpponentGoalpost * flip;
00207       rightGoalPost.y = yPosRightGoal* flip;
00208       break;
00209     }
00210     goals[numberOfGoals].color = color;
00211     goals[numberOfGoals].leftPost = leftGoalPost;
00212     goals[numberOfGoals].rightPost = rightGoalPost;
00213     (ConditionalBoundary&) goals[numberOfGoals++] = boundary;
00214   }
00215 }
00216 
00217 void LandmarksPercept::estimateOffsetForGoals
00218 (
00219   const Vector2<double>& cameraOffset
00220 )
00221 {
00222   for (int i = 0; i < numberOfGoals; i++)
00223   {
00224     if(i >= 2)
00225     {
00226       OUTPUT(idText,text,"to many Goals");
00227       numberOfGoals = 2;
00228       return;
00229     }
00230     Goal& goal = goals[i];
00231 
00232     /** @todo distinguish between height of left and right post
00233       * @todo isOnBorder(flag.?.?) not checked
00234       */
00235     double distance;
00236     if(goal.y.max != goal.y.min)
00237       distance = goalHeight / (tan(goal.y.max) - tan(goal.y.min));
00238     else
00239       distance = 10000;
00240     double direction = goal.x.getCenter();
00241     Pose2D p = Pose2D(cameraOffset) + Pose2D(direction) 
00242                        + Pose2D(Vector2<double>(distance,0));
00243     goal.distance = p.translation.abs();
00244 //    goal.angle = atan2(p.translation.y,p.translation.x);
00245     goal.angle = direction;
00246     goal.rotation = 0; // wrong!
00247     if(!goal.isOnBorder(goal.x.min) && !goal.isOnBorder(goal.x.max)) // goal touches no vertical borders
00248     { 
00249       goal.angleValidity = 0.80;
00250       goal.distanceValidity = 0.50;
00251     }
00252     else
00253       if (goal.isOnBorder(goal.x.min) && goal.isOnBorder(goal.x.max)) // goal touches both vertical borders
00254       {
00255         goal.angleValidity = 0.20;
00256         goal.distanceValidity = 0.10;
00257       }
00258       else
00259       {
00260         goal.angleValidity = 0.5;
00261         goal.distanceValidity = 0.15;
00262       }
00263 
00264     if (goal.distance > 6000)
00265     {
00266       goal.distance = 6000;
00267       goal.distanceValidity=0; // goals far away are meassured very bad
00268     }
00269     else if (goal.distance > 3000) 
00270       goal.distanceValidity*=0.5; // goals medium far away are meassured medium bad
00271 
00272   }
00273 }
00274 
00275 
00276 In& operator>>(In& stream,LandmarksPercept& landmarksPercept)
00277 {
00278   stream >> landmarksPercept.frameNumber;
00279   stream.read(&landmarksPercept.numberOfFlags,sizeof(int));
00280   stream.read(&landmarksPercept.flags,sizeof(Flag) * landmarksPercept.numberOfFlags);
00281   stream.read(&landmarksPercept.numberOfGoals,sizeof(int));
00282   stream.read(&landmarksPercept.goals,sizeof(Goal) * landmarksPercept.numberOfGoals);
00283   stream.read(&landmarksPercept.cameraOffset,sizeof(landmarksPercept.cameraOffset));
00284   return stream;
00285 }
00286 
00287 Out& operator<<(Out& stream, const LandmarksPercept& landmarksPercept)
00288 {
00289   stream << landmarksPercept.frameNumber;
00290   stream.write(&landmarksPercept.numberOfFlags,sizeof(int));
00291   stream.write(&landmarksPercept.flags,sizeof(Flag) * landmarksPercept.numberOfFlags);
00292   stream.write(&landmarksPercept.numberOfGoals,sizeof(int));
00293   stream.write(&landmarksPercept.goals,sizeof(Goal) * landmarksPercept.numberOfGoals);
00294   stream.write(&landmarksPercept.cameraOffset,sizeof(landmarksPercept.cameraOffset));
00295 
00296   return stream;
00297 }
00298 
00299 /*
00300  * Change log :
00301  * 
00302  * $Log: LandmarksPercept.cpp,v $
00303  * Revision 1.2  2004/06/17 14:34:46  dassler
00304  * GT2004HeadControl updated
00305  * Now looks after propergated ball, followed up withe the communicated ball
00306  * GT2004HeadPathPlanner work now with time optimized moves
00307  * Middle Beacons removed of the Landmarkspercept
00308  *
00309  * Revision 1.1.1.1  2004/05/22 17:25:51  cvsadm
00310  * created new repository GT2004_WM
00311  *
00312  * Revision 1.3  2004/01/19 14:53:46  dueffert
00313  * all frameNumbers (and not only some of them) are unsigned long now
00314  *
00315  * Revision 1.2  2003/11/12 16:19:35  goehring
00316  * frameNumber added to percepts
00317  *
00318  * Revision 1.1  2003/10/07 10:09:36  cvsadm
00319  * Created GT2004 (M.J.)
00320  *
00321  * Revision 1.2  2003/09/26 15:27:27  juengel
00322  * Renamed DataTypes to representations.
00323  *
00324  * Revision 1.1.1.1  2003/07/02 09:40:22  cvsadm
00325  * created new repository for the competitions in Padova from the 
00326  * tamara CVS (Tuesday 2:00 pm)
00327  *
00328  * removed unused solutions
00329  *
00330  * Revision 1.7  2003/03/22 16:53:10  juengel
00331  * Added estimateOffsetForGoals.
00332  *
00333  * Revision 1.6  2003/03/15 13:28:01  juengel
00334  * Added  void addGoal(colorClass color,  bool ownTeamColorIsBlue,  const ConditionalBoundary& boundary);
00335  *
00336  * Revision 1.5  2003/03/07 11:35:01  juengel
00337  * removed  smoothedDistance;
00338  *
00339  * added void addFlag(Flag::FlagType type, bool ownTeamColorIsBlue, const ConditionalBoundary& boundary);
00340  * added void LandmarksPercept::estimateOffsetForFlags()
00341  *
00342  * Revision 1.4  2002/10/14 13:14:24  dueffert
00343  * doxygen comments corrected
00344  *
00345  * Revision 1.3  2002/09/22 18:40:49  risler
00346  * added new math functions, removed GTMath library
00347  *
00348  * Revision 1.2  2002/09/17 23:55:20  loetzsch
00349  * - unraveled several datatypes
00350  * - changed the WATCH macro
00351  * - completed the process restructuring
00352  *
00353  * Revision 1.1  2002/09/10 15:26:40  cvsadm
00354  * Created new project GT2003 (M.L.)
00355  * - Cleaned up the /Src/DataTypes directory
00356  * - Removed Challenge Code
00357  * - Removed processing of incoming audio data
00358  * - Renamed AcousticMessage to SoundRequest
00359  *
00360  * Revision 1.2  2002/08/30 13:33:05  dueffert
00361  * removed unused includes
00362  *
00363  * Revision 1.1.1.1  2002/05/10 12:40:13  cvsadm
00364  * Moved GT2002 Project from ute to tamara.
00365  *
00366  * Revision 1.6  2002/04/23 15:20:18  roefer
00367  * Number of goals and landmarks limited
00368  *
00369  * Revision 1.5  2002/04/02 13:10:18  dueffert
00370  * big change: odometryData and cameraMatrix in image now, old logfiles may be obsolete
00371  *
00372  * Revision 1.4  2002/02/13 22:43:02  roefer
00373  * First working versions of DefaultLandmarksPerceptor and MonteCarloSelfLocator
00374  *
00375  * Revision 1.3  2002/02/12 09:45:17  roefer
00376  * Progress in DefaultLandmarksPerceptor and MonteCarloSelfLocator
00377  *
00378  * Revision 1.2  2002/02/06 10:30:11  AndySHB
00379  * MonteCarloLocalization First Draft
00380  *
00381  * Revision 1.3  2001/12/10 17:47:06  risler
00382  * change log added
00383  *
00384  */

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