All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
RRTstar.h
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2011, Rice University
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Rice University nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Authors: Alejandro Perez, Sertac Karaman, Ioan Sucan */
00036 
00037 #ifndef OMPL_CONTRIB_RRT_STAR_RRTSTAR_
00038 #define OMPL_CONTRIB_RRT_STAR_RRTSTAR_
00039 
00040 #include "ompl/geometric/planners/PlannerIncludes.h"
00041 #include "ompl/datastructures/NearestNeighbors.h"
00042 #include "ompl/base/spaces/RealVectorStateSpace.h"
00043 #include <limits>
00044 #include <vector>
00045 
00046 
00047 namespace ompl
00048 {
00049 
00050     namespace geometric
00051     {
00052 
00077         class RRTstar : public base::Planner
00078         {
00079         public:
00080 
00081             RRTstar(const base::SpaceInformationPtr &si) : base::Planner(si, "RRTstar")
00082             {
00083                 specs_.approximateSolutions = true;
00084                 specs_.optimizingPaths = true;
00085 
00086                 goalBias_ = 0.05;
00087                 maxDistance_ = 0.0;
00088                 ballRadiusMax_ = 0.0;
00089                 ballRadiusConst_ = 1.0;
00090                 delayCC_ = true;
00091             }
00092 
00093             virtual ~RRTstar(void)
00094             {
00095                 freeMemory();
00096             }
00097 
00098             virtual void getPlannerData(base::PlannerData &data) const;
00099 
00100             virtual bool solve(const base::PlannerTerminationCondition &ptc);
00101 
00102             virtual void clear(void);
00103 
00113             void setGoalBias(double goalBias)
00114             {
00115                 goalBias_ = goalBias;
00116             }
00117 
00119             double getGoalBias(void) const
00120             {
00121                 return goalBias_;
00122             }
00123 
00129             void setRange(double distance)
00130             {
00131                 maxDistance_ = distance;
00132             }
00133 
00135             double getRange(void) const
00136             {
00137                 return maxDistance_;
00138             }
00139 
00149             void setBallRadiusConstant(double ballRadiusConstant)
00150             {
00151                 ballRadiusConst_ = ballRadiusConstant;
00152             }
00153 
00157             double getBallRadiusConstant(void) const
00158             {
00159                 return ballRadiusConst_;
00160             }
00161 
00170             void setMaxBallRadius(double maxBallRadius)
00171             {
00172                 ballRadiusMax_ = maxBallRadius;
00173             }
00174 
00177             double getMaxBallRadius(void) const
00178             {
00179                 return ballRadiusMax_;
00180             }
00181 
00183             template<template<typename T> class NN>
00184             void setNearestNeighbors(void)
00185             {
00186                 nn_.reset(new NN<Motion*>());
00187             }
00188 
00196             void setDelayCC(bool delayCC)
00197             {
00198                 delayCC_ = delayCC;
00199             }
00200 
00202             bool getDelayCC(void) const
00203             {
00204                 return delayCC_;
00205             }
00206 
00207             virtual void setup(void);
00208 
00209         protected:
00210 
00211 
00213             class Motion
00214             {
00215             public:
00216 
00217                 Motion(void) : state(NULL), parent(NULL), cost(0.0)
00218                 {
00219                 }
00220 
00222                 Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(NULL), cost(0.0)
00223                 {
00224                 }
00225 
00226                 ~Motion(void)
00227                 {
00228                 }
00229 
00231                 base::State       *state;
00232 
00234                 Motion            *parent;
00235 
00237                 double             cost;
00238             };
00239 
00241             void freeMemory(void);
00242 
00244             static bool compareMotion(const Motion* a, const Motion* b)
00245             {
00246                 return (a->cost < b->cost);
00247             }
00248 
00250             double distanceFunction(const Motion* a, const Motion* b) const
00251             {
00252                 return si_->distance(a->state, b->state);
00253             }
00254 
00256             base::StateSamplerPtr                          sampler_;
00257 
00259             boost::shared_ptr< NearestNeighbors<Motion*> > nn_;
00260 
00262             double                                         goalBias_;
00263 
00265             double                                         maxDistance_;
00266 
00268             RNG                                            rng_;
00269 
00271             double                                         ballRadiusConst_;
00272 
00274             double                                         ballRadiusMax_;
00275 
00277             bool                                           delayCC_;
00278 
00279         };
00280 
00281     }
00282 }
00283 
00284 #endif