planners/ik_mpep/PL_MPEP.h

Go to the documentation of this file.
00001 
00003 //
00004 //Contents: Class PL_MPEP
00005 // 
00006 //PL_MPEP: Planner for Motion Planning along given End-effector Path.
00007 //
00009 
00010 #ifndef _PL_MPEP_HEADER_
00011 #define _PL_MPEP_HEADER_
00012 
00013 #define DEFAULT_SAMPLE_RATE       10
00014 #define DEFAULT_TOLERANCE         0.1
00015 #define DEFAULT_RANDOM_RETRY      150
00016 #define DEFAULT_EXTEND_RETRY      50  //times the number of sample
00017 #define DEFAULT_EXPLORE_RETRY     20
00018 #define DEFAULT_ITERATION         10
00019 #define DEFAULT_SMGNODE_NUM       10
00020 
00021 //#define MAX_GREEDY_STEP_RETRY     50
00022 //#define MAX_RRT_RETRY             10
00023 
00024 #define ALG_GREEDY_PLANNER        0x00
00025 #define ALG_RRT_LIKE              0x01
00026 #define ALG_RRT_CONNECT_LIKE      0x02
00027 #define ALG_RRT_GREEDY_LIKE       0x03
00028 #define ALG_RRT_GREED_CONNECT     0x04
00029 #define ALG_IMP_GREEDY_PLANNER    0x05
00030 #define ALG_SMG_GREEDY_PLANNER    0x06
00031 #define ALG_SMG_RRT_PLANNER       0x07
00032 #define ALG_SMG_CONNECT_PLANNER   0x08
00033 
00034 #define ERROR_OK                          0x00
00035 #define ERROR_GET_RANDOM_CONF_FAILURE     0x01
00036 #define ERROR_GET_COLLISION_FREE_FAILURE  0x02
00037 #define ERROR_RRT_EXTEND_FAILURE          0x03
00038 #define ERROR_START_CONFIG_INVALID        0x04
00039 #define ERROR_GOAL_CONFIG_INVALID         0x05
00040 #define ERROR_SMGRAPH_FULL                0x06
00041 #define ERROR_PLANNING_TIMEOUT            0x0FE
00042 
00043 #define ERROR_UNKNOW_PLANNER              0x0FF
00044 
00045 #define TRAJ_LINE       0x00
00046 #define TRAJ_SEMICIRCLE 0x01
00047 #define TRAJ_CIRCLE     0x02
00048 
00049 #pragma warning( disable : 4250 )
00050 
00051 #include "Kinematics/Jacobian.h"
00052 #include "Robots/R_OpenChain.h"
00053 #include "geometry/Frame.h"
00054 #include "kinematics/Configuration.h"
00055 #include "CollisionDetectors/CD_BasicStyle.h"
00056 #include "kinematics/FrameManager.h"
00057 #include "Robots\RobotBase.h"
00058 #include "../inversekin/Redundant.h"
00059 //#include "SMGraph.h"
00060 #include "Planners/PL_Boolean_Output.h"
00061 #include "Planners/PL_OpenGL.h"
00062 
00063 #include "Planners/PL_GraphBase.h"
00064 
00065 #include <LEDA/dynamic_trees.h>
00066 //#include <LEDA/edge_map.h>
00067 //#include <LEDA/node_list.h>
00068 //#include <LEDA/list.h>
00069 
00070 #undef array
00071 #undef vector
00072 #undef map
00073 #undef string
00074 #undef set
00075 
00076 //using namespace std;
00077 
00078 class SMGraph;
00079 class CRedundant;
00080 
00081 typedef struct
00082 {
00083         int poses;
00084         SMGraph *graph;
00085         Configuration conf;
00086 }
00087 Pose_Node;
00088 
00089 class PL_MPEP: public PL_Boolean_Output, public PL_OpenGL
00090 {
00091 public:
00092         PL_MPEP();
00093         virtual ~PL_MPEP();
00094 
00095         //Inherited form ancestor
00096         virtual void SetCollisionDetector (CD_BasicStyle* collisionDetector);
00097         virtual bool DrawExplicit () const;
00098         virtual bool Plan ();
00099         
00100         Frame GetToolFrame( const Configuration& config ) const;
00101 
00102         //-----------The following function set the parameter from upper layer----------
00103         void SetTrajectory(std::vector<Frame> &traj);
00104         void SetPassiveNum(unsigned int num);         //The number of passive joints
00105         void SetAlgorithm(unsigned int alg);          //Which algorithm to use
00106         void SetTolerance(double dist);               //What is the tolerant diviation
00107         void SetUsingStartConfig(bool use);           //Whether use the specified start conf.
00108         void SetUsingGoalConfig(bool use);            //Whether use the specified goal configuration, when grow up goal tree
00109         void SetRandomRetry(unsigned int retry);      //The number of retry to get a random configuration
00110         void SetExtendNum(unsigned int num);          //In RRT-series planner, it's the number of extended lankmark
00111         void SetExploreNum(unsigned int num);         //In Greedy-series planner, it's the number of retry in Greedy planner
00112         void SetIterationNum(unsigned int num);       //The number of main iteration
00113         //How many time, they re-do from the very beginning
00114         void SetSMGNodeNum(unsigned int num);         //Set the node limitation in the self-motion graph
00115         void SetUsingJacobianExt(bool use);
00116 
00117 protected:
00118         //---------The following functions just try to get configuration with certain requirement-----
00119         //Get a configuration in a given (random) direction
00120         bool GetConfigurationByDirection(Configuration &conf, Configuration &base, Configuration &direct);
00121         //Get a configuration purely randomly
00122         bool GetRandomConfiguration(Configuration &conf);
00123         //Get a CLOSED configuration, which satisfies the pose of end-effector specified in frame.
00124         bool GetRandomConfiguration(Configuration &conf, Frame &frame);
00125         //Get a CLOSED configuration in a certain distance with bias.
00126         bool GetRandomConfiguration(Configuration &conf, Frame &frame, Configuration &bias);
00127 
00128         //----------The subroutines for planner------
00129         //Used in Greedy-series
00130         int Greedy_Step(int &begin, int end, vertex &base);
00131         //Used in RRT-series
00132         int RRT_Extend_Like(dynamic_trees &tr, std::vector<vertex> &vert, int &extPose, vertex &extended, int dir=1);
00133         int Step(dynamic_trees &tr, std::vector<vertex> &vert, int begin, int end, vertex &base, int dir=1);
00134 
00135         bool IsJointWithinLimits(Configuration& config);
00136         bool AdjustConfiguration(Configuration &config, int nPose);
00137         int Extend_Node_Self_Motion_Graph_Jacobian(vertex g_vertex, Configuration **nextConf);
00138         //The following functions are used in Planners enabling self-motion graph
00139         //Create and explore Self-motion Graph for a certain node in Random tree
00140         int Establish_Self_Motion_Graph(dynamic_trees &tr, vertex extended);
00141         //Get valid configuration for Self_Motion Graph.
00142         int Extend_Node_Self_Motion_Graph(vertex g_vertex, Configuration **);
00143         //Check the connectivity from a node to a the random tree growing from the other direction.
00144         int CheckConnectivity(dynamic_trees &tr, std::vector<vertex> &vert, vertex extendedVert, vertex &connectedVert, int dir);
00145 
00146         //----------Algorithms for planning-----------
00147         int Planner_Greedy();
00148         int Planner_RRT_Like();
00149         int Planner_RRT_Connect_Like();
00150         int Planner_RRT_Greedy_Like();
00151         int Planner_RRT_Greedy_Connect();
00152 
00153         //Improved Greedy Planner, with backtracking
00154         int Planner_IMP_Greedy();
00155         //Improved Greedy Planner, with Self-Motion-Graph
00156         int Planner_SMG_Greedy();
00157         //Improve RRT-Connect-Like Planner, with Self-Motion-Graph
00158         int Planner_SMG_RRT_Connect_Like();
00159         //Improve RRT-Greed-Like Planner, with Self-Motion-Graph;
00160         int Planner_SMG_RRT_Greedy_Like();
00161 
00162 protected:
00163         //------------- The following functions operate the Random tree created in RRT-series planner ---------
00164         void ClearTree();
00165         int InitializeTree();
00166         void RetrievePathFromTree();
00167         vertex ConnectNode(dynamic_trees &tr, std::vector<vertex> &vert, vertex &parent, Pose_Node &child);
00168         //Get the node in the tree which is closest to given configuration.
00169         vertex GetNearestNodeInTree(dynamic_trees &tr, std::vector<vertex> &vert, Configuration &conf);
00170         //Get furthest pose currently explored
00171         vertex GetClosestPoseVert(dynamic_trees &tr, std::vector<vertex> &vert);
00172 
00173         //------------- The following functions operate the Self-Motion Graph ------------
00174         void *GetNearestNodeInGraph(SMGraph *graph, Configuration *conf);
00175 
00176         //The following function computing the distance between two configurations
00177         double Distance(Configuration &conf1, Configuration &conf2);
00178         double DistanceInActiveJoints(Configuration &conf1, Configuration &conf2);
00179 
00180         //Just use for debug purpose when debugging the programe
00181         void Display_Error_Message(int result);
00182 
00183 protected:
00184         R_OpenChain *   m_pRobot;             // to get DH parameters
00185         int             m_nDof;
00186         int             m_nToolFrame;
00187         Frame           m_frEndEffector;
00188         CJacobian      *m_pJacobian;
00189 
00190 protected:
00191         //A class implementing closed-form inverse kinematics.
00192         CRedundant redundant;
00193 
00194         //Used when retrieving the path; Set after planning
00195         vertex goalPoseVertex;
00196         vertex goalPoseVertex2;
00197 
00198         //Used when retrieving the path; Set after planning
00199         //  The difference to the previous one is:
00200         //    this one is for the Random Tree growing up from GOAL;
00201         vertex startPoseVertex;
00202 
00203         //Random-tree data structure
00204         //  the vertex in the tree actually stored independent to the tree
00205         //  in LEDA, dynamic_tree just stores the relationship among the vertices.
00206         dynamic_trees tree;
00207         std::vector<vertex> vertices;
00208 
00209         //Random-tree growing from goal, using in RRT-CONNECT like
00210         //  when enabling S-M-G.
00211         dynamic_trees goal_tree;
00212         std::vector<vertex> goal_vertices;
00213 
00214         //Store the path, when we finish planning
00215         std::vector<vertex> itinerary;
00216 
00217         //The end effect poses
00218         //All sampling trajectory points are stored here.
00219         std::vector<Frame> poses;
00220 
00221         //private member corresponding to the upper layer parameter setting.
00222         unsigned int algorithm;
00223         unsigned int passiveNum;
00224         unsigned int randomRetry;
00225         unsigned int extendNum;
00226         unsigned int exploreNum;
00227         unsigned int iterationNum;
00228         unsigned int smgNodeNum;
00229         double distTolerance;
00230         bool usingStartConfig;
00231         bool usingGoalConfig;
00232         bool usingGoalTree;
00233         bool usingJacobianExt;
00234 
00235 private:
00236 };
00237 
00238 #endif

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