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

Modules/MotionControl/DebugMotionControl.cpp

Go to the documentation of this file.
00001 /**
00002 * @file DebugMotionControl.cpp
00003 *
00004 * Implementation of class DebugMotionControl
00005 * 
00006 * @author Max Risler
00007 */
00008 
00009 #include "DebugMotionControl.h"
00010 
00011 void DebugMotionControl::execute()
00012 {
00013   for (int i = 0; i < jointDataBufferNumOfFrames; i++)
00014   {
00015     JointData &currentFrame = jointDataBuffer.frame[i];
00016     
00017     if (sequencer.isRunning())
00018       //execute sequence
00019       sequencer.nextSequenceData(currentFrame);
00020     else
00021       //do nothing if sequence empty
00022       currentFrame = JointData();
00023     
00024     // stay as forced for joints not used
00025     executeStayAsForced(sensorDataBuffer.lastFrame(), currentFrame);
00026     
00027     // the obgligatory GT tail wag
00028     // other direction to distinguish obviously from DefaultMotionControl
00029     if (currentFrame.data[JointData::tailTilt] == jointDataInvalidValue)
00030     {
00031       static int tailcount = 0;
00032       int j=tailcount++;
00033       if (j>64) j = 128-j;
00034       currentFrame.data[JointData::tailTilt] = 10000*(j - 32);
00035       tailcount &= 127;
00036     }
00037     if (currentFrame.data[JointData::tailPan] == jointDataInvalidValue)
00038       currentFrame.data[JointData::tailPan] = 0;
00039     
00040     //stabilize(0, motionRequest, currentFrame, odometryData, sensorData);
00041     
00042   }
00043   clip();
00044 }
00045 
00046 bool DebugMotionControl::handleMessage(InMessage& message)
00047 {
00048   switch(message.getMessageID())
00049   {
00050   case idJointDataSequence:
00051     message.bin >> sequencer;
00052     sequencer.start();
00053     return true;
00054   }
00055   return false;
00056 }
00057 
00058 #define CLIP(x,min,max) \
00059   if (x > max) x=max; \
00060   else if (x < min) x=min;
00061 
00062 
00063 void DebugMotionControl::clip()
00064 {
00065   for (int i = 0; i < jointDataBufferNumOfFrames; i++)
00066   {
00067     CLIP(jointDataBuffer.frame[i].data[JointData::legFR1], toMicroRad(jointLimitLeg1FN), toMicroRad(jointLimitLeg1FP));
00068     CLIP(jointDataBuffer.frame[i].data[JointData::legFR2], toMicroRad(jointLimitLeg2N), toMicroRad(jointLimitLeg2P));
00069     CLIP(jointDataBuffer.frame[i].data[JointData::legFR3], toMicroRad(jointLimitLeg3N), toMicroRad(jointLimitLeg3P));
00070     CLIP(jointDataBuffer.frame[i].data[JointData::legFL1], toMicroRad(jointLimitLeg1FN), toMicroRad(jointLimitLeg1FP));
00071     CLIP(jointDataBuffer.frame[i].data[JointData::legFL2], toMicroRad(jointLimitLeg2N), toMicroRad(jointLimitLeg2P));
00072     CLIP(jointDataBuffer.frame[i].data[JointData::legFL3], toMicroRad(jointLimitLeg3N), toMicroRad(jointLimitLeg3P));
00073     CLIP(jointDataBuffer.frame[i].data[JointData::legHR1], toMicroRad(jointLimitLeg1HN), toMicroRad(jointLimitLeg1HP));
00074     CLIP(jointDataBuffer.frame[i].data[JointData::legHR2], toMicroRad(jointLimitLeg2N), toMicroRad(jointLimitLeg2P));
00075     CLIP(jointDataBuffer.frame[i].data[JointData::legHR3], toMicroRad(jointLimitLeg3N), toMicroRad(jointLimitLeg3P));
00076     CLIP(jointDataBuffer.frame[i].data[JointData::legHL1], toMicroRad(jointLimitLeg1HN), toMicroRad(jointLimitLeg1HP));
00077     CLIP(jointDataBuffer.frame[i].data[JointData::legHL2], toMicroRad(jointLimitLeg2N), toMicroRad(jointLimitLeg2P));
00078     CLIP(jointDataBuffer.frame[i].data[JointData::legHL3], toMicroRad(jointLimitLeg3N), toMicroRad(jointLimitLeg3P));
00079     CLIP(jointDataBuffer.frame[i].data[JointData::neckTilt], toMicroRad(jointLimitNeckTiltN), toMicroRad(jointLimitNeckTiltP));
00080     CLIP(jointDataBuffer.frame[i].data[JointData::headPan], toMicroRad(jointLimitHeadPanN), toMicroRad(jointLimitHeadPanP));
00081     CLIP(jointDataBuffer.frame[i].data[JointData::headTilt], toMicroRad(jointLimitHeadTiltN), toMicroRad(jointLimitHeadTiltP));
00082   }
00083 }
00084 
00085 
00086 #define SET_STAYASFORCED(joint,tolerance) \
00087 setStayAsForcedValue(sensorData,jointData, SensorData::joint,JointData::joint,tolerance)
00088 
00089 void DebugMotionControl::executeStayAsForced(
00090                                              const SensorData& sensorData,
00091                                              JointData& jointData
00092                                              )
00093 {
00094   SET_STAYASFORCED(neckTilt,100000);
00095   SET_STAYASFORCED(headPan,100000);
00096   SET_STAYASFORCED(headTilt,50000);
00097   SET_STAYASFORCED(legFL1,100000);
00098   SET_STAYASFORCED(legHL1,100000);
00099   SET_STAYASFORCED(legFR1,100000);
00100   SET_STAYASFORCED(legHR1,100000);
00101   SET_STAYASFORCED(legFL2,100000);
00102   SET_STAYASFORCED(legHL2,100000);
00103   SET_STAYASFORCED(legFR2,100000);
00104   SET_STAYASFORCED(legHR2,100000);
00105   SET_STAYASFORCED(legFL3,100000);
00106   SET_STAYASFORCED(legHL3,100000);
00107   SET_STAYASFORCED(legFR3,100000);
00108   SET_STAYASFORCED(legHR3,100000);
00109   SET_STAYASFORCED(mouth,100000);
00110 }
00111 
00112 void DebugMotionControl::setStayAsForcedValue(
00113                                               const SensorData& sensorData,
00114                                               JointData& jointData,
00115                                               SensorData::sensors sensor,
00116                                               JointData::JointID joint,
00117                                               long tolerance
00118                                               )
00119 {
00120   if (jointData.data[joint] == jointDataInvalidValue)
00121   {
00122     if (
00123       ((stayAsForcedOldValue.data[joint] - sensorData.data[sensor]) > tolerance)  ||
00124       ((stayAsForcedOldValue.data[joint] - sensorData.data[sensor]) < -tolerance)
00125       )
00126       jointData.data[joint] = stayAsForcedOldValue.data[joint] = sensorData.data[sensor];
00127     else
00128       jointData.data[joint] = stayAsForcedOldValue.data[joint];
00129   }
00130 }
00131 
00132 /*
00133 * Change log :
00134 * 
00135 * $Log: DebugMotionControl.cpp,v $
00136 * Revision 1.2  2004/05/27 17:13:37  jhoffman
00137 * - renaming: tilt1 -> neckTilt,  pan -> headPan,  tilt2 -> headTilt
00138 * - clipping included for setJoints
00139 * - removed some microrad/rad-bugs
00140 * - bodyPosture constructor and "=" operator fixed
00141 *
00142 * Revision 1.1.1.1  2004/05/22 17:20:35  cvsadm
00143 * created new repository GT2004_WM
00144 *
00145 * Revision 1.4  2004/03/11 17:02:27  risler
00146 * different limits for front and hind leg joint 1 for ERS-7
00147 *
00148 * Revision 1.3  2004/03/10 10:44:33  risler
00149 * stay as forced for mouth
00150 *
00151 * Revision 1.2  2004/01/07 16:59:19  loetzsch
00152 * added a clipping function
00153 *
00154 * Revision 1.1  2003/10/06 14:10:13  cvsadm
00155 * Created GT2004 (M.J.)
00156 *
00157 * Revision 1.1.1.1  2003/07/02 09:40:24  cvsadm
00158 * created new repository for the competitions in Padova from the 
00159 * tamara CVS (Tuesday 2:00 pm)
00160 *
00161 * removed unused solutions
00162 *
00163 * Revision 1.4  2003/05/02 18:26:18  risler
00164 * SensorDataBuffer added
00165 * replaced SensorData with SensorDataBuffer
00166 * full SensorData resolution now accessible
00167 *
00168 * Revision 1.3  2002/11/19 17:14:14  risler
00169 * coding conventions: renamed JointData::joint to JointID, GetName to getName
00170 *
00171 * Revision 1.2  2002/09/11 00:06:58  loetzsch
00172 * continued change of module/solution mechanisms
00173 *
00174 * Revision 1.1  2002/09/10 15:36:15  cvsadm
00175 * Created new project GT2003 (M.L.)
00176 * - Cleaned up the /Src/DataTypes directory
00177 * - Removed challenge related source code
00178 * - Removed processing of incoming audio data
00179 * - Renamed AcousticMessage to SoundRequest
00180 *
00181 * Revision 1.2  2002/07/23 13:33:40  loetzsch
00182 * new streaming classes
00183 *
00184 * removed many #include statements
00185 *
00186 * Revision 1.1.1.1  2002/05/10 12:40:15  cvsadm
00187 * Moved GT2002 Project from ute to tamara.
00188 *
00189 * Revision 1.8  2002/04/05 14:08:43  jhoffman
00190 * stabilizer stuff
00191 *
00192 * Revision 1.7  2002/02/23 14:51:23  risler
00193 * increased tolerance values
00194 *
00195 * Revision 1.6  2002/02/21 16:29:21  risler
00196 * added JointDataSequencer
00197 *
00198 * Revision 1.5  2002/02/13 16:21:05  risler
00199 * increased stay-as-forced tolerance values
00200 *
00201 * Revision 1.4  2002/02/11 16:37:52  risler
00202 * adjusted stay-as-forced tolerance values
00203 *
00204 * Revision 1.3  2002/02/08 22:38:13  risler
00205 * added JointDataSequence, finished DebugMotionControl
00206 *
00207 * Revision 1.2  2002/02/08 22:31:46  risler
00208 * added JointDataSequence, finished DebugMotionControl
00209 *
00210 * Revision 1.1  2002/02/08 20:00:01  risler
00211 * added DebugMotionControl
00212 *
00213 */

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