00001 00002 // 00003 //Contents: Class TrajPlanner; base class of local planners used in APACE. 00004 // Class RRT_TrajPlanner; probabilistic local planner. 00005 // Class Jacobian_TrajPlanner; Jacobian-based local planner. 00006 // 00007 //Revision History: 00008 // Date Author Description 00009 // --------------------------------------------------------- 00010 // Jun-2004: Z.Yao First version implemented 00011 // Nov-2004: Z.Yao Comments added 00012 // 00013 //Notes: 00014 // 1. The typical procedure to call the local planner is 00015 // a. Set start/goal: SetStartConfig()/SetGoalPose()/.. 00016 // b. Set the given end-effector trajectory: SetTrajectory(..) 00017 // c. Set Parameters. 00018 // d. Begin planning: Plan() 00019 // 2. Different collision detectors are created for different local planner 00020 // a. RRT_TrajPlanner: V_Collide; 00021 // b. Jacobian_TrajPlanner: SWIFT++; 00022 // 3. More Reference: 00023 // a. RRT_TrajPlanner: PL_MPEP; 00024 // b. Jacobian_TrajPlanner: IK_Jacobian; 00025 // 4. Since these local planners work under APACE framework, which is a 00026 // glboal framework. So, we can make our "local" planners local and easy. 00027 // For example, when using $RRT_TrajPlanner$, we set the connecting strategy 00028 // to the simplest one: GREEDY, with small number of retries. 00029 // 00031 00032 #include "collisiondetectors/CD_Swiftpp.h" 00033 #include "LocalPlanner.h" 00034 #include "Planners/ik_mpep/PL_MPEP.h" 00035 #include "math/Vector4.h" 00036 //#include "math\math2.h" 00037 #include "debug/debug.h" 00038 00039 #define SAMPLE_RESOLUTION 0.4 00040 00041 00042 //========================== Start of Trajectory Local Planner ==================== 00043 // 00044 TrajPlanner::TrajPlanner() 00045 { 00046 //LogMessage("LocalPlanner.log", "====================== Open Planner ========================"); 00047 } 00048 00049 TrajPlanner::~TrajPlanner() 00050 { 00051 //LogMessage("LocalPlanner.log", "====================== Close Planner ========================"); 00052 } 00053 00054 bool TrajPlanner::DrawExplicit () const 00055 { 00056 Sleep(100); 00057 return true; 00058 } 00059 00060 //========================== Start of RRT Local Planner ==================== 00061 RRT_TrajPlanner::RRT_TrajPlanner() 00062 { 00063 planner = new( PL_MPEP ); 00064 } 00065 00066 RRT_TrajPlanner::~RRT_TrajPlanner() 00067 { 00068 delete planner; 00069 } 00070 00071 //Inherited form ancestor 00072 void RRT_TrajPlanner::SetCollisionDetector (CD_BasicStyle* collisionDetector) 00073 { 00074 planner->SetCollisionDetector(collisionDetector); 00075 } 00076 00077 void RRT_TrajPlanner::SetStartConfig( const Configuration& config ) 00078 { 00079 planner->SetStartConfig(config); 00080 } 00081 00082 void RRT_TrajPlanner::SetGoalConfig( const Configuration& config) 00083 { 00084 planner->SetGoalConfig(config); 00085 } 00086 00087 void RRT_TrajPlanner::SetTrajectory(std::vector<Frame> &poses) 00088 { 00089 m_nNumPose = poses.size(); 00090 planner->SetTrajectory(poses); 00091 } 00092 00093 bool RRT_TrajPlanner::Plan () 00094 { 00095 UINT passiveNum = 3; 00096 double tolerance = 0.1; 00097 int algorithm = ALG_GREEDY_PLANNER;//ALG_SMG_GREEDY_PLANNER; //ALG_GREEDY_PLANNER;//ALG_RRT_CONNECT_LIKE; 00098 bool useStartConf = true; 00099 bool useGoalConf = m_bUseGoalConfig; 00100 UINT randomRetry = 50; 00101 UINT extendNum = 50; 00102 UINT iterationNum = 1; 00103 UINT nodeInSMG = 5;//10; 00104 UINT exploreNum = 10;//20; 00105 00106 //if (m_bUseGoalConfig) 00107 //{ 00108 // algorithm = ALG_SMG_CONNECT_PLANNER; 00109 // extendNum = m_nNumPose * 10; 00110 // planner->SetSMGNodeNum(nodeInSMG); 00111 //} 00112 00113 if (!m_bUseOrientation) 00114 passiveNum = 2; 00115 00116 planner->SetPassiveNum(passiveNum); 00117 planner->SetAlgorithm(algorithm); 00118 planner->SetTolerance(tolerance); 00119 planner->SetUsingStartConfig(useStartConf); 00120 planner->SetUsingGoalConfig(useGoalConf); 00121 planner->SetRandomRetry(randomRetry); 00122 planner->SetExtendNum(extendNum); 00123 planner->SetIterationNum(iterationNum); 00124 planner->SetExploreNum(exploreNum); 00125 00126 if (planner->Plan()) 00127 { 00128 path = *((PA_Points *)planner->GetPath()); 00129 return true; 00130 } 00131 else 00132 { 00133 return false; 00134 } 00135 } 00136 00137 //==================== Start of Jacobian-base Local Planner ============== 00138 // 00139 Jacobian_TrajPlanner::Jacobian_TrajPlanner() 00140 { 00141 planner = new( IK_Jacobian ); 00142 pCollisionDetector = NULL; 00143 } 00144 00145 Jacobian_TrajPlanner::~Jacobian_TrajPlanner() 00146 { 00147 if(pCollisionDetector) 00148 { 00149 delete pCollisionDetector; 00150 } 00151 delete planner; 00152 } 00153 00154 void Jacobian_TrajPlanner::SetStartConfig( const Configuration& config ) 00155 { 00156 planner->SetStartConfig(config); 00157 } 00158 00159 void Jacobian_TrajPlanner::SetCollisionDetector (CD_BasicStyle* collisionDetector) 00160 { 00161 if (pCollisionDetector != NULL) 00162 delete pCollisionDetector; 00163 00164 pCollisionDetector = new CD_Swiftpp( *(collisionDetector->GetUniverse()) ); 00165 planner->SetCollisionDetector(pCollisionDetector); 00166 } 00167 00168 void Jacobian_TrajPlanner::SetTrajectory(std::vector<Frame> &poses) 00169 { 00170 planner->SetTrajectory(poses); 00171 } 00172 00173 bool Jacobian_TrajPlanner::Plan () 00174 { 00175 double dObstacleTol = 0.01; 00176 double dHomogain = 0.5; 00177 double dPathTol = 0.5; 00178 int nObstacleNum = 2; 00179 00180 planner->SetObstacleTolerance(dObstacleTol); 00181 planner->SetNumObstaclePt(nObstacleNum); 00182 planner->SetHomogeneousGain(dHomogain); 00183 planner->SetOrientation(m_bUseOrientation); 00184 planner->SetPosition(true); 00185 planner->SetPathTolerence(dPathTol); 00186 00187 if (planner->Plan()) 00188 { 00189 path = *((PA_Points *)planner->GetPath()); 00190 return true; 00191 } 00192 else 00193 { 00194 return false; 00195 } 00196 } 00197 00198 00199 00200