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 <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,          /*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 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   // TODO: add constructor that takes RobotState as param
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   // TODO: 'overloaded' requests depending on source and destination
00123   // bool GetShortestPathJointToCartesian(int startIndex, int endIndex, double &cost,
00124   // std::vector<descartes_core::TrajectoryPt> &path);
00125   // bool GetShortestPathCartesianToCartesian(int startIndex, int endIndex, double &cost,
00126   // std::vector<descartes_core::TrajectoryPt> &path);
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   // NOTE: both Cartesian Points and Joint Points/solutions extend a base descartes_core::TrajectoryPt type
00169   //       and include an accessor to both formats
00170 
00171   // maintains the original (Cartesian) points list along with link information and associated joint trajectories per
00172   // point
00173   CartesianMap *cartesian_point_link_;
00174 
00175   // maintains a map of joint solutions with it's corresponding graph vertex_descriptor
00176   //   one or more of these will exist for each element in trajectory_point_map
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 } /* namespace descartes_planner */
00205 
00206 #endif /* PLANNING_GRAPH_H_ */


descartes_planner
Author(s): Jorge Nicho
autogenerated on Thu Jun 6 2019 21:36:12