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

Modules/WalkingEngine/BB2004InvKinWalkingEngine.h

Go to the documentation of this file.
00001 /**
00002 * @file BB2004InvKinWalkingEngine.h
00003 * 
00004 * This file contains an approach to evolutionary algorithms based on 
00005 * a parameter set for the InvKinWalkingEngine.
00006 *
00007 * @author <a href="mailto:roefer@tzi.de">Thomas Röfer</a>
00008 */
00009 
00010 #ifndef __BB2004InvKinWalkingEngine_h_
00011 #define __BB2004InvKinWalkingEngine_h_
00012 
00013 #include "InvKinWalkingEngine.h"
00014 #include "Tools/Evolution/BB2004Evo.h"
00015 #include "Tools/RingBuffer.h"
00016 
00017 /**
00018 * @class BBInvKinIndividual
00019 *
00020 * The class represents an individual for a set of walking parameters.
00021 */
00022 class BBInvKinIndividual : public BBIndividual
00023 {
00024 private:
00025   enum 
00026   {
00027     numOfGenes = 27 /**< The number of genes of the individual. */
00028   };
00029   static double geneScale[numOfGenes]; /**< An array that estimates the range of value of a certain gene. */
00030   double genes[numOfGenes]; /**< The genes. */
00031   double fitness, /**< The fitness of this individual. */
00032          speed, /**< The speed of the walk using this individual. */
00033          smoothness; /**< The smooothness of the walk using this individual. */
00034 
00035 public:
00036   /**
00037   * Constructor.
00038   */
00039   BBInvKinIndividual() {fitness = 1;}
00040 
00041   /**
00042   * Constructor.
00043   * @param parameters The parameters that copied into the genes.
00044   */
00045   BBInvKinIndividual(const InvKinWalkingParameters& parameters);
00046 
00047   /**
00048   * The function initializes the current individual with another one.
00049   * @param initial The other individual the current one is initialized with.
00050   */
00051   virtual void init(const BBIndividual& initial);
00052   
00053   /**
00054   * The function interpolates between the current individual and another one.
00055   * The result is stored in the current individual.
00056   * @param other The other individual the current one is interpolated with.
00057   */
00058   virtual void interpolate(const BBIndividual& other);
00059 
00060   /**
00061   * The function extrapolates between the current individual and another one.
00062   * @param other The other individual the current one is extrapolated with.
00063   */
00064   virtual void extrapolate(const BBIndividual& other);
00065 
00066   /**
00067   * The function mutates the current individual.
00068   */
00069   virtual void mutate();
00070 
00071   /**
00072   * The function returns the fitness of the individual.
00073   * @return The fitness as a number >= 0. A higher result means a higher fitness.
00074   */
00075   virtual double getFitness() const {return fitness;}
00076 
00077   /**
00078   * The function returns the speed of the walk of the individual.
00079   * @return The speed.
00080   */
00081   double getSpeed() const {return speed;}
00082 
00083   /**
00084   * The function returns the smoothness of the walk of the individual.
00085   * @return The smoothness.
00086   */
00087   double getSmoothness() const {return smoothness;}
00088 
00089   /**
00090   * The function sets the speed and the smoothness of the walk using the individual.
00091   * @param speed The speed.
00092   * @param smoothness The smoothness.
00093   */
00094   void setWalkCharacteristics(double speed, double smoothness);
00095 
00096   /**
00097   * The function copies the genes into walking parameters.
00098   * @param parameters The parameters the genes are copied to.
00099   */
00100   void getParameters(InvKinWalkingParameters& parameters) const;
00101 
00102   /**
00103   * The function prints the genes.
00104   */
00105   void dump() const;
00106 };
00107 
00108 /**
00109 * @class BB2004InvKinWalkingEngine
00110 *
00111 * This class implements a walking engine that optimizes its parameters
00112 * using evolutionary algorithms.
00113 */
00114 
00115 class BB2004InvKinWalkingEngine : public WalkingEngine
00116 {
00117 private:
00118   /**
00119   * @class FootPositions
00120   * The class represents a pair of positions of the back feet.
00121   */
00122   class FootPositions
00123   {
00124   public:
00125     Vector3<double> positions[2]; /**< The 3-D positions of the back feet. */
00126     bool onGround[2]; /**< Were the feet on the ground? */
00127 
00128     /**
00129     * Constructor.
00130     * The feet have no contact to the ground.
00131     */
00132     FootPositions() {onGround[0] = onGround[1] = false;}
00133   };
00134 
00135   InvKinWalkingEngine* pEngine; /**< The address of the actual walking engine. */
00136   ERS7EvolveWalkingParameters parameters[2], /**< Two parameter sets that are interchangingly used. */
00137                               bestParameters, /**< The best parameters found so far. */
00138                               forward, /**< Parameters for forward walking. */
00139                               fastForward, /**< Parameters for fast forward walking. */
00140                               backward, /**< Parameters for backward walking. */
00141                               stand; /**< Parameters for standing. */
00142   int currentParameters; /**< The index that defines which of the two "parameters" are currently used. */
00143   int currentIndividual; /**< The index of the current individual in the population. */
00144   int currentFrame; /**< The index of the current frame that measures the performance of the current individual. */
00145   int evolutions; /**< The number of evolutions done so far. */
00146   double bestFitness; /**< The best overall fitness found so far. */
00147   Pose2D odometrySpeed; /**< The current speed of the robot. */
00148   double odometryScaleX, /**< The scale factor for odometry in x direction. */
00149          odometryScaleY, /**< The scale factor for odometry in y direction. */
00150          odometryScaleRotation, /**< The scale factor for odometry rotation. */
00151          odometryCounterRotation; /**< A factor that compensates rotation resulting from sideward motion. */
00152   RingBuffer<Vector2<double>, 100> odometrySums[2]; /**< The current state of the odometers. */
00153   FootPositions prevPositions; /**< The previous positions of the feet. */
00154   enum 
00155   {
00156     numOfIndividuals = 15, /**< The number of individuals in the population. */
00157     numOfFramesPerIndividual = 625, /**< The number of frames tested per individual. */
00158     ignoreFrames = 250, /**< The number of frames to ignore at the beginning of an individual. */
00159     useFrames = numOfFramesPerIndividual - ignoreFrames /**< The number of frames that are assessed per individual. */
00160   };
00161   RingBuffer<SensorData, numOfFramesPerIndividual> buffer; /**< A buffer for previous sensor readings. */
00162   Pose2D measured, /**< Accumulated odometry for current individual. */
00163          target; /**< Accumulated request motion for current individual. */
00164   BBPopulation<BBInvKinIndividual>* population; /**< The population of individuals. */
00165 
00166   /**
00167   * The function optimizes the gait for the current motion request.
00168 <<<<<<< BB2004InvKinWalkingEngine.h
00169   * @param walkRequest The current walk request.
00170 =======
00171   * @param walkRequest The current motion request.
00172 >>>>>>> 1.7
00173   */
00174   void learn(const WalkRequest& walkRequest);
00175 
00176   /**
00177   * The function sets a new parameter set using the individual specified.
00178   * @param p The individual that is used to set the walking parameters.
00179   */
00180   void setParameters(const BBIndividual& p);
00181 
00182   /**
00183   * The function loads a set of walking parameters.
00184   * @param parameters The variable that receives the loaded parameters.
00185   * @param name The name of the parameters. It will automatically be preceeded by the 
00186   *             current robot design.
00187   */
00188   void loadParameters(InvKinWalkingParameters& parameters, const char* name);
00189 
00190   /**
00191   * The function calculates the standard deviation of the last "useFrames" measurements of a certain sensor.
00192   * @param s The sensor.
00193   * @return The standard deviation of the measurements of s.
00194   */
00195   double stdV(SensorData::sensors s) const;
00196 
00197   /**
00198   * The function updates the odometry.
00199   */
00200   void updateOdometry();
00201 
00202 public:
00203   /**
00204   * Constructor.
00205   * @param pEngine The actual walking engine used.
00206   */
00207   BB2004InvKinWalkingEngine(InvKinWalkingEngine* pEngine);
00208 
00209   /**
00210   * Destructor.
00211   */
00212   ~BB2004InvKinWalkingEngine() {delete population;}
00213 
00214   /**
00215   * The function executes the walking engine.
00216   * @param jointData The joints already set by other modules.
00217   * @param walkRequest The motion request to execute.
00218   * @param positionInWalkingCycle The position in walking cycle requested
00219   * @return Is it forbidden to change to another kind of motion (e.g. special action)?
00220   */
00221   virtual bool executeParameterized(JointData& jointData, const WalkRequest& walkRequest, double positionInWalkingCycle);
00222 
00223   /**
00224   * The function handles a message sent by the PC.
00225   * @param message The message sent.
00226   * @return Was the message handled by this function?
00227   */
00228   bool handleMessage(InMessage& message);
00229 };
00230 
00231 #endif // __BB2004InvKinWalkingEngine_h_
00232 
00233 /*
00234 * Change log :
00235 * 
00236 * $Log: BB2004InvKinWalkingEngine.h,v $
00237 * Revision 1.8  2004/09/09 11:37:39  wachter
00238 * - Fixed some more doxygen-errors
00239 *
00240 * Revision 1.7  2004/09/09 10:15:54  spranger
00241 * fixed doxygen-errors
00242 *
00243 * Revision 1.6  2004/06/14 16:55:19  juengel
00244 * Removed some WalkingEngineParameterSets.
00245 *
00246 * Revision 1.5  2004/06/07 18:47:50  spranger
00247 * extended interface of executeParametrized by positionInWalkCycle
00248 *
00249 * Revision 1.4  2004/06/02 17:18:22  spranger
00250 * MotionRequest cleanup
00251 *
00252 * Revision 1.3  2004/05/27 12:51:14  roefer
00253 * Minor error fixed
00254 *
00255 * Revision 1.2  2004/05/26 09:29:30  roefer
00256 * Remove redundant code
00257 *
00258 * Revision 1.2  2004/03/22 21:58:13  roefer
00259 * True odometry
00260 *
00261 * Revision 1.1  2004/03/03 21:17:09  roefer
00262 * For the sake of consistency, renamed BB* to BB2004*
00263 *
00264 * Revision 1.6  2004/02/16 17:56:32  dueffert
00265 * InvKin engine and parameters separated
00266 *
00267 * Revision 1.5  2004/02/06 20:23:00  roefer
00268 * Further improvements
00269 *
00270 * Revision 1.4  2004/01/28 21:55:49  roefer
00271 * RobotDimensions revised
00272 *
00273 * Revision 1.3  2004/01/05 22:59:53  roefer
00274 * Different parameters for ERS-210 and ERS-7
00275 *
00276 * Revision 1.2  2004/01/02 13:37:27  roefer
00277 * Handle if a single individual was drawn too often
00278 *
00279 * Revision 1.1  2003/12/29 15:48:54  roefer
00280 * Bremen Byters evo walking added
00281 *
00282 */

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