00001
00002
00003
00004
00006
00007 #ifndef _PL_ATACE_HEADER_
00008 #define _PL_ATACE_HEADER_
00009
00010
00011 #define ERR_FAIL 0xff
00012 #define ERR_SUCCESS 0x00
00013 #define ERR_TIMEOUT 0x10
00014 #define ERR_ILLPARAMETER 0x20
00015
00016
00017 #define FLAG_NEW 0x01 //Normal node
00018 #define FLAG_OBSOLETE 0x02 //Node which has been deleted
00019
00020
00021 #define TYPE_START_CONF 0x01
00022 #define TYPE_START_POSE 0x02
00023 #define TYPE_GOAL_CONF 0x04
00024 #define TYPE_GOAL_POSE 0x08
00025
00026
00027 #define FLAG_C_METRICS 0x10 //C-space metrics
00028 #define FLAG_P_METRICS 0x01 //Phy-space metrics
00029 #define FLAG_B_METRICS (FLAG_C_METRICS|FLAG_P_METRICS) //Combined
00030
00031
00032 #define LOCAL_JACOBIAN 0 //Deterministic Jacobian-based local planner
00033 #define LOCAL_RRT 1 //Probabilistic local planner
00034
00035 #pragma warning( disable : 4250 )
00036
00037 #include "kinematics/Configuration.h"
00038 #include "geometry/Frame.h"
00039 #include "Planners/PL_Boolean_Output.h"
00040 #include "Planners/PL_OpenGL.h"
00041
00042 #include "planners/inversekin/IK_InvKinBase.h"
00043 #include "robots/R_OpenChain.h"
00044 #include <LEDA/dynamic_trees.h>
00045
00046 #include "kinematics/Pose.h"
00047
00048 #undef array
00049 #undef vector
00050 #undef map
00051 #undef string
00052 #undef set
00053
00054 class TrajPlanner;
00055
00056 typedef PA_Points Path;
00057 typedef vertex Vertex;
00058 typedef std::vector<Frame> EEPath;
00059
00060
00061
00062 typedef struct
00063 {
00064
00065 Pose pose;
00066 Configuration conf;
00067 }
00068 Node;
00069
00070
00071 typedef struct
00072 {
00073 int flag;
00074 bool collisionChecked;
00075 Pose pose;
00076 Configuration conf;
00077 Pose dirPose;
00078 Configuration dirConf;
00079 Path edge;
00080 EEPath eeEdge;
00081 }
00082 VertexInfo;
00083
00084
00085 typedef bool (*ProcIsStaified)(Frame &pose);
00086 typedef void (*ProcAdjustToSatisfy)(Frame &pose);
00087 typedef void (*ProcGetVelocity)(Frame &pose, VectorN &vel);
00088 typedef void (*ProcGetDirectedVelocity)(Frame &pose, Frame &dir, VectorN &vel, Frame &projection, bool greedy, double timeInterval);
00089
00090 class PL_ATACE: public IK_InvKinBase
00091 {
00092 public:
00093 PL_ATACE();
00094 virtual ~PL_ATACE();
00095
00096
00097 virtual void SetCollisionDetector (CD_BasicStyle* collisionDetector);
00098 virtual bool DrawExplicit () const;
00099 virtual bool Plan ();
00100 Frame GetToolFrame( const Configuration& config ) const;
00101
00102
00103 virtual void SetStartConfig( const Configuration& config );
00104 virtual void SetGoalConfig ( const Configuration& config );
00105 void SetStartPose(const Pose &start);
00106 void SetGoalPose(const Pose &goal);
00107 void SetProblemType(unsigned int type);
00108 bool IsReady();
00109
00110
00111
00112 void SetTimeInterval(double interval){m_timeInterval = interval;}
00113 double GetTimeInterval(){return m_timeInterval;}
00114
00115
00116 void SetStepSize(double step){m_stepSize = step;}
00117 double GetStepSize(){return m_stepSize;}
00118
00119
00120 void SetMetrics(int metrics){m_metrics = metrics;}
00121 int GetMetrics(){return m_metrics;}
00122
00123
00124 void SetDrawSpace(bool drawCSpace){m_drawCSpace = drawCSpace;}
00125 bool GetDrawSpace(){return m_drawCSpace;}
00126
00127
00128 void SetOrientation(bool considered, bool always){m_useOrientation = considered; m_useOrientationAlways = always;}
00129 bool GetOrientation(){return m_useOrientation;}
00130
00131
00132 void SetLazy(bool use){m_useLazy = use;}
00133 bool GetLazy(){return m_useLazy;}
00134
00135
00136 void SetLocalPlanner(int localPlanner);
00137 int GetLocalPlanner(){return m_nLocalPlanner;}
00138
00139 protected:
00140 R_OpenChain *m_robot;
00141 int m_toolFrame;
00142 TrajPlanner *m_localPlanner;
00143 int m_nLocalPlanner;
00144 int m_metrics;
00145 bool m_useLazy;
00146 bool m_drawCSpace;
00147 bool m_useOrientation;
00148 bool m_useOrientationAlways;
00149 double m_stepSize;
00150 double m_timeInterval;
00151
00152 Pose m_startPose;
00153 Pose m_goalPose;
00154 bool m_useGoalPose;
00155 bool m_useGoalConf;
00156 bool m_useStartPose;
00157 bool m_useStartConf;
00158 bool m_isGoalPoseSet;
00159 bool m_isGoalConfSet;
00160 bool m_isStartPoseSet;
00161 bool m_isStartConfSet;
00162
00163 protected:
00164 Vertex m_goalVert;
00165 int ExtendWithConstraint(Node &fromNode, Pose &dirPose, Node &toNode, Path &path, EEPath &endeffpath, bool greedy);
00166 int ExtendToGoal(Vertex &fromVert, Pose &dirPose, Vertex &endVert);
00167 int LazyTrackEEPath();
00168 void RetrievePath(Vertex &goalVert);
00169 void GenerateRandomNode(Node &randomNode);
00170 Configuration GenerateRandomConfig();
00171
00172 protected:
00173 Universe *m_trajUniverse;
00174 CD_BasicStyle *m_trajCollisionDetector;
00175 void CreateTrajectoryCD(CD_BasicStyle* collisionDetector);
00176 void DeleteTrajectoryCD();
00177 bool IsInterfering (const Pose& pose1, const Pose& pose2);
00178
00179 private:
00180 VectorN distWeight;
00181 double Distance(const Pose &pos1, const Pose &pos2);
00182 double Distance(const Configuration &conf1, const Configuration &conf2);
00183
00184 private:
00185 Vertex m_rootVert;
00186 dynamic_trees m_trajTree;
00187 std::vector<vertex> m_vertices;
00188
00189 bool CreateTree(Node &rootNode);
00190 void ClearTree();
00191 void TrimTreeFrom(Vertex failVert);
00192
00193 Vertex AddNodeInTree(Vertex parentVertex, Node &childNode, Pose &dirPose, Path &localPath, EEPath &endeffPath);
00194
00195 Vertex FindClosestInTree(Pose &pose);
00196 Vertex FindClosestInTree(Configuration &conf);
00197 Vertex FindClosestInTree(Node node);
00198
00199 Configuration& GetConfigurationFromTree(Vertex vert);
00200 Pose& GetPoseFromTree(Vertex vert);
00201 Path& GetPathFromTree(Vertex vert);
00202
00203 public:
00204
00205 void SetPoseChecker(ProcIsStaified proc);
00206 void SetPoseAdjuster(ProcAdjustToSatisfy proc);
00207 void SetVelocityChecker(ProcGetVelocity proc);
00208 void SetDirectedVelocityChecker(ProcGetDirectedVelocity proc);
00209 private:
00210
00211 ProcIsStaified IsPoseSatified;
00212 ProcAdjustToSatisfy AdjustPoseToSatisfy;
00213 ProcGetVelocity GetVelocity;
00214 ProcGetDirectedVelocity GetDirectedVelocity;
00215
00216 void GetNextPose(Pose &prePose, Pose &dirPose, Pose &postPose, bool greedy);
00217
00218 private:
00219 inline void CopyPath(Path &target, Path &source);
00220 inline void CopyEEPath(EEPath &target, EEPath &source);
00221 void AppendPath(Path &collect, Path &local);
00222 void AppendPath(Path &collect, PA_Points *local);
00223 void InsertPath(Path &target, Path &source);
00224 void InterpolatePath(Path &target, Configuration &start, Configuration &end);
00225 };
00226
00227 #endif