collisiondetectors/CD_LinearContinuous.cpp

Go to the documentation of this file.
00001 //## begin module%378A7A4B03DD.cm preserve=no
00002 //        %X% %Q% %Z% %W%
00003 //## end module%378A7A4B03DD.cm
00004 
00005 //## begin module%378A7A4B03DD.cp preserve=no
00006 //## end module%378A7A4B03DD.cp
00007 
00008 //## Module: CD_LinearContinuous%378A7A4B03DD; Pseudo Package body
00009 //## Source file: C:\project\mpk\code\CollisionDetectors\CD_LinearContinuous.cpp
00010 
00011 //## begin module%378A7A4B03DD.additionalIncludes preserve=no
00012 //## end module%378A7A4B03DD.additionalIncludes
00013 
00014 //## begin module%378A7A4B03DD.includes preserve=yes
00015 //## end module%378A7A4B03DD.includes
00016 
00017 #include <assert.h>
00018 #include "CollisionDetectors\CD_LinearContinuous.h"
00019 // Universe
00020 #include "Universe\Universe.h"
00021 //## begin module%378A7A4B03DD.additionalDeclarations preserve=yes
00022 //## end module%378A7A4B03DD.additionalDeclarations
00023 
00024 static const int maxSteps = 32;
00025 static const double cspaceResolution = 0.5;
00026 
00027 // Class CD_LinearContinuous 
00028 
00029 CD_LinearContinuous::CD_LinearContinuous (const CD_LinearContinuous& right)
00030   //## begin CD_LinearContinuous::CD_LinearContinuous%931798970.hasinit preserve=no
00031   //## end CD_LinearContinuous::CD_LinearContinuous%931798970.hasinit
00032   //## begin CD_LinearContinuous::CD_LinearContinuous%931798970.initialization preserve=yes
00033   :     
00034         CollisionDetectorBase( right ),
00035         CD_Linear( right ) 
00036   //## end CD_LinearContinuous::CD_LinearContinuous%931798970.initialization
00037 {
00038   //## begin CD_LinearContinuous::CD_LinearContinuous%931798970.body preserve=yes
00039   //## end CD_LinearContinuous::CD_LinearContinuous%931798970.body
00040 }
00041 
00042 CD_LinearContinuous::CD_LinearContinuous (const Universe& universe)
00043   //## begin CD_LinearContinuous::CD_LinearContinuous%931798971.hasinit preserve=no
00044   //## end CD_LinearContinuous::CD_LinearContinuous%931798971.hasinit
00045   //## begin CD_LinearContinuous::CD_LinearContinuous%931798971.initialization preserve=yes
00046   :     
00047         CollisionDetectorBase( universe ),
00048         CD_Linear( universe )
00049   //## end CD_LinearContinuous::CD_LinearContinuous%931798971.initialization
00050 {
00051   //## begin CD_LinearContinuous::CD_LinearContinuous%931798971.body preserve=yes
00052   //## end CD_LinearContinuous::CD_LinearContinuous%931798971.body
00053 }
00054 
00055 
00056 CD_LinearContinuous::~CD_LinearContinuous()
00057 {
00058   //## begin CD_LinearContinuous::~CD_LinearContinuous%.body preserve=yes
00059   //## end CD_LinearContinuous::~CD_LinearContinuous%.body
00060 }
00061 
00062 bool CD_LinearContinuous::IsCompletelyWithinObstacles(const Configuration& c1, const Configuration& c2)
00063 {
00064     return IsCompletelyWithinObstaclesNoWrapping( c1, c2 );
00065 }
00066 
00067 //## Other Operations (implementation)
00068 bool CD_LinearContinuous::IsInterferingLinear (const Configuration& c1, const Configuration& c2)
00069 {
00070         IncrementLinearStat();
00071         if ( useWrapping )
00072         {
00073                 return IsInterferingLinearWrapping( c1, c2 );
00074         }
00075         else
00076         {
00077                 return IsInterferingLinearNoWrapping( c1, c2 );
00078         }
00079 }
00080 
00081 bool CD_LinearContinuous::IsCompletelyWithinObstaclesNoWrapping (const Configuration& c1, const Configuration& c2)
00082 {
00083         //const int steps = maxSteps ;          //IMPROVE: this is not reliable - put it elsewhere
00084         //Configuration offset = ( c2 - c1 ) / ( steps - 1 ) ;
00085         
00086         Configuration offset = c2 - c1;
00087         int steps = offset.Magnitude()/cspaceResolution + 2;
00088         if (steps > maxSteps)
00089                 steps = maxSteps;
00090         offset /= (steps-1);    
00091         Configuration current = c1 ;
00092         for( int i = 0; i < steps; i++ )
00093         {
00094                 if( !IsInterfering( current ) )
00095                 {
00096                         lastIntersection = current ;
00097                         lastValid = lastIntersection - offset;
00098                         return false ;
00099                 }
00100                 current += offset ;
00101         }
00102         lastValid = current;
00103         lastIntersection = current ;
00104         return true ;
00105 }
00106 
00107 bool CD_LinearContinuous::IsCompletelyWithinObstaclesWrapping (const Configuration& c1, const Configuration& c2)
00108 {
00109     assert( false ); //this doesn't work yet
00110     return false;
00111 }
00112 
00113 
00114 bool CD_LinearContinuous::IsInterferingLinearNoWrapping (const Configuration& c1, const Configuration& c2)
00115 {
00116         //const int steps = maxSteps ;          //IMPROVE: this is not reliable - put it elsewhere
00117         //Configuration offset = ( c2 - c1 ) / ( steps - 1 ) ;
00118         Configuration offset = c2 - c1;
00119         int steps = offset.Magnitude()/cspaceResolution + 2;
00120         if (steps > maxSteps)
00121                 steps = maxSteps;
00122         offset /= (steps-1);    
00123         Configuration current = c1 ;
00124         for( int i = 0; i < steps; i++ )
00125         {
00126                 if( IsInterfering( current ) )
00127                 {
00128                         lastIntersection = current ;
00129                         lastValid = lastIntersection - offset;
00130                         return true ;
00131                 }
00132                 current += offset ;
00133         }
00134         lastValid = current;
00135         lastIntersection = current ;
00136         return false ;
00137 }
00138 
00139 bool CD_LinearContinuous::IsInterferingLinearWrapping (const Configuration& c1, const Configuration& c2)
00140 {
00141         assert( false ); //IAN needs to look into this some more
00142         VectorN stepdisp = JointDisplacement( c1, c2 ) / ( maxSteps ); 
00143         Configuration current = c1;
00144 
00145         int dof = c1.DOF();
00146 
00147         // Check starting configuration 
00148         if( IsInterfering( current ) )
00149         {
00150                 lastIntersection = current;
00151                 return true;
00152         }
00153 
00154         // Check all intermediate configurations and final config. ( c2 = c1 + stepdisp*maxsteps )
00155         for (int step = 0; step < maxSteps; step++ )
00156         {
00157                 // advance configuration by the displacement
00158                 current += stepdisp;
00159 
00160                 // check if any of the joints went over the limits and correct.  (Limits will only
00161                 // be exceeded if joints were wrapping.
00162                 for (int i = 0; i < dof; i++)
00163                 {
00164                         double jmin = JointMin( i );
00165                         double jmax = JointMax( i );
00166                         if ( current[i] < jmin )
00167                         {
00168                                 current[i] += (jmax - jmin);    // add joint range ccw to have joint wrap over lower limit.
00169                         }
00170                         else if ( current[i] > jmax )
00171                         {
00172                                 current[i] -= (jmax - jmin);    // add joint range cw to have joint wrap back under upper limit.
00173                         }
00174                 }
00175 
00176                 // check the new config for collision
00177                 if( IsInterfering( current ) )
00178                 {
00179                         lastIntersection = current;
00180                         return true;
00181                 }
00182 
00183         }
00184 
00185         // If still in function, then we have checked all configuration between start and goal config
00186         // linearly, through the shortest wrapping displacement.
00187 
00188         return false;
00189 
00190 }
00191 
00192 // Additional Declarations
00193   //## begin CD_LinearContinuous%378A7A4B03DD.declarations preserve=yes
00194   //## end CD_LinearContinuous%378A7A4B03DD.declarations
00195 
00196 //## begin module%378A7A4B03DD.epilog preserve=yes
00197 //## end module%378A7A4B03DD.epilog

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