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

Modules/WalkingEngine/InvKinWalkingEngine.h

Go to the documentation of this file.
00001 /**
00002 * @file InvKinWalkingEngine.h
00003 * 
00004 * Definition of class InvKinWalkingEngine
00005 *
00006 * @author Max Risler
00007 */
00008 
00009 #ifndef __InvKinWalkingEngine_h_
00010 #define __InvKinWalkingEngine_h_
00011 
00012 #include "WalkingEngine.h"
00013 #include "InvKinWalkingParameterSets.h"
00014 
00015 /**
00016 * @class InvKinWalkingEngine
00017 *
00018 * Walking engine based on 
00019 * calculation of rectangular foot movement and
00020 * inverse kinematics
00021 *
00022 * @author Max Risler
00023 */
00024 class InvKinWalkingEngine : public WalkingEngine
00025 {
00026 public:
00027 /**
00028 * Constructor.
00029 * @param interfaces The paramters of the WalkingEngine module.
00030   */
00031   InvKinWalkingEngine(const WalkingEngineInterfaces& interfaces);
00032   
00033   /**
00034   * Destructor
00035   */
00036   ~InvKinWalkingEngine();
00037   
00038   /** Executes the engine */
00039   virtual bool executeParameterized(JointData& jointData, const WalkRequest& walkRequest, double positionInWalkingCycle);
00040   
00041   /** 
00042   * Called from a MessageQueue to distribute messages 
00043   * @param message The message that can be read.
00044   * @return true if the message was read (handled).
00045   */
00046   virtual bool handleMessage(InMessage& message);
00047   
00048   /**
00049   * Sets the engine's parameters
00050   * @param p The new parameter set
00051   * @param changeSteps Number of interpolation steps from old to new parameters
00052   */
00053   void setParameters(InvKinWalkingParameters* p, int changeSteps=32);
00054   
00055   /**
00056   * Gets the engine's parameters
00057   */
00058   const InvKinWalkingParameters& getParameters() const {return currentParameters;}
00059   
00060 private:
00061   
00062   //!@name parameter set interpolation
00063   //!@{
00064   /** Current parameters of this walk */
00065   InvKinWalkingParameters currentParameters;
00066 
00067   /** Pointer to the parameter set requested in setParameters */
00068   InvKinWalkingParameters *requestedParameters;
00069   
00070   /** Next parameters of this walk, target of current interpolation */
00071   InvKinWalkingParameters nextParameters;
00072   
00073   /** Last parameters of this walk, origin of current interpolation */
00074   InvKinWalkingParameters lastParameters;
00075     
00076   /** Counts parameter set interpolation steps */
00077   int paramInterpolCount;
00078   
00079   /** Stores the length of the current parameter set interpolation */
00080   int paramInterpolLength;
00081   
00082   /** Stores precise version of currentStep during interpolation */
00083   double positionInWalkCycle;
00084   
00085   /** Initialize interpolation of WalkingParameterSets */
00086   void initParametersInterpolation(int changeSteps);
00087   
00088   /** Calculate next step in parameterset interpolation and increase currentStep if walk is true*/
00089   void nextParametersInterpolation(bool walk);
00090   //!@}
00091   
00092   unsigned long lastParametersFromPackageTimeStamp;
00093  
00094   //!@name current walk values
00095   //!@{
00096   double legSpeedX[4]; ///< speed of leg in x direction (step size in mm)
00097   double legSpeedY[4]; ///< speed of leg in y direction (step size in mm)
00098   // int currentStep;  ///< current step
00099   bool footOnGround[4]; ///< foot is on ground
00100   double x[4]; ///< foot x positions
00101   double y[4]; ///< foot y positions
00102   double z[4]; ///< foot z positions
00103   //!@}
00104   
00105   /** currently executed motion request
00106   * speeds in mm/s
00107   */
00108   Pose2D currentRequest;
00109   
00110   /** odometry resulting from current request
00111   * speed in mm/tick
00112   */
00113   Pose2D odometry;
00114   
00115   /** calculates new leg speeds according to current motion request */
00116   void calculateLegSpeeds();
00117   
00118   /** calculate relative foot position for one leg 
00119   * rx is relative to current step size (range -1.0..1.0)
00120   * ry is an absolute offset to y foot position
00121   * rz is relative to step lift parameter (range 0..1.0)
00122   */
00123   void calculateRelativeFootPosition(int step, int leg, double &rx, double &ry, double &rz);
00124   
00125   /** calculate current joint data values */
00126   void calculateData(JointData &j);
00127   
00128   /** calculate current foot positions */
00129   void calculateFootPositions();
00130   
00131   /** calculate angles for one leg in current step */
00132   int calculateLegJoints(Kinematics::LegIndex leg, 
00133     double &j1, double &j2, double &j3,
00134     double bodyTilt=0);
00135   
00136   /** smooth motion request 
00137   * current request is adjusted according to motion request
00138   * eliminating quick changes */
00139   void smoothMotionRequest(const Pose2D& request, Pose2D& currentRequest);
00140   
00141   /** 
00142   * limit step to maximum step size
00143   * corrects odometry accordingly
00144   */
00145   void limitToMaxSpeed(double& stepSizeX, double& stepSizeY, double& stepSizeR);
00146 
00147   /** gets (hopefully optimized) relative foot position from a lookup table with interpolation
00148   * @param index exact table index 0.0..0.25
00149   * @param rz the returned relative z coordinate of the foot 
00150   * @return the returned relative x coordinate (signless) of the foot
00151   */
00152   double getLegPositionCurve(double& rz,double index);
00153 };
00154 
00155 
00156 /**
00157 * @class ParamInvKinWalkingEngine
00158 *
00159 * This class is a wrapper for the InvKinWalkingEngine
00160 * calling a given instance of the engine with a
00161 * specific set of parameters.
00162 *
00163 * @author Max Risler
00164 */
00165 class ParamInvKinWalkingEngine : public WalkingEngine
00166 {
00167 public:
00168   ParamInvKinWalkingEngine(InvKinWalkingParameters* pParams, InvKinWalkingEngine* pEngine) :
00169     WalkingEngine(*pEngine),
00170     pEngine(pEngine),
00171     pParams(pParams)
00172   {}
00173 
00174   ~ParamInvKinWalkingEngine()
00175   {
00176     delete pParams;
00177   }
00178 
00179   InvKinWalkingEngine* pEngine;
00180   InvKinWalkingParameters* pParams;
00181 
00182   virtual bool executeParameterized(JointData& jointData,
00183         const WalkRequest& walkRequest, double positionInWalkingCycle)
00184   {
00185     pEngine->setParameters(pParams);
00186     return pEngine->executeParameterized(jointData, walkRequest, positionInWalkingCycle);
00187   }
00188 
00189   bool handleMessage(InMessage& message)
00190   {
00191     if (message.getMessageID() == idInvKinWalkingParameters)
00192     {
00193       InvKinWalkingParameters* newParams = new InvKinWalkingParameters;
00194       delete pParams;
00195       pParams = newParams;
00196       message.bin >> *pParams;
00197       pParams->readValues();
00198       return true;
00199     }
00200     return pEngine->handleMessage(message);
00201   }
00202 };
00203 
00204 
00205 /**
00206  * @class ParamRearOnlyInvKinWalkingEngine
00207  *
00208  * This class is a wrapper for the InvKinWalkingEngine
00209  * calling a given instance of the engine with a specific
00210  * set of parameters. Only the hind legs are moved, every
00211  * other joints are left in their current positions.
00212  * \note  this is useful for turning with the ball.
00213  *
00214  * @author Thomas Kindler
00215  */
00216 class ParamRearOnlyInvKinWalkingEngine : public WalkingEngine
00217 {
00218 public:
00219   ParamRearOnlyInvKinWalkingEngine(
00220     InvKinWalkingParameters  *pParams, 
00221     InvKinWalkingEngine      *pEngine
00222   ) :
00223     WalkingEngine(*pEngine),
00224     pEngine(pEngine),
00225     pParams(pParams)
00226   {}
00227 
00228   ~ParamRearOnlyInvKinWalkingEngine()
00229   {
00230     delete pParams;
00231   }
00232 
00233   InvKinWalkingEngine     *pEngine;
00234   InvKinWalkingParameters *pParams;
00235 
00236   virtual bool executeParameterized(
00237     JointData            &jointData,
00238     const WalkRequest  &walkRequest,
00239     double positionInWalkingCycle
00240   ) {
00241     pEngine->setParameters(pParams);
00242 
00243     JointData jd = jointData;
00244     bool result = pEngine->executeParameterized(jd, walkRequest, positionInWalkingCycle);
00245     
00246     // Copy hind leg joint angles only
00247     //
00248     jointData.data[JointData::legHL1] = jd.data[JointData::legHL1];
00249     jointData.data[JointData::legHL2] = jd.data[JointData::legHL2];
00250     jointData.data[JointData::legHL3] = jd.data[JointData::legHL3];
00251     jointData.data[JointData::legHR1] = jd.data[JointData::legHR1];
00252     jointData.data[JointData::legHR2] = jd.data[JointData::legHR2];
00253     jointData.data[JointData::legHR3] = jd.data[JointData::legHR3];
00254     return  result;
00255   }
00256 
00257   bool handleMessage(InMessage &message)
00258   {
00259     if (message.getMessageID() == idInvKinWalkingParameters)
00260     {
00261       InvKinWalkingParameters* newParams = new InvKinWalkingParameters;
00262       delete pParams;
00263       pParams = newParams;
00264       message.bin >> *pParams;
00265       return true;
00266     }
00267     return pEngine->handleMessage(message);
00268   }
00269 };
00270 
00271 #endif// __InvKinWalkingEngine_h_
00272 
00273 /*
00274 * Change log :
00275 * 
00276 * $Log: InvKinWalkingEngine.h,v $
00277 * Revision 1.5  2004/09/09 10:15:55  spranger
00278 * fixed doxygen-errors
00279 *
00280 * Revision 1.4  2004/06/14 16:54:11  juengel
00281 * Removed some WalkingEngineParameterSets.
00282 *
00283 * Revision 1.3  2004/06/07 18:49:37  spranger
00284 * -extended interface of executeParametrized by positionInWalkCycle,
00285 * -removed currentStep and doubleStep
00286 * -all cycle determination relies on positionInWalkCycle
00287 *
00288 * Revision 1.2  2004/06/02 17:18:22  spranger
00289 * MotionRequest cleanup
00290 *
00291 * Revision 1.1.1.1  2004/05/22 17:22:31  cvsadm
00292 * created new repository GT2004_WM
00293 *
00294 * Revision 1.10  2004/04/08 15:33:06  wachter
00295 * GT04 checkin of Microsoft-Hellounds
00296 *
00297 * Revision 1.9  2004/03/26 10:57:04  thomas
00298 * added name of parameters to streaming operator
00299 * call readValues after setting new parameters
00300 *
00301 * Revision 1.8  2004/03/22 21:58:13  roefer
00302 * True odometry
00303 *
00304 * Revision 1.7  2004/03/18 16:59:40  risler
00305 * new pointer when receving parameter set
00306 *
00307 * Revision 1.6  2004/03/17 15:38:51  thomas
00308 * added walkType debug for debugging WalkingEngineParameterSets
00309 * paramSets-messages send by debug-message are stored in the new debug-walkType only
00310 *
00311 * Revision 1.5  2004/03/09 22:31:49  cesarz
00312 * added functionality to change invKinWalkingParameters through the behavior
00313 *
00314 * Revision 1.4  2004/03/08 02:11:54  roefer
00315 * Interfaces should be const
00316 *
00317 * Revision 1.3  2004/02/16 17:56:32  dueffert
00318 * InvKin engine and parameters separated
00319 *
00320 * Revision 1.2  2003/12/02 18:19:23  dueffert
00321 * comment bug fixed
00322 *
00323 * Revision 1.1  2003/10/06 14:10:15  cvsadm
00324 * Created GT2004 (M.J.)
00325 *
00326 * Revision 1.6  2003/09/26 11:38:52  juengel
00327 * - sorted tools
00328 * - clean-up in DataTypes
00329 *
00330 * Revision 1.5  2003/09/01 15:57:42  dueffert
00331 * Genom and Individual merged
00332 *
00333 * Revision 1.4  2003/08/08 15:43:25  dueffert
00334 * some evolution implementation added
00335 *
00336 * Revision 1.3  2003/07/24 12:44:19  risler
00337 * new walking engine Parameters loweringPhase, Phase parameters for fore and hind legs now, leaveAnytime, new footmode freeFormQuad
00338 *
00339 * Revision 1.2  2003/07/05 09:49:05  roefer
00340 * Generic debug message for bodyOffsets improved
00341 *
00342 * Revision 1.1.1.1  2003/07/02 09:40:24  cvsadm
00343 * created new repository for the competitions in Padova from the 
00344 * tamara CVS (Tuesday 2:00 pm)
00345 *
00346 * removed unused solutions
00347 *
00348 * Revision 1.22  2003/06/12 21:42:26  roefer
00349 * GT2003 walking parameters finished
00350 *
00351 * Revision 1.21  2003/05/12 00:03:30  dueffert
00352 * doxygen bugs fixed
00353 *
00354 * Revision 1.20  2003/05/03 16:20:01  roefer
00355 * robot.cfg added
00356 *
00357 * Revision 1.19  2003/04/16 07:00:16  roefer
00358 * Bremen GO checkin
00359 *
00360 * Revision 1.19  2003/04/08 18:28:28  roefer
00361 * bodyTiltOffset added
00362 *
00363 * Revision 1.18  2003/04/04 17:37:38  dueffert
00364 * a bunch of fine tuning
00365 *
00366 * Revision 1.17  2003/03/19 09:22:17  dueffert
00367 * circle mode added
00368 *
00369 * Revision 1.16  2003/03/06 12:08:14  dueffert
00370 * execute with parameters renamed to avoid inheritance warnings
00371 *
00372 * Revision 1.15  2003/03/05 10:31:46  risler
00373 * interpolation bug fixed
00374 *
00375 * Revision 1.14  2003/03/03 17:32:57  risler
00376 * walking engine now writes calculated bodyTilt to headState
00377 * minor cleanup to new parameter interpolation stuff
00378 * parameter interpolation when standing
00379 *
00380 * Revision 1.13  2003/03/03 08:44:32  dueffert
00381 * switching InvKinWalkingParameters is smoothed now
00382 *
00383 * Revision 1.12  2003/02/03 19:32:25  risler
00384 * sending walking parameters now works properly again
00385 *
00386 * Revision 1.11  2003/01/23 16:44:10  risler
00387 * only one instance of InvKinWalkingEngine
00388 * parameter sets can now be switched while walking
00389 * added UNSWFastTurn, combining two parameter sets
00390 *
00391 * Revision 1.10  2003/01/18 17:40:16  risler
00392 * changed walking engine parameter coordinate system
00393 *
00394 * Revision 1.9  2002/12/11 14:58:45  risler
00395 * InvKinWalkingEngine:
00396 * added body shift parameters,
00397 * and rotation center correction value
00398 *
00399 * Revision 1.8  2002/11/28 16:57:34  risler
00400 * added leg phase parameters for variable gaits
00401 *
00402 * Revision 1.7  2002/11/26 12:28:57  dueffert
00403 * doxygen docu corrected
00404 *
00405 * Revision 1.6  2002/11/25 12:35:33  dueffert
00406 * bodyTilt should be used to calculate leg positions from joints and vice versa
00407 *
00408 * Revision 1.5  2002/11/19 17:10:54  risler
00409 * DebugMessageGenerator uses InConfigMemory
00410 * Can handle comments now
00411 *
00412 * Revision 1.4  2002/10/14 13:14:24  dueffert
00413 * doxygen comments corrected
00414 *
00415 * Revision 1.3  2002/09/22 18:40:53  risler
00416 * added new math functions, removed GTMath library
00417 *
00418 * Revision 1.2  2002/09/11 00:06:58  loetzsch
00419 * continued change of module/solution mechanisms
00420 *
00421 * Revision 1.1  2002/09/10 15:36:16  cvsadm
00422 * Created new project GT2003 (M.L.)
00423 * - Cleaned up the /Src/DataTypes directory
00424 * - Removed challenge related source code
00425 * - Removed processing of incoming audio data
00426 * - Renamed AcousticMessage to SoundRequest
00427 *
00428 * Revision 1.4  2002/08/22 14:41:03  risler
00429 * added some doxygen comments
00430 *
00431 * Revision 1.3  2002/07/23 13:33:43  loetzsch
00432 * new streaming classes
00433 *
00434 * removed many #include statements
00435 *
00436 * Revision 1.2  2002/05/11 08:07:43  risler
00437 * added head and mouth joints to InvKinWalkingParameters
00438 *
00439 * Revision 1.1.1.1  2002/05/10 12:40:19  cvsadm
00440 * Moved GT2002 Project from ute to tamara.
00441 *
00442 * Revision 1.5  2002/05/02 18:17:03  risler
00443 * added InvKin Parameters fore/hindFootTilt
00444 *
00445 * Revision 1.4  2002/05/02 09:45:33  risler
00446 * no message
00447 *
00448 * Revision 1.3  2002/04/30 16:22:34  risler
00449 * added InvKin Parameters footMode, footTilt
00450 *
00451 * Revision 1.2  2002/04/29 13:48:21  risler
00452 * added lastWalkType to WalkingEngine execute
00453 *
00454 * Revision 1.1  2002/04/26 13:35:32  risler
00455 * DarmstadtGOWalkingEngine renamed to InvKinWalkingEngine
00456 * added InvKinParameterSets
00457 *
00458 * Revision 1.3  2002/04/17 17:04:41  risler
00459 * Darmstadt GO
00460 *
00461 * Revision 1.2  2002/04/09 16:46:02  risler
00462 * added DarmstadtGOWalkingEngine
00463 *
00464 * Revision 1.1  2002/03/29 19:36:53  risler
00465 * added DarmstadtGOWalkingEngine
00466 *
00467 *
00468 */

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