optimal_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 OPTIMAL_PLANNER_H_
00040 #define OPTIMAL_PLANNER_H_
00041 
00042 #include <math.h>
00043 
00044 
00045 // teb stuff
00046 #include <teb_local_planner/teb_config.h>
00047 #include <teb_local_planner/misc.h>
00048 #include <teb_local_planner/timed_elastic_band.h>
00049 #include <teb_local_planner/planner_interface.h>
00050 #include <teb_local_planner/visualization.h>
00051 #include <teb_local_planner/robot_footprint_model.h>
00052 
00053 // g2o lib stuff
00054 #include "g2o/core/sparse_optimizer.h"
00055 #include "g2o/core/block_solver.h"
00056 #include "g2o/core/factory.h"
00057 #include "g2o/core/optimization_algorithm_gauss_newton.h"
00058 #include "g2o/core/optimization_algorithm_levenberg.h"
00059 #include "g2o/solvers/csparse/linear_solver_csparse.h"
00060 #include "g2o/solvers/cholmod/linear_solver_cholmod.h"
00061 
00062 // g2o custom edges and vertices for the TEB planner
00063 #include <teb_local_planner/g2o_types/edge_velocity.h>
00064 #include <teb_local_planner/g2o_types/edge_acceleration.h>
00065 #include <teb_local_planner/g2o_types/edge_kinematics.h>
00066 #include <teb_local_planner/g2o_types/edge_time_optimal.h>
00067 #include <teb_local_planner/g2o_types/edge_obstacle.h>
00068 #include <teb_local_planner/g2o_types/edge_dynamic_obstacle.h>
00069 #include <teb_local_planner/g2o_types/edge_via_point.h>
00070 
00071 // messages
00072 #include <nav_msgs/Path.h>
00073 #include <geometry_msgs/PoseStamped.h>
00074 #include <tf/transform_datatypes.h>
00075 #include <teb_local_planner/TrajectoryMsg.h>
00076 
00077 #include <nav_msgs/Odometry.h>
00078 #include <limits.h>
00079 
00080 namespace teb_local_planner
00081 {
00082 
00084 typedef g2o::BlockSolver< g2o::BlockSolverTraits<-1, -1> >  TEBBlockSolver;
00085 
00087 typedef g2o::LinearSolverCSparse<TEBBlockSolver::PoseMatrixType> TEBLinearSolver;
00088 //typedef g2o::LinearSolverCholmod<TEBBlockSolver::PoseMatrixType> TEBLinearSolver;
00089 
00091 typedef std::vector< Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d> > ViaPointContainer;
00092 
00093 
00105 class TebOptimalPlanner : public PlannerInterface
00106 {
00107 public:
00108     
00112   TebOptimalPlanner();
00113   
00122   TebOptimalPlanner(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
00123                     TebVisualizationPtr visual = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
00124   
00128   virtual ~TebOptimalPlanner();
00129   
00138   void initialize(const TebConfig& cfg, ObstContainer* obstacles = NULL, RobotFootprintModelPtr robot_model = boost::make_shared<PointRobotFootprint>(),
00139                   TebVisualizationPtr visual = TebVisualizationPtr(), const ViaPointContainer* via_points = NULL);
00140   
00141   
00142 
00145   
00163   virtual bool plan(const std::vector<geometry_msgs::PoseStamped>& initial_plan, const geometry_msgs::Twist* start_vel = NULL, bool free_goal_vel=false);
00164   
00181   virtual bool plan(const tf::Pose& start, const tf::Pose& goal, const geometry_msgs::Twist* start_vel = NULL, bool free_goal_vel=false);
00182   
00199   virtual bool plan(const PoseSE2& start, const PoseSE2& goal, const Eigen::Vector2d& start_vel, bool free_goal_vel=false);
00200   
00201   
00209   virtual bool getVelocityCommand(double& v, double& omega) const;
00210   
00211   
00238   bool optimizeTEB(unsigned int iterations_innerloop, unsigned int iterations_outerloop, bool compute_cost_afterwards = false,
00239                    double obst_cost_scale=1.0, double viapoint_cost_scale=1.0, bool alternative_time_cost=false);
00240   
00242   
00243   
00246   
00252   void setVelocityStart(const Eigen::Ref<const Eigen::Vector2d>& vel_start);
00253   
00259   void setVelocityStart(const geometry_msgs::Twist& vel_start);
00260   
00266   void setVelocityGoal(const Eigen::Ref<const Eigen::Vector2d>& vel_goal);
00267   
00272   void setVelocityGoalFree() {vel_goal_.first = false;}
00273   
00275   
00276   
00279   
00280   
00286   void setObstVector(ObstContainer* obst_vector) {obstacles_ = obst_vector;}
00287   
00292   const ObstContainer& getObstVector() const {return *obstacles_;}
00293 
00295   
00298   
00299   
00305   void setViaPoints(const ViaPointContainer* via_points) {via_points_ = via_points;}
00306   
00311   const ViaPointContainer& getViaPoints() const {return *via_points_;}
00312 
00314           
00315   
00318   
00324   void setVisualization(TebVisualizationPtr visualization);
00325   
00332   virtual void visualize();
00333   
00335   
00336   
00339         
00343   virtual void clearPlanner() 
00344   {
00345     clearGraph();
00346     teb_.clearTimedElasticBand();
00347   }
00348   
00355   static void registerG2OTypes();
00356   
00362   TimedElasticBand& teb() {return teb_;};
00363   
00368   const TimedElasticBand& teb() const {return teb_;};
00369   
00375   boost::shared_ptr<g2o::SparseOptimizer> optimizer() {return optimizer_;};
00376   
00381   boost::shared_ptr<const g2o::SparseOptimizer> optimizer() const {return optimizer_;};
00382   
00388   bool isOptimized() const {return optimized_;};
00389         
00411   void computeCurrentCost(double obst_cost_scale=1.0, double viapoint_cost_scale=1.0, bool alternative_time_cost=false);
00412   
00421   virtual void computeCurrentCost(std::vector<double>& cost, double obst_cost_scale=1.0, double viapoint_cost_scale=1.0, bool alternative_time_cost=false)
00422   {
00423     computeCurrentCost(obst_cost_scale, viapoint_cost_scale, alternative_time_cost);
00424     cost.push_back( getCurrentCost() );
00425   }
00426   
00434   double getCurrentCost() const {return cost_;}
00435   
00436   
00448   inline void extractVelocity(const PoseSE2& pose1, const PoseSE2& pose2, double dt, double& v, double& omega) const;
00449   
00468   void getVelocityProfile(std::vector<geometry_msgs::Twist>& velocity_profile) const;
00469   
00481   void getFullTrajectory(std::vector<TrajectoryPointMsg>& trajectory) const;
00482   
00496   virtual bool isTrajectoryFeasible(base_local_planner::CostmapModel* costmap_model, const std::vector<geometry_msgs::Point>& footprint_spec, double inscribed_radius = 0.0,
00497           double circumscribed_radius=0.0, int look_ahead_idx=-1);
00498   
00499   
00513   virtual bool isHorizonReductionAppropriate(const std::vector<geometry_msgs::PoseStamped>& initial_plan) const;
00514   
00516   
00517 protected:
00518   
00521   
00531   bool buildGraph();
00532   
00545   bool optimizeGraph(int no_iterations,bool clear_after=true);
00546   
00552   void clearGraph();
00553   
00566   void AddTEBVertices();
00567   
00574   void AddEdgesVelocity();
00575   
00584   void AddEdgesAcceleration();
00585   
00592   void AddEdgesTimeOptimal();
00593   
00601   void AddEdgesObstacles();
00602   
00603   
00611   void AddEdgesInflatedObstacles();
00612   
00619   void AddEdgesViaPoints();
00620   
00628   void AddEdgesDynamicObstacles();  
00629 
00637   void AddEdgesKinematicsDiffDrive();
00638   
00646   void AddEdgesKinematicsCarlike();
00647   
00649   
00650   
00655   boost::shared_ptr<g2o::SparseOptimizer> initOptimizer();
00656     
00657 
00658   // external objects (store weak pointers)
00659   const TebConfig* cfg_; 
00660   ObstContainer* obstacles_; 
00661   const ViaPointContainer* via_points_; 
00662   
00663   double cost_; 
00664   
00665   // internal objects (memory management owned)
00666   TebVisualizationPtr visualization_; 
00667   TimedElasticBand teb_; 
00668   RobotFootprintModelPtr robot_model_; 
00669   boost::shared_ptr<g2o::SparseOptimizer> optimizer_; 
00670   std::pair<bool, Eigen::Vector2d> vel_start_; 
00671   std::pair<bool, Eigen::Vector2d> vel_goal_; 
00672 
00673   bool initialized_; 
00674   bool optimized_; 
00675   
00676 public:
00677   EIGEN_MAKE_ALIGNED_OPERATOR_NEW    
00678 };
00679 
00681 typedef boost::shared_ptr<TebOptimalPlanner> TebOptimalPlannerPtr;
00683 typedef boost::shared_ptr<const TebOptimalPlanner> TebOptimalPlannerConstPtr;
00685 typedef std::vector< TebOptimalPlannerPtr > TebOptPlannerContainer;
00686 
00687 } // namespace teb_local_planner
00688 
00689 #endif /* OPTIMAL_PLANNER_H_ */


teb_local_planner
Author(s): Christoph Rösmann
autogenerated on Mon Oct 24 2016 05:31:15