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

Modules/ImageProcessor/RasterImageProcessor/RFieldStateMachine.h

Go to the documentation of this file.
00001 /**
00002 * @file RFieldStateMachine.h
00003 * 
00004 * This file contains the definition of class RFieldStateMachine.
00005 *
00006 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a>
00007 */
00008 #ifndef _RFieldStateMachine_h_
00009 #define _RFieldStateMachine_h_
00010 
00011 
00012 #include "Modules/ImageProcessor/RasterImageProcessor/REdgeDetection.h"
00013 
00014 /**
00015 * @class RFieldStateMachine
00016 *
00017 * This class represents a deterministic state machine.
00018 * The machine has the ability to determine
00019 * the object-type of an edge-point found on
00020 * the field.
00021 * The scans should go from the horizon to the ground.
00022 * It is not really needed to scan perpendicular to the
00023 * horizon.
00024 * The machine is reading from the buffers of the edgeDetection
00025 * and changes its states automaticly. For this the client should
00026 * call reset() before every scan and then use a buffered scan to
00027 * an edge to fill the buffer. After this call update() to update
00028 * the state of the machine and continue the scan. So the client has
00029 * to call update() after an edge is found or the scan is finished.
00030 *
00031 *
00032 * @author <A href=mailto:sadprofessor@web.de>Bernd Schmidt</A>
00033 */
00034 class RFieldStateMachine 
00035 {
00036     
00037 public:
00038   
00039   /** Different point types.*/
00040   enum PointTypes {
00041     nothing = 0,
00042     blueRobot,
00043     redRobot,
00044     border,
00045     line,
00046     ball,
00047     skyblueGoal,
00048     yellowGoal,
00049     unknown,
00050     numberOfPointTypes
00051   };
00052 
00053   /** The different states.*/
00054   enum FIELD_STATES{
00055     START = 0,
00056     FOUND_WHITE,
00057     FOUND_FIELD,
00058     FOUND_BORDER,
00059     LINE_IN,
00060     LINE_OUT,
00061     YELLOW_GOAL,
00062     YELLOW_FINISHED,
00063     SKYBLUE_GOAL,
00064     SKYBLUE_FINISHED,
00065     FOUND_RED_ROBOT,
00066     FOUND_BLUE_ROBOT,
00067     FINISHED_BLUE_ROBOT,
00068     FINISHED_RED_ROBOT,
00069     FOUND_BALL,
00070     FINISHED_BALL,
00071     FOUND_UNKNOWN,
00072     FINISHED_UNKNOWN
00073   };
00074   
00075   /** Constructor */
00076   RFieldStateMachine();
00077   /** Destructor */
00078   ~RFieldStateMachine();
00079 
00080   /** Updates the state machine after a scan.
00081   * 
00082   *   @param x current x-coordinate.  
00083   *   @param y current y-coordinate.
00084   *   @param scanner Reference of the edge scanner.
00085   */
00086   void update(int x,int y,REdgeDetection& scanner);
00087   /** Resets the state machine. The first point is setted to (x,y).
00088   *   
00089   *   @param x x-coordinate
00090   *   @param y y-coordinate
00091   */
00092   void reset(int x,int y);
00093   /** Returns one of the detected edge points.
00094   *   
00095   *   @param index The index of the point.
00096   *   @return The edge point as Vector2<int>
00097   */
00098   inline Vector2<int> getEdge(int index){
00099     return edgeBuffer[index];
00100   }
00101   /** Returns the type of one of the detected edge points.
00102   *   
00103   *   @param index The index of the point.
00104   *   @return The type of a edge point.
00105   */
00106   inline PointTypes getType(int index){
00107     return types[index];
00108   }
00109   /** Returns the number of edges found after the last reset.
00110   *   @return Number of edge points.
00111   */
00112   inline int size(){
00113     return numberOfEdges;
00114   }
00115   /** Tells if the machine determined a obstacle and its free space.
00116   *   @return True, if the machine determined a obstacle after the last reset.
00117   */
00118   inline bool foundObstacle(){
00119     return obstacleNearPoint != -1 && obstacleFarPoint != -1;
00120   }
00121   /** Returns the near point of the detected obstacle space.
00122   *   @return The near obstacle point.
00123   */
00124   inline Vector2<int>& nearPoint(){
00125     return edgeBuffer[obstacleNearPoint];
00126   }
00127   /** Returns the far point of the detected obstacle space.
00128   *   @return The far obstacle point.
00129   */
00130   inline Vector2<int>& farPoint(){
00131     return edgeBuffer[obstacleFarPoint];
00132   }
00133   /** Returns the type of the obstacle.
00134   *   @return The obstacle type.
00135   */
00136   inline ObstaclesPercept::ObstacleType getObstacleType(){
00137     switch (types[obstacleFarPoint]){
00138     case blueRobot: 
00139       if(getPlayer().getTeamColor() == Player::blue) 
00140           return ObstaclesPercept::teammate;
00141       else
00142         return ObstaclesPercept::opponent;
00143       
00144     case redRobot:
00145       if(getPlayer().getTeamColor() == Player::red)
00146           return ObstaclesPercept::teammate;
00147       else
00148         return ObstaclesPercept::opponent;
00149     case border:    return ObstaclesPercept::border;
00150     case yellowGoal: return ObstaclesPercept::goal;
00151     case skyblueGoal: return ObstaclesPercept::goal;
00152     case unknown: return ObstaclesPercept::unknown;
00153     default: return ObstaclesPercept::unknown;      
00154     }
00155   }
00156 
00157 private :
00158 
00159   /** Calculates the next state.*/
00160   void findNextState();
00161   /** Executes the active state.*/
00162   void executeState();
00163   /** Current color.*/
00164   colorClass color;
00165   /** The range between the last two edges.*/
00166   int range;
00167   /** The sum of ranges since the last reset.*/
00168   int rangeSum;
00169   /** The sum of the green range.*/
00170   int greenRange;
00171   /** The sum of the white range.*/
00172   int whiteRange;
00173   /** The sum of the gray range.*/
00174   int grayRange;
00175   /** Temporary variable.*/
00176   bool isUnknownBot;
00177   /** The edge buffer.*/
00178   Vector2<int> edgeBuffer[20];
00179   /** The start point stored at the last reset*/
00180   Vector2<int> start;
00181   /** The type buffer.*/
00182   PointTypes types[20];
00183   /** The active state.*/
00184   FIELD_STATES state;
00185   /** The number of edges found since last reset.*/
00186   int numberOfEdges;
00187   /** The far point of the obstacle.*/
00188   int obstacleFarPoint;
00189   /** The near point of the obstacle.*/
00190   int obstacleNearPoint;
00191 
00192 };
00193 
00194 #endif   //  _RFieldStateMachine_h_
00195 
00196 /*
00197 * Change log :
00198 * 
00199 * $Log: RFieldStateMachine.h,v $
00200 * Revision 1.6  2004/09/09 11:08:05  spranger
00201 * renamed GT2004EdgeDetection to REdgeDetection for consistency
00202 * 
00203 * Revision 1.5  2004/09/09 10:15:55  spranger
00204 * fixed doxygen-errors
00205 * 
00206 * Revision 1.4  2004/09/06 12:02:25  schmidtb
00207 * commented almost all members, removed warnings in documentation
00208 
00209 * did further code clean up
00210 * 
00211 * Revision 1.3  2004/09/02 07:59:29  schmidtb
00212 * Added RasterImageProcessor to repository, because we used it for the OpenChallenge.
00213 * 
00214 * Revision 1.3  2004/05/25 13:27:33  schmidtb
00215 * modified version of rip for open-challenge
00216 * 
00217 * Revision 1.2  2004/03/25 15:29:04  pg_besc
00218 * made some changes
00219 * 
00220 * Revision 1.1  2004/03/17 22:12:39  schmidtb
00221 * established RFieldStateMachine
00222 * 
00223 *
00224 */

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