homotopy_class_planner.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2016,
00006  *  TU Dortmund - Institute of Control Theory and Systems Engineering.
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the institute nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * Author: Christoph Rösmann
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   // Workaround for a bug in boost graph library (concerning directed graphs), boost version 1.48:
00052   // boost::add_vertex requires a move constructor/assignment operator in one of the underlying boost objects if C++11 is activated,
00053   // but they are missing. The compiler fails due to an implicit deletion. We just deactivate C++11 default functions for now.
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; // position of vertices in the map
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; // Found! Homotopy class already exists, therefore nothing added  
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   // external objects (store weak pointers)
00559   const TebConfig* cfg_; 
00560   ObstContainer* obstacles_; 
00561   const ViaPointContainer* via_points_; 
00562   
00563   // internal objects (memory management owned)
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                                                                             //   The second parameter denotes whether to exclude the class from detour deletion or not (true: force keeping).
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 } // namespace teb_local_planner
00597 
00598 // include template implementations / definitions
00599 #include <teb_local_planner/homotopy_class_planner.hpp>
00600 
00601 #endif /* HOMOTOPY_CLASS_PLANNER_H_ */


teb_local_planner
Author(s): Christoph Rösmann
autogenerated on Sat Jun 8 2019 20:21:34