00001 //## begin module%3775A6140215.cm preserve=no 00002 // %X% %Q% %Z% %W% 00003 //## end module%3775A6140215.cm 00004 00005 //## begin module%3775A6140215.cp preserve=no 00006 //## end module%3775A6140215.cp 00007 00008 //## Module: PL_IanRandom%3775A6140215; Pseudo Package body 00009 //## Source file: E:\mpk\code\Planners\PL_IanRandom.cpp 00010 00011 //## begin module%3775A6140215.additionalIncludes preserve=no 00012 //## end module%3775A6140215.additionalIncludes 00013 00014 //## begin module%3775A6140215.includes preserve=yes 00015 //## end module%3775A6140215.includes 00016 00017 // PL_IanRandom 00018 #include "PL_IanRandom.h" 00019 //## begin module%3775A6140215.additionalDeclarations preserve=yes 00020 //## end module%3775A6140215.additionalDeclarations 00021 00022 00023 // Class PL_IanRandom 00024 00025 PL_IanRandom::~PL_IanRandom() 00026 { 00027 //## begin PL_IanRandom::~PL_IanRandom%.body preserve=yes 00028 //## end PL_IanRandom::~PL_IanRandom%.body 00029 } 00030 00031 00032 00033 //## Other Operations (implementation) 00034 bool PL_IanRandom::Plan () 00035 { 00036 //## begin PL_IanRandom::Plan%930457209.body preserve=yes 00037 //always start at the start 00038 path.AppendPoint( GetStartConfig() ) ; 00039 00040 //check the initial and the goal point in a direct line 00041 if( !collisionDetector->IsInterferingLinear( GetStartConfig(), GetGoalConfig() ) ) 00042 { 00043 path.AppendPoint( GetGoalConfig() ) ; 00044 return true ; 00045 } 00046 00047 //start trying some random configurations 00048 for( int i = 0; i < 100000; i++ ) //IMPROVE: don't hardcode the 100 00049 { 00050 Configuration intermediate = GenerateRandomConfig() ; 00051 if( !collisionDetector->IsInterferingLinear( GetStartConfig(), intermediate ) && 00052 !collisionDetector->IsInterferingLinear( intermediate, GetGoalConfig() ) ) 00053 { 00054 path.AppendPoint( intermediate ) ; 00055 path.AppendPoint( GetGoalConfig() ) ; 00056 return true ; 00057 } 00058 00059 //check the timer 00060 if( HasTimeLimitExpired() == true ) 00061 { 00062 return false ; 00063 } 00064 } 00065 return false ; 00066 //## end PL_IanRandom::Plan%930457209.body 00067 } 00068 00069 Configuration PL_IanRandom::GenerateRandomConfig () const 00070 { 00071 //## begin PL_IanRandom::GenerateRandomConfig%930611904.body preserve=yes 00072 int dof = GetStartConfig().DOF() ; 00073 Configuration returnme ; 00074 returnme.SetLength( dof ) ; 00075 00076 for( int i = 0; i < dof; i++ ) 00077 { 00078 double max = collisionDetector->JointMax( i ) ; 00079 double min = collisionDetector->JointMin( i ) ; 00080 double random = double( rand() ) / RAND_MAX ; //this is a random number between [0..1] 00081 returnme[ i ] = min + ( max - min ) * random ; 00082 } 00083 00084 return returnme ; 00085 //## end PL_IanRandom::GenerateRandomConfig%930611904.body 00086 } 00087 00088 Configuration PL_IanRandom::GenerateValidRandomConfig () const 00089 { 00090 //## begin PL_IanRandom::GenerateValidRandomConfig%930611905.body preserve=yes 00091 Configuration returnMe = GenerateRandomConfig() ; 00092 while( collisionDetector->IsInterfering( returnMe ) ) 00093 { 00094 //IMPROVE: this is potentially an infinite loop if the cspace is all blocked up 00095 returnMe = GenerateRandomConfig() ; 00096 } 00097 return returnMe ; 00098 //## end PL_IanRandom::GenerateValidRandomConfig%930611905.body 00099 } 00100 00101 // Additional Declarations 00102 //## begin PL_IanRandom%3775A6140215.declarations preserve=yes 00103 //## end PL_IanRandom%3775A6140215.declarations 00104 00105 //## begin module%3775A6140215.epilog preserve=yes 00106 //## end module%3775A6140215.epilog