planning_graph.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Southwest Research Institute
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 /*
00019  * Planning_graph.h
00020  *
00021  *  Created on: Jun 5, 2014
00022  *      Author: Dan Solomon
00023  */
00024 
00025 #ifndef PLANNING_GRAPH_H_
00026 #define PLANNING_GRAPH_H_
00027 
00028 #include <boost/graph/adjacency_list.hpp>
00029 #include "descartes_core/trajectory_pt.h"
00030 #include "descartes_trajectory/cart_trajectory_pt.h"
00031 #include "descartes_trajectory/joint_trajectory_pt.h"
00032 
00033 #include <map>
00034 #include <vector>
00035 
00036 namespace descartes_planner
00037 {
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, /*edge container*/
00058   boost::vecS, /*vertex_container*/
00059   boost::bidirectionalS, /*allows in_edge and out_edge*/
00060   JointVertex, /*vertex structure*/
00061   JointEdge /*edge structure*/
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 struct CartesianPointInformation
00070 {
00071   CartesianPointRelationship links_;
00072   descartes_core::TrajectoryPtPtr source_trajectory_;
00073   std::list<descartes_core::TrajectoryPt::ID> joints_;
00074 };
00075 
00076 typedef std::map<descartes_core::TrajectoryPt::ID, CartesianPointInformation> CartesianMap;
00077 
00078 class PlanningGraph
00079 {
00080 public:
00081   // TODO: add constructor that takes RobotState as param
00082   PlanningGraph(descartes_core::RobotModelConstPtr model);
00083 
00084   virtual ~PlanningGraph();
00085 
00090   bool insertGraph(const std::vector<descartes_core::TrajectoryPtPtr> *points);
00091 
00096   bool addTrajectory(descartes_core::TrajectoryPtPtr point, descartes_core::TrajectoryPt::ID previous_id, descartes_core::TrajectoryPt::ID next_id);
00097 
00098   bool modifyTrajectory(descartes_core::TrajectoryPtPtr point);
00099 
00100   bool removeTrajectory(descartes_core::TrajectoryPtPtr point);
00101 
00102   CartesianMap getCartesianMap();
00103 
00104   bool getCartesianTrajectory(std::vector<descartes_core::TrajectoryPtPtr>& traj);
00105 
00113   bool getShortestPath(double &cost, std::list<descartes_trajectory::JointTrajectoryPt> &path);
00114   // TODO: 'overloaded' requests depending on source and destination
00115   //bool GetShortestPathJointToCartesian(int startIndex, int endIndex, double &cost, std::vector<descartes_core::TrajectoryPt> &path);
00116   //bool GetShortestPathCartesianToCartesian(int startIndex, int endIndex, double &cost, std::vector<descartes_core::TrajectoryPt> &path);
00117 
00121   void printGraph();
00122   void printMaps();
00123 
00124   descartes_core::RobotModelConstPtr getRobotModel();
00125 
00126 protected:
00127   descartes_core::RobotModelConstPtr robot_model_;
00128 
00129   JointGraph dg_;
00130 
00131   int recalculateJointSolutionsVertexMap(std::map<descartes_core::TrajectoryPt::ID, JointGraph::vertex_descriptor> &joint_vertex_map);
00132 
00137   typedef std::pair<bool, double> LinearWeightResult;
00138 
00140   LinearWeightResult linearWeight(const descartes_trajectory::JointTrajectoryPt& start,
00141                                   const descartes_trajectory::JointTrajectoryPt& end) const;
00142 
00143   // NOTE: both Cartesian Points and Joint Points/solutions extend a base descartes_core::TrajectoryPt type
00144   //       and include an accessor to both formats
00145 
00146   // maintains the original (Cartesian) points list along with link information and associated joint trajectories per point
00147   std::map<descartes_core::TrajectoryPt::ID, CartesianPointInformation> *cartesian_point_link_;
00148 
00149   // maintains a map of joint solutions with it's corresponding graph vertex_descriptor
00150   //   one or more of these will exist for each element in trajectory_point_map
00151   std::map<descartes_core::TrajectoryPt::ID, descartes_trajectory::JointTrajectoryPt> joint_solutions_map_;
00152 
00154   bool findStartVertices(std::list<JointGraph::vertex_descriptor> &start_points);
00155 
00157   bool findEndVertices(std::list<JointGraph::vertex_descriptor> &end_points);
00158 
00160   bool calculateJointSolutions();
00161 
00163   bool populateGraphVertices();
00164 
00166   bool calculateEdgeWeights(const std::list<descartes_core::TrajectoryPt::ID> &start_joints,
00167                             const std::list<descartes_core::TrajectoryPt::ID> &end_joints, std::list<JointEdge> &edge_results);
00168 
00170   bool calculateAllEdgeWeights(std::list<JointEdge> &edges);
00171 
00173   bool populateGraphEdges(const std::list<JointEdge> &edges);
00174 };
00175 
00176 } /* namespace descartes_planner */
00177 
00178 #endif /* PLANNING_GRAPH_H_ */


descartes_planner
Author(s): Jorge Nicho
autogenerated on Wed Aug 26 2015 11:21:35