planners/inversekin/Active.cpp

Go to the documentation of this file.
00001 
00003 //
00004 //Contents: Class CActive
00005 // 
00006 //Relations:
00007 //      CJoints --> CActive  ---o CRedundant
00008 //            |---> CPassive -|
00009 //
00010 //      Class CActive/CPassive is derived from class CJoints
00011 //      Class CRedundant constains entities of CActive and CPassive
00012 //
00013 //CActive is used for active joint chain. 
00014 //The typical calling sequence is:
00015 //      1.CActive::CActive(...)
00016 //      2.CActive::SetFrameManager(...)
00017 //        CActive::SetRobot(...)
00018 //        CActive::SetFirstJoint(...)
00019 //        CActive::SetLastJoint(...)
00020 //      3.CActive::SetFirstFrame(...)
00021 //        CActive::SetEndEffectFrame(...)
00022 //      4.CActive::SetDesireEndEffect(...)
00023 //      5.CActive::GetConfiguration(...)
00024 //
00025 //Revision History:
00026 //       Date     Author    Description
00027 //      ---------------------------------------------------------
00028 //     Mar-2003:  Z.Yao     First version implemented
00029 //                          
00030 //Others:
00031 //     a.[Mar-2003]
00033 
00034 #include "Active.h"
00035 #include "kinematics/dh_link.h"
00036 #include "math/math2.h"
00037 
00038 #define MAX_ACTIVE_RETRY    100
00039 
00040 //------------------------------------------------------------------
00041 //
00042 //Construction and Deconstruction function
00043 //
00044 //------------------------------------------------------------------
00045 CActive::CActive():CJoints()
00046 {}
00047 
00048 CActive::CActive(FrameManager* frameManager)
00049                 :CJoints(frameManager)
00050 {}
00051 
00052 CActive::~CActive()
00053 {}
00054 
00055 //------------------------------------------------------------------
00056 //This function is used to get active joint variables randomly.
00057 //
00058 //Input Parameter:
00059 //      N.A
00060 //
00061 //Ouput Parameter:
00062 //      conf: A random configuration
00063 //
00064 //Return Value:
00065 //      true, if success; 
00066 //      false, otherwise;
00067 //------------------------------------------------------------------
00068 bool CActive::GetConfiguration(Configuration &conf)
00069 {
00070         conf.SetLength(jointNum);
00071 
00072         if (jointNum==0)
00073                 return true;
00074 
00075 #ifdef _DEBUG
00076 
00077         if ((lastJoint-firstJoint)!=(jointNum-1))
00078                 return false;
00079 #endif
00080 
00081         for( int i = 0; i < jointNum; i++ )
00082         {
00083                 double max = links[firstJoint+i]->JointMax() ;
00084                 double min = links[firstJoint+i]->JointMin() ;
00085                 double random = 2*( double( rand() ) / RAND_MAX ) - 1; //this is a random number between [-1..1]
00086                 double jointvalue = ( max - min ) * random;
00087 
00088                 // Create a uniform distribution by having the random number go over the limits have wrapping the C-space;
00089                 if ( jointvalue < min )
00090                 {
00091                         jointvalue += (max - min);
00092                 }
00093                 else if ( jointvalue > max )
00094                 {
00095                         jointvalue -= (max - min);
00096                 }
00097 
00098                 conf[ i ] = jointvalue;
00099         }
00100 
00101         return true;
00102 }
00103 
00104 //------------------------------------------------------------------
00105 //This function is used to get active joint variables
00106 //in a neighbour area of current configuration;
00107 //
00108 //Input Parameter:
00109 //      current: Given bias configuration
00110 //      dist: Deviation allowed for each joint variables
00111 //
00112 //Ouput Parameter:
00113 //      conf: Satisfactory configuration
00114 //
00115 //Return Value:
00116 //      true, if success; 
00117 //      false, otherwise;
00118 //------------------------------------------------------------------
00119 bool CActive::GetConfiguration(Configuration &conf, Configuration &current, double dist)
00120 {
00121         /*
00122           bool bFind;
00123           int i;
00124           int retry = 0;
00125           Configuration randConf;
00126          
00127           do 
00128           {
00129             bFind = true;
00130             GetConfiguration(randConf);
00131             for (i=0; i<jointNum; i++)
00132             {
00133               if (Distance(links[firstJoint+i], randConf[i], current[i])>dist)
00134               {  
00135                 bFind = false;
00136                 break;
00137               }
00138             }
00139             if (bFind)
00140             {
00141               for (i=0; i<jointNum; i++)
00142                 conf[i] = randConf[i];
00143               break;
00144             }
00145             retry ++;
00146           } while ((!bFind) && (retry<MAX_ACTIVE_RETRY));
00147          
00148           return bFind;
00149         */
00150 
00151         conf.SetLength(jointNum);
00152 
00153         if (jointNum==0)
00154                 return true;
00155 
00156 #ifdef _DEBUG
00157 
00158         if ((lastJoint-firstJoint)!=(jointNum-1))
00159                 return false;
00160 #endif
00161 
00162         for( int i=0; i < jointNum; i++ )
00163         {
00164                 double random = 2*( double( rand() ) / RAND_MAX ) - 1; //this is a random number between [-1..1]
00165                 double jmax = links[firstJoint+i]->JointMax();
00166                 double jmin = links[firstJoint+i]->JointMin();
00167 
00168                 double jointvalue = current[i] + random*dist;
00169                 // Use wrapping of the C-space (for all joints) to ensure normal distribution about seed.
00170 
00171                 if ( jointvalue > jmax )
00172                 {
00173                         //jointvalue -= ( jmax - jmin );
00174                         jointvalue = current[i] + random*(jmax - current[i]);
00175                 }
00176                 else if ( jointvalue < jmin )
00177                 {
00178                         //jointvalue += ( jmax - jmin );
00179                         jointvalue = current[i] + random*(current[i]-jmin);
00180                 }
00181 
00182                 conf[i] = jointvalue;
00183         }
00184 
00185         return true;
00186 }
00187 
00188 

Generated on Sat Apr 1 21:30:43 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO