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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef HOMOTOPY_CLASS_PLANNER_H_
00040 #define HOMOTOPY_CLASS_PLANNER_H_
00041
00042 #include <math.h>
00043 #include <algorithm>
00044 #include <functional>
00045 #include <vector>
00046 #include <iterator>
00047
00048 #ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
00049 #include <boost/graph/adjacency_list.hpp>
00050 #else
00051
00052
00053
00054 #define BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
00055 #include <boost/graph/adjacency_list.hpp>
00056 #undef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
00057 #endif
00058
00059 #include <boost/graph/graph_traits.hpp>
00060 #include <boost/graph/depth_first_search.hpp>
00061 #include <boost/shared_ptr.hpp>
00062 #include <boost/random.hpp>
00063 #include <boost/utility.hpp>
00064
00065
00066 #include <visualization_msgs/Marker.h>
00067 #include <geometry_msgs/Point.h>
00068 #include <std_msgs/ColorRGBA.h>
00069
00070 #include <ros/console.h>
00071 #include <ros/ros.h>
00072
00073 #include <teb_local_planner/planner_interface.h>
00074 #include <teb_local_planner/teb_config.h>
00075 #include <teb_local_planner/obstacles.h>
00076 #include <teb_local_planner/optimal_planner.h>
00077 #include <teb_local_planner/visualization.h>
00078 #include <teb_local_planner/robot_footprint_model.h>
00079 #include <teb_local_planner/equivalence_relations.h>
00080
00081
00082 namespace teb_local_planner
00083 {
00084
00085
00087 struct HcGraphVertex
00088 {
00089 public:
00090 Eigen::Vector2d pos;
00091 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00092 };
00093
00095 typedef boost::adjacency_list < boost::listS, boost::vecS, boost::directedS, HcGraphVertex, boost::no_property > HcGraph;
00097 typedef boost::graph_traits<HcGraph>::vertex_descriptor HcGraphVertexType;
00099 typedef boost::graph_traits<HcGraph>::edge_descriptor HcGraphEdgeType;
00101 typedef boost::graph_traits<HcGraph>::vertex_iterator HcGraphVertexIterator;
00103 typedef boost::graph_traits<HcGraph>::edge_iterator HcGraphEdgeIterator;
00105 typedef boost::graph_traits<HcGraph>::adjacency_iterator HcGraphAdjecencyIterator;
00106
00131 class HomotopyClassPlanner : public PlannerInterface
00132 {
00133 public:
00134
00138 HomotopyClassPlanner();
00139
00148 HomotopyClassPlanner(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
00149 TebVisualizationPtr visualization = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
00150
00154 virtual ~HomotopyClassPlanner();
00155
00164 void initialize(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
00165 TebVisualizationPtr visualization = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
00166
00167
00168
00171
00184 virtual bool plan(const std::vector<geometry_msgs::PoseStamped>& initial_plan, const geometry_msgs::Twist* start_vel = NULL, bool free_goal_vel=false);
00185
00197 virtual bool plan(const tf::Pose& start, const tf::Pose& goal, const geometry_msgs::Twist* start_vel = NULL, bool free_goal_vel=false);
00198
00210 virtual bool plan(const PoseSE2& start, const PoseSE2& goal, const geometry_msgs::Twist* start_vel = NULL, bool free_goal_vel=false);
00211
00220 virtual bool getVelocityCommand(double& vx, double& vy, double& omega) const;
00221
00230 TebOptimalPlannerPtr bestTeb() const {return tebs_.empty() ? TebOptimalPlannerPtr() : tebs_.size()==1 ? tebs_.front() : best_teb_;}
00231
00245 virtual bool isTrajectoryFeasible(base_local_planner::CostmapModel* costmap_model, const std::vector<geometry_msgs::Point>& footprint_spec,
00246 double inscribed_radius = 0.0, double circumscribed_radius=0.0, int look_ahead_idx=-1);
00247
00249
00252
00258 void setVisualization(TebVisualizationPtr visualization);
00259
00266 virtual void visualize();
00267
00269
00272
00273
00289 void exploreEquivalenceClassesAndInitTebs(const PoseSE2& start, const PoseSE2& goal, double dist_to_obst, const geometry_msgs::Twist* start_vel);
00290
00291
00297 void deleteTebDetours(double threshold=0.0);
00298
00299
00314 template<typename BidirIter, typename Fun>
00315 TebOptimalPlannerPtr addAndInitNewTeb(BidirIter path_start, BidirIter path_end, Fun fun_position, double start_orientation, double goal_orientation, const geometry_msgs::Twist* start_velocity);
00316
00324 TebOptimalPlannerPtr addAndInitNewTeb(const PoseSE2& start, const PoseSE2& goal, const geometry_msgs::Twist* start_velocity);
00325
00332 TebOptimalPlannerPtr addAndInitNewTeb(const std::vector<geometry_msgs::PoseStamped>& initial_plan, const geometry_msgs::Twist* start_velocity);
00333
00340 void updateAllTEBs(const PoseSE2* start, const PoseSE2* goal, const geometry_msgs::Twist* start_velocity);
00341
00342
00350 void optimizeAllTEBs(int iter_innerloop, int iter_outerloop);
00351
00356 TebOptimalPlannerPtr getInitialPlanTEB();
00357
00365 TebOptimalPlannerPtr selectBestTeb();
00366
00368
00374 void clearPlanner() {graph_.clear(); equivalence_classes_.clear(); tebs_.clear(); initial_plan_ = NULL;}
00375
00385 virtual bool isHorizonReductionAppropriate(const std::vector<geometry_msgs::PoseStamped>& initial_plan) const;
00386
00400 template<typename BidirIter, typename Fun>
00401 EquivalenceClassPtr calculateEquivalenceClass(BidirIter path_start, BidirIter path_end, Fun fun_cplx_point, const ObstContainer* obstacles = NULL);
00402
00407 const TebOptPlannerContainer& getTrajectoryContainer() const {return tebs_;};
00408
00417 virtual void computeCurrentCost(std::vector<double>& cost, double obst_cost_scale=1.0, double viapoint_cost_scale=1.0, bool alternative_time_cost=false);
00418
00425 inline static bool isHSignatureSimilar(const std::complex<long double>& h1, const std::complex<long double>& h2, double threshold)
00426 {
00427 double diff_real = std::abs(h2.real() - h1.real());
00428 double diff_imag = std::abs(h2.imag() - h1.imag());
00429 if (diff_real<=threshold && diff_imag<=threshold)
00430 return true;
00431 return false;
00432 }
00433
00434
00439 const TebConfig* config() const {return cfg_;}
00440
00445 const ObstContainer* obstacles() const {return obstacles_;}
00446
00450 bool isInitialized() const {return initialized_;}
00451
00455 void clearGraph() {graph_.clear();}
00456
00462 int bestTebIdx() const;
00463
00464
00465 protected:
00466
00469
00485 void createGraph(const PoseSE2& start, const PoseSE2& goal, double dist_to_obst, double obstacle_heading_threshold, const geometry_msgs::Twist* start_velocity);
00486
00503 void createProbRoadmapGraph(const PoseSE2& start, const PoseSE2& goal, double dist_to_obst, int no_samples, double obstacle_heading_threshold, const geometry_msgs::Twist* start_velocity);
00504
00510 bool hasEquivalenceClass(const EquivalenceClassPtr& eq_class) const;
00511
00518 bool addEquivalenceClassIfNew(const EquivalenceClassPtr& eq_class, bool lock=false);
00519
00529 void renewAndAnalyzeOldTebs(bool delete_detours);
00530
00539 void updateReferenceTrajectoryViaPoints(bool all_trajectories);
00540
00553 void DepthFirst(HcGraph& g, std::vector<HcGraphVertexType>& visited, const HcGraphVertexType& goal, double start_orientation, double goal_orientation, const geometry_msgs::Twist* start_velocity);
00554
00556
00557
00558
00559 const TebConfig* cfg_;
00560 ObstContainer* obstacles_;
00561 const ViaPointContainer* via_points_;
00562
00563
00564 TebVisualizationPtr visualization_;
00565 TebOptimalPlannerPtr best_teb_;
00566 RobotFootprintModelPtr robot_model_;
00567
00568 const std::vector<geometry_msgs::PoseStamped>* initial_plan_;
00569 EquivalenceClassPtr initial_plan_eq_class_;
00570 TebOptimalPlannerPtr initial_plan_teb_;
00571
00572 TebOptPlannerContainer tebs_;
00573
00574 HcGraph graph_;
00575
00576 using EquivalenceClassContainer = std::vector< std::pair<EquivalenceClassPtr, bool> >;
00577 EquivalenceClassContainer equivalence_classes_;
00578
00579
00580 boost::random::mt19937 rnd_generator_;
00581
00582 bool initialized_;
00583
00584
00585
00586 public:
00587 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00588
00589
00590 };
00591
00593 typedef boost::shared_ptr<HomotopyClassPlanner> HomotopyClassPlannerPtr;
00594
00595
00596 }
00597
00598
00599 #include <teb_local_planner/homotopy_class_planner.hpp>
00600
00601 #endif