00001 #include "synchronization/guid.h" 00002 #include <assert.h> 00003 00004 #include "CollisionDetectors\CollisionDetectorBase.h" 00005 #include "Paths\PathBase.h" 00006 #include "Planners\PlannerBase.h" 00007 00008 PlannerBase::PlannerBase () 00009 : m_UseSemaphores( true ), 00010 timeLimitInSeconds(100), 00011 planSuccessful(false), 00012 paramBuffer(NULL), 00013 sizeOfParameterBuffer(0), 00014 guid( GuidGenerator::GenerateNewGuid() ) 00015 { 00016 } 00017 00018 00019 PlannerBase::~PlannerBase() 00020 { 00021 if (paramBuffer) 00022 free(paramBuffer); 00023 } 00024 00025 void* PlannerBase::GetParameters() 00026 { 00027 if (paramBuffer) 00028 memset(paramBuffer, 0, sizeOfParameterBuffer); 00029 00030 return paramBuffer; 00031 } 00032 00033 bool PlannerBase::SetParameters(const void *param) 00034 { 00035 bool neednewbuffer = false; 00036 int length; 00037 if (paramBuffer == NULL) 00038 { 00039 neednewbuffer = true; 00040 } 00041 else 00042 { 00043 length = strlen((char*)param); 00044 if (length >= sizeOfParameterBuffer) 00045 { 00046 neednewbuffer = true; 00047 } 00048 } 00049 00050 if (neednewbuffer) 00051 { 00052 void *newBuffer = malloc(length + 1); 00053 if (newBuffer) 00054 { 00055 if (paramBuffer) 00056 delete paramBuffer; 00057 sizeOfParameterBuffer = length + 1; 00058 paramBuffer = (char *)newBuffer; 00059 } 00060 else 00061 return false; 00062 } 00063 00064 strcpy(paramBuffer, (char *)param); 00065 return true; 00066 } 00067 00068 bool PlannerBase::ValidateParameters() 00069 { 00070 return true; 00071 } 00072 00073 void PlannerBase::SetCollisionDetector (CollisionDetectorBase* collisionDetector) 00074 { 00075 assert( false ); 00076 } 00077 00078 bool PlannerBase::HasTimeLimitExpired () const 00079 { 00080 double elapsedTime = timer.ElapsedTime(); 00081 if( elapsedTime > this->timeLimitInSeconds ) 00082 { 00083 return true; 00084 } 00085 else 00086 { 00087 return false; 00088 } 00089 } 00090 00091 void PlannerBase::StartTimer () const 00092 { 00093 timer.Start(); 00094 } 00095 00096 void PlannerBase::SetTimeLimitInSeconds (double newTimeLimit) 00097 { 00098 this->timeLimitInSeconds = newTimeLimit; 00099 //IMPROVE: what if the timer is already past this? 00100 } 00101 00102 bool PlannerBase::Save (const char *filename) const 00103 { 00104 return false; 00105 } 00106 00107 bool PlannerBase::Load (const char *filename) 00108 { 00109 return false; 00110 } 00111 00112 bool PlannerBase::GetPlanSuccess () const 00113 { 00114 return this->planSuccessful; 00115 } 00116 00117 void PlannerBase::SetPlanSuccess (bool success) 00118 { 00119 this->planSuccessful = success; 00120 } 00121 00122 //============================================================================= 00123 // GetTimeElapsedInSeconds 00124 // 00125 // Description: allows you to deterimine how much time elapsed during planning 00126 //============================================================================= 00127 double PlannerBase::GetTimeElapsedInSeconds() const 00128 { 00129 double elapsedTime = timer.ElapsedTime(); 00130 return elapsedTime; 00131 } 00132 00133 double PlannerBase::GetTimeLimitInSeconds () const 00134 { 00135 return this->timeLimitInSeconds; 00136 } 00137 00138 //============================================================================= 00139 // CopySettings 00140 // 00141 // Description: copy the settings from a previous instance of this planner 00142 //============================================================================= 00143 void PlannerBase::CopySettings( PlannerBase* original ) 00144 { 00145 assert( false ); 00146 } 00147 00148 int PlannerBase::GetGuid() const 00149 { 00150 return this->guid; 00151 } 00152 00153 //============================================================================= 00154 // PlannerBase::GetStartConfig 00155 // 00156 // Description: allow access to these members 00157 //============================================================================= 00158 const Configuration& PlannerBase::GetStartConfig() const 00159 { 00160 return startConfig; 00161 } 00162 00163 //============================================================================= 00164 // PlannerBase::GetGoalConfig 00165 // 00166 // Description: allow access to these members 00167 //============================================================================= 00168 const Configuration& PlannerBase::GetGoalConfig() const 00169 { 00170 return goalConfig; 00171 } 00172 00173 //============================================================================= 00174 // PlannerBase::SetStartConfig 00175 // 00176 // Description: allow access to these members 00177 //============================================================================= 00178 void PlannerBase::SetStartConfig( const Configuration& configuration ) 00179 { 00180 startConfig = configuration ; 00181 } 00182 00183 //============================================================================= 00184 // PlannerBase::SetGoalConfig 00185 // 00186 // Description: allow access to these members 00187 //============================================================================= 00188 void PlannerBase::SetGoalConfig (const Configuration& configuration) 00189 { 00190 goalConfig = configuration ; 00191 } 00192