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

Modules/MotionControl/WakeUpEngine.cpp

Go to the documentation of this file.
00001 /**
00002 * @file WakeUpEngine.cpp
00003 * 
00004 * Implementation of class WakeUpEngine.
00005 *
00006 * @author Andreas Heinze
00007 */
00008 #include "Tools/Math/Common.h"
00009 
00010 #include "WakeUpEngine.h"
00011 #include "Tools/Debugging/Debugging.h"
00012 
00013 WakeUpEngine::WakeUpEngine():lastTimeRunFrameNumber(0), finished(true)
00014 {
00015 
00016   frameNumberOfKeyFrame[0] =   0;
00017   frameNumberWhenDefaultPidDataIsReached = 20;
00018   frameNumberOfKeyFrame[1] = 100;
00019   frameNumberOfKeyFrame[2] = 200;
00020   frameNumberOfKeyFrame[3] = 300;
00021 
00022 #ifdef _WIN32
00023   frameNumberOfKeyFrame[0] =   0;
00024   frameNumberWhenDefaultPidDataIsReached = 1;
00025   frameNumberOfKeyFrame[1] = 2;
00026   frameNumberOfKeyFrame[2] = 3;
00027   frameNumberOfKeyFrame[3] = 4;
00028 #endif
00029 
00030   position[JointData::legFL1][2] =  -111000;
00031   position[JointData::legFL2][2] =  1230000; 
00032   position[JointData::legFL3][2] =   777000;
00033 
00034   position[JointData::legFR1][2] =   -50000;
00035   position[JointData::legFR2][2] =  1213000; 
00036   position[JointData::legFR3][2] =   737000;
00037   
00038   position[JointData::legHL1][2] =    93000;
00039   position[JointData::legHL2][2] =  1207000; 
00040   position[JointData::legHL3][2] =  1028000;
00041 
00042   position[JointData::legHR1][2] =   142000;
00043   position[JointData::legHR2][2] =  1144000; 
00044   position[JointData::legHR3][2] =  1142000;
00045   
00046 
00047   position[JointData::legFL1][3] = -300000;
00048   position[JointData::legFL2][3] =  250000;
00049   position[JointData::legFL3][3] = 1800000;
00050   
00051   position[JointData::legFR1][3] = -300000;
00052   position[JointData::legFR2][3] =  250000;
00053   position[JointData::legFR3][3] = 1800000;
00054 
00055   position[JointData::legHL1][3] = -600000;
00056   position[JointData::legHL2][3] =  150000;
00057   position[JointData::legHL3][3] = 1600000;
00058   
00059   position[JointData::legHR1][3] = -600000;
00060   position[JointData::legHR2][3] =  150000;
00061   position[JointData::legHR3][3] = 1600000;
00062 }
00063 
00064 WakeUpEngine::~WakeUpEngine()
00065 {
00066 }
00067 
00068 void WakeUpEngine::start(const SensorData& sensorData, PIDData& pidData)
00069 {
00070   counter = 0;
00071   currentKeyFrame = 0;
00072   
00073   PIDData defaultPid;
00074   
00075   int i;
00076   for(i = 0; i < JointData::numOfJoint; i++)
00077     {
00078       pidData.p[i] = 0;
00079       pidData.i[i] = 0; 
00080       pidData.d[i] = 0; 
00081     }
00082   for(i = 0; i < JointData::numOfJoint; i++)
00083   {
00084     diffP[i] = (double)(defaultPid.p[i] - pidData.p[i]) / (double)frameNumberWhenDefaultPidDataIsReached;
00085     diffI[i] = (double)(defaultPid.i[i] - pidData.i[i]) / (double)frameNumberWhenDefaultPidDataIsReached;
00086     diffD[i] = (double)(defaultPid.d[i] - pidData.d[i]) / (double)frameNumberWhenDefaultPidDataIsReached;
00087   }
00088   
00089   position[JointData::legFL1][0] = sensorData.data[SensorData::legFL1];
00090   position[JointData::legFL2][0] = sensorData.data[SensorData::legFL2];
00091   position[JointData::legFL3][0] = sensorData.data[SensorData::legFL3];
00092 
00093   position[JointData::legFR1][0] = sensorData.data[SensorData::legFR1];
00094   position[JointData::legFR2][0] = sensorData.data[SensorData::legFR2];
00095   position[JointData::legFR3][0] = sensorData.data[SensorData::legFR3];
00096 
00097   position[JointData::legHL1][0] = sensorData.data[SensorData::legHL1];
00098   position[JointData::legHL2][0] = sensorData.data[SensorData::legHL2];
00099   position[JointData::legHL3][0] = sensorData.data[SensorData::legHL3];
00100 
00101   position[JointData::legHR1][0] = sensorData.data[SensorData::legHR1];
00102   position[JointData::legHR2][0] = sensorData.data[SensorData::legHR2];
00103   position[JointData::legHR3][0] = sensorData.data[SensorData::legHR3];
00104 
00105   position[JointData::legFL1][1] = sensorData.data[SensorData::legFL1];
00106   position[JointData::legFL2][1] = 1200000;
00107   position[JointData::legFL3][1] = sensorData.data[SensorData::legFL3];
00108 
00109   position[JointData::legFR1][1] = sensorData.data[SensorData::legFR1];
00110   position[JointData::legFR2][1] = 1200000;
00111   position[JointData::legFR3][1] = sensorData.data[SensorData::legFR3];
00112 
00113   position[JointData::legHL1][1] = sensorData.data[SensorData::legHL1];
00114   position[JointData::legHL2][1] = 1200000;
00115   position[JointData::legHL3][1] = sensorData.data[SensorData::legHL3];
00116 
00117   position[JointData::legHR1][1] = sensorData.data[SensorData::legHR1];
00118   position[JointData::legHR2][1] = 1200000;
00119   position[JointData::legHR3][1] = sensorData.data[SensorData::legHR3];
00120 
00121   int keyFrame;
00122   for(keyFrame = 0; keyFrame < numberOfKeyFrames - 1; keyFrame++)
00123   {
00124     for(i = JointData::legFR1; i <= JointData::legHL3; i++)
00125     {
00126         stepSize[i][keyFrame] = (position[i][keyFrame+1] - position[i][keyFrame]) / (frameNumberOfKeyFrame[keyFrame + 1] - frameNumberOfKeyFrame[keyFrame]);
00127     }
00128   }
00129 }
00130 
00131 
00132 bool WakeUpEngine::execute(unsigned int frameNumber, const SensorData& sensorData, JointData& jointData, PIDData& pidData)
00133 {
00134   if(finished || abs(int(frameNumber - lastTimeRunFrameNumber)) > 100)
00135   {
00136      finished = false;
00137      start(sensorData, pidData);
00138   }
00139    
00140   lastTimeRunFrameNumber = frameNumber;
00141 
00142   counter++;
00143   int i;
00144   if(counter < frameNumberWhenDefaultPidDataIsReached)
00145   {
00146     for(i = 0; i < JointData::numOfJoint; i++)
00147     {
00148       pidData.p[i] = (int)(counter * diffP[i]);
00149       pidData.i[i] = (int)(counter * diffI[i]); 
00150       pidData.d[i] = (int)(counter * diffD[i]); 
00151     }
00152   }
00153   if(counter == frameNumberWhenDefaultPidDataIsReached)
00154   {
00155     pidData.setToDefaults();
00156   }
00157 
00158   if(counter > frameNumberOfKeyFrame[currentKeyFrame+1]) currentKeyFrame++;
00159 
00160   if(currentKeyFrame == numberOfKeyFrames){
00161     
00162     //OUTPUT(idText, text, "wakeUP finish!");
00163     finished = true;
00164     return false;
00165   }
00166 
00167   int positionInCurrentPhase = counter - frameNumberOfKeyFrame[currentKeyFrame];
00168 
00169   for(i = JointData::legFR1; i <= JointData::legHL3; i++)
00170   {
00171     jointData.data[i] = position[i][currentKeyFrame] + positionInCurrentPhase * stepSize[i][currentKeyFrame];
00172   }
00173 
00174   finished = false;
00175   return true;
00176 }
00177 
00178 
00179 
00180 
00181 /*
00182 * Change log :
00183 * 
00184 * $Log: WakeUpEngine.cpp,v $
00185 * Revision 1.5  2004/06/15 17:15:21  roefer
00186 * Warning removed
00187 *
00188 * Revision 1.4  2004/06/14 14:53:43  spranger
00189 * put everything into execute (start is called from there)
00190 * motioncontrol cleanup
00191 *
00192 * Revision 1.3  2004/05/24 14:50:01  juengel
00193 * faster
00194 *
00195 * Revision 1.2  2004/05/23 20:29:27  juengel
00196 * Faster WakeUp in simulation.
00197 *
00198 * Revision 1.1.1.1  2004/05/22 17:20:37  cvsadm
00199 * created new repository GT2004_WM
00200 *
00201 * Revision 1.4  2004/05/22 14:28:13  juengel
00202 * First working version.
00203 *
00204 * Revision 1.3  2004/05/19 13:32:39  heinze
00205 * worked at the engine
00206 *
00207 * Revision 1.2  2004/05/03 15:29:48  roefer
00208 * Warnings removed
00209 *
00210 * Revision 1.1  2004/05/03 09:45:01  heinze
00211 * Added WakeUpEngine.
00212 *
00213 */

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