Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef PLANNING_GRAPH_H_
00026 #define PLANNING_GRAPH_H_
00027
00028 #include <boost/graph/adjacency_list.hpp>
00029 #include <boost/function.hpp>
00030 #include "descartes_core/trajectory_pt.h"
00031 #include "descartes_trajectory/cart_trajectory_pt.h"
00032 #include "descartes_trajectory/joint_trajectory_pt.h"
00033
00034 #include <map>
00035 #include <vector>
00036
00037 namespace descartes_planner
00038 {
00039 struct JointVertex
00040 {
00041 descartes_core::TrajectoryPt::ID id;
00042 };
00043 struct JointEdge
00044 {
00045 descartes_core::TrajectoryPt::ID joint_start;
00046 descartes_core::TrajectoryPt::ID joint_end;
00047 double transition_cost;
00048 };
00049
00050 struct CartesianPointRelationship
00051 {
00052 descartes_core::TrajectoryPt::ID id;
00053 descartes_core::TrajectoryPt::ID id_previous;
00054 descartes_core::TrajectoryPt::ID id_next;
00055 };
00056
00057 typedef boost::adjacency_list<boost::listS,
00058 boost::vecS,
00059 boost::bidirectionalS,
00060 JointVertex,
00061 JointEdge
00062 > JointGraph;
00063
00064 typedef boost::graph_traits<JointGraph>::vertex_iterator VertexIterator;
00065 typedef boost::graph_traits<JointGraph>::edge_iterator EdgeIterator;
00066 typedef boost::graph_traits<JointGraph>::out_edge_iterator OutEdgeIterator;
00067 typedef boost::graph_traits<JointGraph>::in_edge_iterator InEdgeIterator;
00068
00069 typedef boost::function<double(const std::vector<double> &, const std::vector<double> &)> CostFunction;
00070
00071 struct CartesianPointInformation
00072 {
00073 CartesianPointRelationship links_;
00074 descartes_core::TrajectoryPtPtr source_trajectory_;
00075 std::vector<descartes_core::TrajectoryPt::ID> joints_;
00076 };
00077
00078 typedef std::map<descartes_core::TrajectoryPt::ID, CartesianPointInformation> CartesianMap;
00079 typedef std::map<descartes_core::TrajectoryPt::ID, descartes_trajectory::JointTrajectoryPt> JointMap;
00080 typedef std::map<descartes_core::TrajectoryPt::ID, JointGraph::vertex_descriptor> VertexMap;
00081
00082 class PlanningGraph
00083 {
00084 public:
00085
00086 PlanningGraph(descartes_core::RobotModelConstPtr model);
00087
00088 PlanningGraph(descartes_core::RobotModelConstPtr model, CostFunction cost_function_callback);
00089
00090 virtual ~PlanningGraph();
00091
00093 void clear();
00094
00099 bool insertGraph(const std::vector<descartes_core::TrajectoryPtPtr> *points);
00100
00105 bool addTrajectory(descartes_core::TrajectoryPtPtr point, descartes_core::TrajectoryPt::ID previous_id,
00106 descartes_core::TrajectoryPt::ID next_id);
00107
00108 bool modifyTrajectory(descartes_core::TrajectoryPtPtr point);
00109
00110 bool removeTrajectory(descartes_core::TrajectoryPtPtr point);
00111
00112 bool getCartesianTrajectory(std::vector<descartes_core::TrajectoryPtPtr> &traj);
00113
00121 bool getShortestPath(double &cost, std::list<descartes_trajectory::JointTrajectoryPt> &path);
00122
00123
00124
00125
00126
00127
00131 void printGraph();
00132 void printMaps();
00133
00134 descartes_core::RobotModelConstPtr getRobotModel();
00135
00136 CartesianMap getCartesianMap() const;
00137
00138 const JointMap &getJointMap() const;
00139
00140 const JointGraph &getGraph() const;
00141
00143 bool findStartVertices(std::vector<JointGraph::vertex_descriptor> &start_points) const;
00144
00146 bool findEndVertices(std::vector<JointGraph::vertex_descriptor> &end_points) const;
00147
00148 protected:
00149 descartes_core::RobotModelConstPtr robot_model_;
00150
00151 CostFunction custom_cost_function_;
00152
00153 JointGraph dg_;
00154
00155 int recalculateJointSolutionsVertexMap(
00156 std::map<descartes_core::TrajectoryPt::ID, JointGraph::vertex_descriptor> &joint_vertex_map) const;
00157
00162 typedef std::pair<bool, double> EdgeWeightResult;
00163
00165 EdgeWeightResult edgeWeight(const descartes_trajectory::JointTrajectoryPt &start,
00166 const descartes_trajectory::JointTrajectoryPt &end) const;
00167
00168
00169
00170
00171
00172
00173 CartesianMap *cartesian_point_link_;
00174
00175
00176
00177 JointMap joint_solutions_map_;
00178
00180 bool calculateJointSolutions(const std::vector<descartes_core::TrajectoryPtPtr> &points,
00181 std::vector<std::vector<descartes_trajectory::JointTrajectoryPt>> &poses);
00182
00184 bool populateGraphVertices(const std::vector<descartes_core::TrajectoryPtPtr> &points,
00185 std::vector<std::vector<descartes_trajectory::JointTrajectoryPt>> &poses);
00186
00188 bool calculateEdgeWeights(const std::vector<descartes_core::TrajectoryPt::ID> &start_joints,
00189 const std::vector<descartes_core::TrajectoryPt::ID> &end_joints,
00190 std::vector<JointEdge> &edge_results);
00191
00192 bool calculateEdgeWeights(const std::vector<descartes_trajectory::JointTrajectoryPt> &start_joints,
00193 const std::vector<descartes_trajectory::JointTrajectoryPt> &end_joints,
00194 std::vector<JointEdge> &edge_results) const;
00195
00197 bool calculateAllEdgeWeights(const std::vector<std::vector<descartes_trajectory::JointTrajectoryPt>> &poses,
00198 std::vector<JointEdge> &edges);
00199
00201 bool populateGraphEdges(const std::vector<JointEdge> &edges);
00202 };
00203
00204 }
00205
00206 #endif