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 terminate_ = true; 00092 00093 } 00094 00095 virtual ~RRTstar(void) 00096 { 00097 freeMemory(); 00098 } 00099 00100 virtual void getPlannerData(base::PlannerData &data) const; 00101 00102 virtual bool solve(const base::PlannerTerminationCondition &ptc); 00103 00104 virtual void clear(void); 00105 00115 void setGoalBias(double goalBias) 00116 { 00117 goalBias_ = goalBias; 00118 } 00119 00121 double getGoalBias(void) const 00122 { 00123 return goalBias_; 00124 } 00125 00131 void setRange(double distance) 00132 { 00133 maxDistance_ = distance; 00134 } 00135 00137 double getRange(void) const 00138 { 00139 return maxDistance_; 00140 } 00141 00151 void setBallRadiusConstant(double ballRadiusConstant) 00152 { 00153 ballRadiusConst_ = ballRadiusConstant; 00154 } 00155 00159 double getBallRadiusConstant(void) const 00160 { 00161 return ballRadiusConst_; 00162 } 00163 00172 void setMaxBallRadius(double maxBallRadius) 00173 { 00174 ballRadiusMax_ = maxBallRadius; 00175 } 00176 00179 double getMaxBallRadius(void) const 00180 { 00181 return ballRadiusMax_; 00182 } 00183 00185 template<template<typename T> class NN> 00186 void setNearestNeighbors(void) 00187 { 00188 nn_.reset(new NN<Motion*>()); 00189 } 00190 00198 void setDelayCC(bool delayCC) 00199 { 00200 delayCC_ = delayCC; 00201 } 00202 00204 bool getDelayCC(void) const 00205 { 00206 return delayCC_; 00207 } 00208 00213 void setTerminate(bool terminate) 00214 { 00215 terminate_ = terminate; 00216 } 00217 00219 bool getTerminate(void) const 00220 { 00221 return terminate_; 00222 } 00223 00224 virtual void setup(void); 00225 00226 protected: 00227 00228 00230 class Motion 00231 { 00232 public: 00233 00234 Motion(void) : state(NULL), parent(NULL), cost(0.0) 00235 { 00236 } 00237 00239 Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(NULL), cost(0.0) 00240 { 00241 } 00242 00243 ~Motion(void) 00244 { 00245 } 00246 00248 base::State *state; 00249 00251 Motion *parent; 00252 00254 double cost; 00255 }; 00256 00258 void freeMemory(void); 00259 00261 static bool compareMotion(const Motion* a, const Motion* b) 00262 { 00263 return (a->cost < b->cost); 00264 } 00265 00267 double distanceFunction(const Motion* a, const Motion* b) const 00268 { 00269 return si_->distance(a->state, b->state); 00270 } 00271 00273 base::StateSamplerPtr sampler_; 00274 00276 boost::shared_ptr< NearestNeighbors<Motion*> > nn_; 00277 00279 double goalBias_; 00280 00282 double maxDistance_; 00283 00285 RNG rng_; 00286 00288 double ballRadiusConst_; 00289 00291 double ballRadiusMax_; 00292 00294 bool delayCC_; 00295 00297 bool terminate_; 00298 }; 00299 00300 } 00301 } 00302 00303 #endif