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

Tools/KickSelectionTable.h

Go to the documentation of this file.
00001 /** 
00002 * @file KickSelectionTable.h
00003 * Declaration of class KickSelectionTable.
00004 *
00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
00006 * @author Martin Lötzsch
00007 */
00008 
00009 #ifndef _KickSelectionTable_h_
00010 #define _KickSelectionTable_h_
00011 
00012 #include "Tools/Math/Vector2.h"
00013 #include "Platform/GTAssert.h"
00014 #include "Representations/Motion/MotionRequest.h"
00015 #include "Representations/Cognition/RobotPose.h"
00016 /**
00017 * Represents the results and the preconditions of a single kick experiment
00018 * @author Martin Lötzsch
00019 */
00020 class KickCase
00021 {
00022 public:
00023   /** The relative x position of the ball when the kick was requested */
00024   double ballXR;
00025 
00026   /** The relative y position of the ball when the kick was requested */
00027   double ballYR;
00028 
00029   /** The time since the ball was seen last when the kick was requested */
00030   unsigned long ballTR;
00031 
00032   /** The relative x position of the ball when the kick was started */
00033   double ballXS;
00034 
00035   /** The relative y position of the ball when the kick was started */
00036   double ballYS;
00037 
00038   /** The time since the ball was seen last when the kick was started */
00039   unsigned long ballTS;
00040 
00041   /** The relative x position of the ball after the kick */
00042   double ballXA;
00043 
00044   /** The relative y position of the ball after the kick */
00045   double ballYA;
00046 
00047   /** The time since the kick was finished when the record was written */
00048   unsigned long tA;
00049 
00050 };
00051 
00052 /**
00053 * @class KickSelectionTable
00054 *
00055 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
00056 * @author Martin Lötzsch
00057 *
00058 * Provides for a set of tables which provides a kick selection depending 
00059 * on a desired kick angle and ball position.
00060 */
00061 class KickSelectionTable
00062 {
00063 public:
00064   /** Constructor */
00065   KickSelectionTable();
00066   
00067   /** Destructor */
00068   ~KickSelectionTable();
00069   
00070   /** Ids for all possible actions */
00071   enum ActionID{
00072     nothing = 0,
00073     headLeft,
00074     headRight,
00075     anyLeft,
00076     anyRight,
00077     hookLeft,
00078     hookRight,
00079     leftPaw,
00080     rightPaw,
00081     armLeft,
00082     armRight,
00083     pushSoft,
00084     pushStrong,
00085     chestSoft,
00086     chestStrong,
00087     putRight,
00088     putLeft,
00089     forwardKickFast,
00090     forwardKickHard,
00091     slapRight,
00092     slapLeft,
00093     headLeftSoft,
00094     headRightSoft,
00095     backKickLeft,
00096     backKickRight,
00097     kickAlongArmLeft,
00098     kickAlongArmRight,
00099     bbHeadLeftSoft,
00100     bbHeadLeftStrong,
00101     bbHeadRightSoft,
00102     bbHeadRightStrong,
00103     kickWithBackLegLeft,
00104     kickWithBackLegRight,
00105     numberOfActions
00106   };
00107   
00108   /** returns names for action ids */
00109   static const char* getActionName(ActionID id)
00110   {
00111     switch (id)
00112     {
00113     case nothing: return "nothing";
00114     case headLeft: return "headLeft"; 
00115     case headRight: return "headRight";
00116     case anyLeft: return "anyLeft";
00117     case anyRight: return "anyRight";
00118     case hookLeft: return "hookLeft";
00119     case hookRight: return "hookRight";
00120     case leftPaw: return "leftPaw";
00121     case rightPaw: return "rightPaw";
00122     case armLeft: return "armLeft";
00123     case armRight: return "armRight";
00124     case pushSoft: return "pushSoft";
00125     case pushStrong: return "pushStrong";
00126     case chestSoft: return "chestSoft";
00127     case chestStrong: return "chestStrong";
00128     case putRight: return "putRight";
00129     case putLeft: return "putLeft";
00130     case forwardKickFast: return "forwardKickFast";
00131     case forwardKickHard: return "forwardKickHard";
00132     case slapRight: return "slapRight";
00133     case slapLeft: return "slapLeft";
00134     case headLeftSoft: return "headLeftSoft";
00135     case headRightSoft: return "headRightSoft";
00136     case backKickLeft: return "backKickLeft";
00137     case backKickRight: return "backKickRight";
00138     case kickAlongArmLeft: return "kickAlongArmLeft";
00139     case kickAlongArmRight: return "kickAlongArmRight";
00140     case bbHeadLeftSoft: return "bbHeadLeftSoft";
00141     case bbHeadLeftStrong: return "bbHeadLeftStrong";
00142     case bbHeadRightSoft: return "bbHeadRightSoft";
00143     case bbHeadRightStrong: return "bbHeadRightStrong";
00144     case kickWithBackLegLeft: return "kickWithBackLegLeft";
00145     case kickWithBackLegRight: return "kickWithBackLegRight";
00146     default: return "please edit KickSelectionTable::getActionName";
00147     }
00148   }
00149   
00150   /** returns short names for action ids (used by streaming operator)*/
00151   static const char* getShortActionName(ActionID id)
00152   {
00153     switch (id)
00154     {
00155     case nothing: return "no";
00156     case headLeft: return "head_l"; 
00157     case headRight: return "head_r";
00158     case anyLeft: return "any_l";
00159     case anyRight: return "any_r";
00160     case hookLeft: return "hook_l";
00161     case hookRight: return "hook_r";
00162     case leftPaw: return "l_paw";
00163     case rightPaw: return "r_paw";
00164     case armLeft: return "arm_l";
00165     case armRight: return "arm_r";
00166     case pushSoft: return "push_so";
00167     case pushStrong: return "pu_str";
00168     case chestSoft: return "che_so";
00169     case chestStrong: return "ch_str";
00170     case putRight: return "put_r";
00171     case putLeft: return "put_l";
00172     case forwardKickFast: return "forw_f";
00173     case forwardKickHard: return "forw_h";
00174     case slapRight: return "slap_r";
00175     case slapLeft: return "slap_l";
00176     case headLeftSoft: return "head_sl";
00177     case headRightSoft: return "head_sr";
00178     case backKickLeft: return "back_l";
00179     case backKickRight: return "back_r";
00180     case kickAlongArmLeft: return "along_a_l";
00181     case kickAlongArmRight: return "along_a_r";
00182     case bbHeadLeftSoft: return "bb_h_l";
00183     case bbHeadLeftStrong: return "bb_h_l_s";
00184     case bbHeadRightSoft: return "bb_h_r";
00185     case bbHeadRightStrong: return "bb_h_r_s";
00186     case kickWithBackLegLeft: return "backleg_l";
00187     case kickWithBackLegRight: return "backleg_r";
00188     default: 
00189       ASSERT(false);
00190       return 0;
00191     }
00192   }
00193   
00194   /** IDs for different kick selection tables */
00195   enum KickSelectionTableID
00196   {
00197     inCenterOfField, 
00198     atLeftBorder, 
00199     atRightBorder, 
00200     atLeftOpponentBorder, 
00201     atRightOpponentBorder, 
00202     nearOwnGoal, 
00203     goalie,
00204     whenStuck,
00205     passing,
00206     intentionalKick,
00207     hardKicks,
00208     numberOfKickSelectionTableIDs
00209   };
00210   
00211   /** returns a name for an action table id */
00212   static const char* getKickSelectionTableIDName(KickSelectionTableID id)
00213   {
00214     switch (id)
00215     {
00216     case inCenterOfField: return "inCenterOfField";
00217     case atLeftBorder: return "atLeftBorder";
00218     case atRightBorder: return "atRightBorder";
00219     case atLeftOpponentBorder: return "atLeftOpponentBorder";
00220     case atRightOpponentBorder: return "atRightOpponentBorder";
00221     case nearOwnGoal: return "nearOwnGoal"; 
00222     case goalie: return "goalie";
00223     case whenStuck: return "whenStuck";
00224     case passing: return "passing";
00225     case intentionalKick: return "intentionalKick";
00226     case hardKicks: return "hardKicks";
00227     default: 
00228       ASSERT(false);
00229       return 0;
00230     }
00231   }
00232   
00233   /** Returns an action id for a special action id */
00234   static const ActionID getActionIDFromSpecialActionID(SpecialActionRequest::SpecialActionID id)
00235   {
00236     switch (id)
00237     {
00238       case SpecialActionRequest::headLeft: return headLeft; 
00239       case SpecialActionRequest::headRight: return headRight;
00240       case SpecialActionRequest::anyLeft: return anyLeft;
00241       case SpecialActionRequest::anyRight: return anyRight;
00242       case SpecialActionRequest::hookLeft: return hookLeft;
00243       case SpecialActionRequest::hookRight: return hookRight;
00244       case SpecialActionRequest::leftPaw: return leftPaw;
00245       case SpecialActionRequest::rightPaw: return rightPaw;
00246       case SpecialActionRequest::armLeft: return armLeft;
00247       case SpecialActionRequest::armRight: return armRight;
00248       case SpecialActionRequest::pushSoft: return pushSoft;
00249       case SpecialActionRequest::pushStrong: return pushStrong;
00250       case SpecialActionRequest::chestSoft: return chestSoft;
00251       case SpecialActionRequest::putRight: return putRight;
00252       case SpecialActionRequest::putLeft: return putLeft;
00253       case SpecialActionRequest::forwardKickFast: return forwardKickFast;
00254       case SpecialActionRequest::forwardKickHard: return forwardKickHard;
00255       case SpecialActionRequest::slapRight: return slapRight;
00256       case SpecialActionRequest::slapLeft: return slapLeft;
00257       case SpecialActionRequest::headLeftSoft: return headLeftSoft;
00258       case SpecialActionRequest::headRightSoft: return headRightSoft;
00259       case SpecialActionRequest::backKickLeft: return backKickLeft;
00260       case SpecialActionRequest::backKickRight: return backKickRight;
00261       case SpecialActionRequest::kickAlongArmLeft: return kickAlongArmLeft;
00262       case SpecialActionRequest::kickAlongArmRight: return kickAlongArmRight;
00263       case SpecialActionRequest::bbHeadLeftSoft: return bbHeadLeftSoft;
00264       case SpecialActionRequest::bbHeadLeftStrong: return bbHeadLeftStrong;
00265       case SpecialActionRequest::bbHeadRightSoft: return bbHeadRightSoft;
00266       case SpecialActionRequest::bbHeadRightStrong: return bbHeadRightStrong;
00267       case SpecialActionRequest::kickWithBackLegLeft: return kickWithBackLegLeft;
00268       case SpecialActionRequest::kickWithBackLegRight: return kickWithBackLegRight;
00269       default: return nothing;
00270     }
00271   }
00272   
00273   /**  */ 
00274   enum{xRange = 20}; 
00275   
00276   /**  */ 
00277   enum{yRange = 40};
00278   
00279   /**  */ 
00280   enum{maxNumberOfSectors = 24};
00281   
00282   /** 
00283   * Calculates the best kick based on the position of the ball relative to the 
00284   * robot and a target angle. 
00285   */
00286   ActionID retrieveKick(
00287     double ballOffsetX, double ballOffsetY, 
00288     double destinationAngle, double destinationAngleWidth,
00289     KickSelectionTableID kickSelectionTableID
00290     ) const;
00291   
00292   Vector2<double> searchKickInNeighbourhood(
00293     double ballOffsetX, double ballOffsetY, 
00294     double destinationAngle,
00295     KickSelectionTableID kickSelectionTableID,
00296     RobotPose robotPose,
00297     double maxDistance,
00298     double& kick
00299    ) const;
00300   
00301   /** The action tables */
00302   ActionID action[xRange][yRange][maxNumberOfSectors][numberOfKickSelectionTableIDs];
00303 
00304   /** The number of sectors */
00305   int numberOfSectors;
00306   
00307   /** Returns a table id for a name */
00308   static KickSelectionTableID getTableIDFromName(const char* name);
00309   
00310   /** Returns an action id for a short name */
00311   static ActionID getActionIDFromShortName(const char* name);
00312   
00313   /** Loads a kick selection table from a file */
00314   void load(const char* fileName);
00315 
00316 private:
00317   int getSectorFromAngle(double destinationAngle) const;
00318 
00319 };
00320 
00321 /**
00322 * Streaming operator that reads KickSelectionTable from a stream.
00323 * @param stream The stream from which is read.
00324 * @param kickSelectionTable The KickSelectionTable object.
00325 * @return The stream.
00326 */ 
00327 In& operator>>(In& stream, KickSelectionTable& kickSelectionTable);
00328 
00329 /**
00330 * Streaming operator that writes KickSelectionTable to a stream.
00331 * @param stream The stream to write on.
00332 * @param kickSelectionTable The KickSelectionTable object.
00333 * @return The stream.
00334 */ 
00335 Out& operator<<(Out& stream, const KickSelectionTable& kickSelectionTable);
00336 
00337 /**
00338 * Streaming operator that reads KickCase from a stream.
00339 * @param stream The stream from which is read.
00340 * @param kickCase The KickCase object.
00341 * @return The stream.
00342 */ 
00343 In& operator>>(In& stream, KickCase& kickCase);
00344 
00345 /**
00346 * Streaming operator that writes KickCase to a stream.
00347 * @param stream The stream to write on.
00348 * @param kickCase The KickCase object.
00349 * @return The stream.
00350 */ 
00351 Out& operator<<(Out& stream, const KickCase& kickCase);
00352 
00353 
00354 #endif   //  _KickSelectionTable_h_

Generated on Mon Mar 20 22:00:05 2006 for GT2005 by doxygen 1.3.6