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

Modules/SpecialActions/GT2003MotionNetSpecialActions/GT2003MotionNetSpecialActions.cpp

Go to the documentation of this file.
00001 /**
00002 * @file GT2003MotionNetSpecialActions.cpp
00003 * 
00004 * This file contains a class for GT2003 motion net special actions.
00005 * @author Uwe Düffert, Max Risler
00006 */
00007 
00008 #include "GT2003MotionNetSpecialActions.h"
00009 #include "Tools/Streams/InStreams.h"
00010 #include "Tools/RobotConfiguration.h"
00011 #include "Tools/Debugging/Debugging.h"
00012 
00013 GT2003MotionNetSpecialActions::GT2003MotionNetSpecialActions
00014 (SpecialActionsInterfaces& interfaces)
00015 : SpecialActions(interfaces),lastDataValid(false),dataRepetitionCounter(0),
00016   lastSpecialActionType(SpecialActionRequest::numOfSpecialAction)
00017 {
00018   InConfigFile* file = new InConfigFile("spec_act.dat");
00019 
00020   motionNetData.load(*file);
00021 
00022   delete file;
00023 
00024   readOdometryTable();
00025   
00026   // create an uninitialised motion request to set startup motion
00027   SpecialActionRequest mr;
00028   currentNode=motionNetData.label_extern_start[(int)mr.specialActionType];
00029 }
00030 
00031 void GT2003MotionNetSpecialActions::readOdometryTable()
00032 {
00033   char fileEntry[256];
00034   double tmp;
00035   int i,t;
00036   char leaveWalkingEngineCycle[1000];
00037   
00038   // initialise executedMotionRequest entries
00039   for (i=0; i<SpecialActionRequest::numOfSpecialAction; i++) 
00040   {
00041     executedMotionRequestTable[i].motionType = MotionRequest::specialAction;
00042     executedMotionRequestTable[i].specialActionRequest.specialActionType = (SpecialActionRequest::SpecialActionID)i;
00043   }
00044   //entry for extern
00045   executedMotionRequestTable[i].motionType = MotionRequest::specialAction;
00046   executedMotionRequestTable[i].specialActionRequest.specialActionType = (SpecialActionRequest::SpecialActionID)0;
00047   
00048   // read entries from file
00049   InConfigFile odometryFile("Odometry.cfg","GT2003MotionNetSpecialActions");
00050   if (!odometryFile.exists() || odometryFile.eof()) {
00051     OUTPUT(idText,text,"GT2003MotionNetSpecialActions : Error, odometry not found.");
00052   } else {
00053     while(!odometryFile.eof()) {
00054       odometryFile >> fileEntry;
00055       if (fileEntry[0] == '[') break; //next section
00056       if (strlen(fileEntry) > 0) {
00057         for (i=0; i<SpecialActionRequest::numOfSpecialAction; i++) {
00058           if (strcmp(fileEntry,SpecialActionRequest::getSpecialActionIDName((SpecialActionRequest::SpecialActionID)i))==0) {
00059             odometryFile >> t;
00060             switch(t) {
00061             case 0:
00062               // no odometry
00063               odometryTable[i].type = OdometryEntry::none;
00064               break;
00065             case 1:
00066               // once
00067               odometryTable[i].type = OdometryEntry::once;
00068               odometryFile >> odometryTable[i].o.translation.x;
00069               odometryFile >> odometryTable[i].o.translation.y;
00070               odometryFile >> tmp;
00071               odometryTable[i].o.fromAngle(tmp);
00072               break;
00073             case 2:
00074               // homogeneous
00075               odometryTable[i].type = OdometryEntry::homogeneous;
00076               odometryFile >> odometryTable[i].o.translation.x;
00077               odometryFile >> odometryTable[i].o.translation.y;
00078               odometryFile >> tmp;
00079               odometryTable[i].o.fromAngle(tmp);
00080               // convert from mm/seconds to mm/tick
00081               double motionCycleTime = getRobotConfiguration().getRobotDimensions().motionCycleTime;
00082               odometryTable[i].o.translation.x *= motionCycleTime;
00083               odometryTable[i].o.translation.y *= motionCycleTime;
00084               // convert from rad/seconds to rad/tick
00085               odometryTable[i].o.rotation *= motionCycleTime;
00086               break;
00087             }
00088             odometryFile >> motionInfoTable[i].neckHeight;
00089             odometryFile >> t;
00090             motionInfoTable[i].motionIsStable = (t!=0);
00091             motionInfoTable[i].executedMotionRequest.motionType = MotionRequest::specialAction;
00092             motionInfoTable[i].executedMotionRequest.specialActionRequest.specialActionType = (SpecialActionRequest::SpecialActionID)i;
00093             // body-tilt invalid, get other tilt from bodyPosture
00094             motionInfoTable[i].bodyTilt = 0;
00095             odometryFile >> leaveWalkingEngineCycle;
00096             odometryTable[i].o.walkCycleDissection = strlen(leaveWalkingEngineCycle);
00097             {
00098               for(unsigned int j = 0; j < strlen(leaveWalkingEngineCycle); ++j)
00099               {
00100                 if(leaveWalkingEngineCycle[j] == 'A')
00101                 {
00102                   odometryTable[i].o.leaveWalkCycleSections.push_back(j);
00103                 }
00104               }
00105             }
00106             break;
00107           }
00108         }
00109         if (i==SpecialActionRequest::numOfSpecialAction) {
00110           OUTPUT(idText,text,"GT2003MotionNetSpecialActions : Error, invalid odometry entry for :");
00111           OUTPUT(idText,text,fileEntry);
00112         }
00113       }
00114     }
00115   }
00116 }
00117 
00118 bool GT2003MotionNetSpecialActions::getNextData(const SpecialActionRequest& specialActionRequest)
00119 {
00120   while((MotionNetNode::NodeType)motionNetData.nodeArray[currentNode].d[0] != MotionNetNode::typeData)
00121   {
00122     switch ((MotionNetNode::NodeType)motionNetData.nodeArray[currentNode].d[0])
00123     {
00124     case MotionNetNode::typePID:
00125       {
00126         // set pid values
00127         motionNetData.nodeArray[currentNode++].toPIDData(pidData);
00128         break;
00129       }
00130     case MotionNetNode::typeConditionalTransition:
00131       if ((motionRequest.motionType != MotionRequest::specialAction)||
00132         (motionNetData.nodeArray[currentNode].d[2] != (short) specialActionRequest.specialActionType))
00133       {
00134         currentNode++;
00135         break;
00136       }
00137       //no break here: if condition is true, continue with transition!
00138     case MotionNetNode::typeTransition:
00139       // follow transition
00140       if (currentNode==0)
00141       {
00142         //we come from extern
00143         if (motionRequest.motionType == MotionRequest::specialAction)
00144         {
00145           currentNode = motionNetData.label_extern_start[(short)specialActionRequest.specialActionType];
00146         }
00147       }
00148       else
00149       {
00150         currentNode = motionNetData.nodeArray[currentNode].d[1];
00151       }
00152       // leave if transition to external motion
00153       if (currentNode==0)
00154       {
00155         return false;
00156       }
00157       break;
00158     }
00159   }
00160   
00161   motionNetData.nodeArray[currentNode].toJointData(currentData, dataRepetitionLength, interpolationMode);
00162   dataRepetitionCounter = dataRepetitionLength;
00163 
00164   //get neckHeight and wanted MotionRequest fromMotionInfoTable:
00165   motionNetData.nodeArray[currentNode++].toExecutedMotionRequest(motionInfo.executedMotionRequest);
00166   motionInfo.bodyTilt = motionInfoTable[motionInfo.executedMotionRequest.specialActionRequest.specialActionType].bodyTilt;
00167   motionInfo.motionIsStable = motionInfoTable[motionInfo.executedMotionRequest.specialActionRequest.specialActionType].motionIsStable;
00168   motionInfo.neckHeight = motionInfoTable[motionInfo.executedMotionRequest.specialActionRequest.specialActionType].neckHeight;
00169  
00170   //get currently executed MotionRequest from motion net traversal:
00171   if (
00172     motionInfo.executedMotionRequest.motionType == MotionRequest::specialAction &&
00173     motionInfo.executedMotionRequest.specialActionRequest.specialActionType != lastSpecialActionType)
00174   {
00175     currentOdometry = odometryTable[motionInfo.executedMotionRequest.specialActionRequest.specialActionType];
00176     lastSpecialActionType = motionInfo.executedMotionRequest.specialActionRequest.specialActionType;
00177   }
00178   
00179   return true;
00180 }
00181 
00182 bool GT2003MotionNetSpecialActions::handleMessage(InMessage& message)
00183 {
00184   if (message.getMessageID() == idMotionNet)
00185   {
00186     motionNetData.load(message.config);
00187     return true;
00188   }
00189   return false;
00190 }
00191 
00192 void GT2003MotionNetSpecialActions::calculateJointData(JointData& jointData)
00193 {
00194   if (interpolationMode && lastDataValid) {
00195     for (int i=0;i<JointData::numOfJoint;i++)
00196       if (lastData.data[i] == jointDataInvalidValue)
00197         jointData.data[i] = currentData.data[i];
00198       else if (currentData.data[i] == jointDataInvalidValue)
00199         jointData.data[i] = jointDataInvalidValue;
00200       else
00201         jointData.data[i] = currentData.data[i] +
00202         (lastData.data[i] - currentData.data[i]) * 
00203         dataRepetitionCounter / dataRepetitionLength;
00204   } else
00205     jointData = currentData;
00206 }
00207 
00208 bool GT2003MotionNetSpecialActions::executeParameterized(SpecialActionRequest specialActionRequest, JointData& jointData)
00209 {
00210   if (dataRepetitionCounter <= 0)
00211   {
00212     if (lastMotionType != MotionRequest::specialAction)
00213     {
00214       //entered from external motion
00215       currentNode=0;
00216       lastDataValid = false;
00217       lastSpecialActionType = SpecialActionRequest::numOfSpecialAction;
00218     }
00219     // search next data, leave on transition to external motion
00220     if (!getNextData(specialActionRequest))
00221       return false;
00222   }
00223   else
00224     dataRepetitionCounter--;
00225   
00226   //set current joint values
00227   calculateJointData(jointData);
00228   
00229   //odometry update
00230   if (currentOdometry.type == OdometryEntry::homogeneous)
00231     odometryData.conc(currentOdometry.o);
00232   else if (currentOdometry.type == OdometryEntry::once) {
00233     odometryData.conc(currentOdometry.o);
00234     currentOdometry.type = OdometryEntry::none;
00235   }
00236   
00237   //store value if current data line finished
00238   if (dataRepetitionCounter <= 0) {
00239     lastData = currentData;
00240     lastDataValid = true;
00241   }
00242   return true;
00243 }
00244 bool GT2003MotionNetSpecialActions::specialActionIsExecutableInWalkingCycle(int specialActionID, double walkCycle){
00245   if(odometryTable[specialActionID].o.walkCycleDissection)
00246   {
00247     for(unsigned int i = 0; i < odometryTable[specialActionID].o.leaveWalkCycleSections.size();++i)
00248     {
00249       if((double)odometryTable[specialActionID].o.leaveWalkCycleSections[i]/(double)odometryTable[specialActionID].o.walkCycleDissection <= walkCycle 
00250         && (double)odometryTable[specialActionID].o.leaveWalkCycleSections[i]+(1.0/(double)odometryTable[specialActionID].o.walkCycleDissection) >= walkCycle)
00251         return true;
00252     }
00253   }
00254   
00255   return false;
00256 }
00257 
00258 
00259 
00260 /*
00261 * Change log :
00262 * 
00263 * $Log: GT2003MotionNetSpecialActions.cpp,v $
00264 * Revision 1.11  2004/06/24 15:37:32  risler
00265 * bugfix reset lastSpecialActionType so that odometry is set correctly when repeating the last special action
00266 *
00267 * Revision 1.10  2004/06/18 00:07:46  spranger
00268 * bugfixxx
00269 *
00270 * Revision 1.9  2004/06/14 15:04:48  spranger
00271 * changed interface of executeParametrized
00272 * (this is not final, the specialActionRequest will be put into the interface)
00273 *
00274 * Revision 1.8  2004/06/09 11:29:51  thomas
00275 * modified to remove warning
00276 *
00277 * Revision 1.7  2004/06/02 17:18:23  spranger
00278 * MotionRequest cleanup
00279 *
00280 * Revision 1.6  2004/05/27 19:00:31  loetzsch
00281 * bug fix
00282 *
00283 * Revision 1.5  2004/05/27 18:20:49  spranger
00284 * motionControl cleaned up
00285 *
00286 * Revision 1.4  2004/05/27 09:29:28  loetzsch
00287 * removed executedMotionRequest from Interfaces
00288 *
00289 * Revision 1.3  2004/05/26 17:37:30  dueffert
00290 * comments fixed
00291 *
00292 * Revision 1.2  2004/05/26 17:21:47  dueffert
00293 * better data types used
00294 *
00295 * Revision 1.1.1.1  2004/05/22 17:21:31  cvsadm
00296 * created new repository GT2004_WM
00297 *
00298 * Revision 1.5  2004/03/20 09:55:25  roefer
00299 * Preparation for improved odometry
00300 *
00301 * Revision 1.4  2004/01/03 16:36:13  roefer
00302 * motionCycleTime 8 ms -> 0.008 s
00303 *
00304 * Revision 1.3  2004/01/01 10:58:50  roefer
00305 * RobotDimensions are in a class now
00306 *
00307 * Revision 1.2  2003/12/16 19:01:18  loetzsch
00308 * The motion net is not compiled into a C++ file but parsed at run time.
00309 *
00310 * Revision 1.1  2003/10/06 14:10:12  cvsadm
00311 * Created GT2004 (M.J.)
00312 *
00313 * Revision 1.2  2003/09/26 11:38:52  juengel
00314 * - sorted tools
00315 * - clean-up in DataTypes
00316 *
00317 * Revision 1.1.1.1  2003/07/02 09:40:24  cvsadm
00318 * created new repository for the competitions in Padova from the 
00319 * tamara CVS (Tuesday 2:00 pm)
00320 *
00321 * removed unused solutions
00322 *
00323 * Revision 1.4  2003/06/21 14:55:06  risler
00324 * odometry only once per special action
00325 *
00326 * Revision 1.3  2003/04/06 19:41:30  dueffert
00327 * 2001 renamed to 2003
00328 *
00329 * Revision 1.2  2003/03/19 09:22:02  dueffert
00330 * executedMotionRequest support added
00331 *
00332 * Revision 1.1  2003/03/10 14:14:08  dueffert
00333 * optimized MotionNet
00334 *
00335 * Revision 1.6  2003/03/07 11:18:33  juengel
00336 * headState.bodyRoll and headState.bodyTilt are not overwritten.
00337 *
00338 * Revision 1.5  2003/03/06 12:06:50  dueffert
00339 * execute with parameters renamed to avoid inheritance warnings
00340 *
00341 * Revision 1.4  2002/11/20 18:02:29  risler
00342 * added PID values to GT2001MotionNetSpecialActions
00343 * added playDead motion
00344 *
00345 * Revision 1.3  2002/09/22 18:40:54  risler
00346 * added new math functions, removed GTMath library
00347 *
00348 * Revision 1.2  2002/09/17 23:55:22  loetzsch
00349 * - unraveled several datatypes
00350 * - changed the WATCH macro
00351 * - completed the process restructuring
00352 *
00353 * Revision 1.1  2002/09/10 15:36:16  cvsadm
00354 * Created new project GT2003 (M.L.)
00355 * - Cleaned up the /Src/DataTypes directory
00356 * - Removed challenge related source code
00357 * - Removed processing of incoming audio data
00358 * - Renamed AcousticMessage to SoundRequest
00359 *
00360 * Revision 1.4  2002/07/23 13:33:43  loetzsch
00361 * new streaming classes
00362 *
00363 * removed many #include statements
00364 *
00365 * Revision 1.3  2002/06/28 10:26:19  roefer
00366 * OUTPUT is possible in constructors
00367 *
00368 * Revision 1.2  2002/06/11 10:22:21  kallnik
00369 * Pose2D neue Version (RotationVector) fertig
00370 * PLEASE DON'T  READ ROTATION DIRECTLY USE getAngle()
00371 *
00372 * Revision 1.1.1.1  2002/05/10 12:40:16  cvsadm
00373 * Moved GT2002 Project from ute to tamara.
00374 *
00375 * Revision 1.21  2002/05/06 15:26:44  loetzsch
00376 * added several ";" after PRINT macros. (Didn't compile in Release version)
00377 *
00378 * Revision 1.20  2002/05/05 15:14:23  risler
00379 * changed stand implementation
00380 *
00381 * Revision 1.19  2002/05/04 18:23:43  risler
00382 * added calculation of executedMotionRequest
00383 *
00384 * Revision 1.18  2002/04/23 10:38:30  risler
00385 * renamed headOdometry to headState
00386 *
00387 * Revision 1.17  2002/04/08 17:49:24  risler
00388 * removed body tilt from odometry
00389 *
00390 * Revision 1.16  2002/04/02 14:01:39  dueffert
00391 * minor odometry enhancements
00392 *
00393 * Revision 1.15  2002/04/02 13:10:20  dueffert
00394 * big change: odometryData and cameraMatrix in image now, old logfiles may be obsolete
00395 *
00396 * Revision 1.14  2002/03/28 13:41:03  dueffert
00397 * cast warning removed
00398 *
00399 * Revision 1.13  2002/03/27 15:54:28  risler
00400 * added neckHeight and stableMotion in motion modules
00401 *
00402 * Revision 1.12  2002/02/13 01:41:24  risler
00403 * no message
00404 *
00405 * Revision 1.11  2002/02/13 01:29:06  risler
00406 * fixed crash on unsupported motion type
00407 *
00408 * Revision 1.10  2001/12/18 14:02:06  risler
00409 * different odometry types in GT2001MotionNetSpecialActions
00410 *
00411 * Revision 1.9  2001/12/16 10:54:06  risler
00412 * added InConfigFile
00413 *
00414 * Revision 1.8  2001/12/15 12:28:39  roefer
00415 * SpecialActionsOdometry.cfg renamed to SAOdo.cfg
00416 *
00417 * Revision 1.7  2001/12/14 14:08:09  risler
00418 * added odometry updates
00419 *
00420 * Revision 1.6  2001/12/13 19:13:58  risler
00421 * added odometry updates in GT2001MotionNetSpecialActions
00422 *
00423 * Revision 1.5  2001/12/13 18:49:25  risler
00424 * added odometry updates in GT2001MotionNetSpecialActions
00425 *
00426 * Revision 1.4  2001/12/12 12:43:33  risler
00427 * removed MotionRequest.specialActionParams and MotionNetNode.pval
00428 *
00429 * Revision 1.3  2001/12/10 17:47:07  risler
00430 * change log added
00431 *
00432 */

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