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); 00082 00083 virtual ~RRTstar(void); 00084 00085 virtual void getPlannerData(base::PlannerData &data) const; 00086 00087 virtual bool solve(const base::PlannerTerminationCondition &ptc); 00088 00089 virtual void clear(void); 00090 00100 void setGoalBias(double goalBias) 00101 { 00102 goalBias_ = goalBias; 00103 } 00104 00106 double getGoalBias(void) const 00107 { 00108 return goalBias_; 00109 } 00110 00116 void setRange(double distance) 00117 { 00118 maxDistance_ = distance; 00119 } 00120 00122 double getRange(void) const 00123 { 00124 return maxDistance_; 00125 } 00126 00136 void setBallRadiusConstant(double ballRadiusConstant) 00137 { 00138 ballRadiusConst_ = ballRadiusConstant; 00139 } 00140 00144 double getBallRadiusConstant(void) const 00145 { 00146 return ballRadiusConst_; 00147 } 00148 00157 void setMaxBallRadius(double maxBallRadius) 00158 { 00159 ballRadiusMax_ = maxBallRadius; 00160 } 00161 00164 double getMaxBallRadius(void) const 00165 { 00166 return ballRadiusMax_; 00167 } 00168 00170 template<template<typename T> class NN> 00171 void setNearestNeighbors(void) 00172 { 00173 nn_.reset(new NN<Motion*>()); 00174 } 00175 00183 void setDelayCC(bool delayCC) 00184 { 00185 delayCC_ = delayCC; 00186 } 00187 00189 bool getDelayCC(void) const 00190 { 00191 return delayCC_; 00192 } 00193 00194 virtual void setup(void); 00195 00196 protected: 00197 00198 00200 class Motion 00201 { 00202 public: 00203 00204 Motion(void) : state(NULL), parent(NULL), cost(0.0) 00205 { 00206 } 00207 00209 Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(NULL), cost(0.0) 00210 { 00211 } 00212 00213 ~Motion(void) 00214 { 00215 } 00216 00218 base::State *state; 00219 00221 Motion *parent; 00222 00224 double cost; 00225 00227 std::vector<Motion*> children; 00228 }; 00229 00231 void freeMemory(void); 00232 00234 static bool compareMotion(const Motion* a, const Motion* b) 00235 { 00236 return (a->cost < b->cost); 00237 } 00238 00240 double distanceFunction(const Motion* a, const Motion* b) const 00241 { 00242 return si_->distance(a->state, b->state); 00243 } 00244 00246 void removeFromParent(Motion *m); 00247 00249 void updateChildCosts(Motion *m, double delta); 00250 00252 base::StateSamplerPtr sampler_; 00253 00255 boost::shared_ptr< NearestNeighbors<Motion*> > nn_; 00256 00258 double goalBias_; 00259 00261 double maxDistance_; 00262 00264 RNG rng_; 00265 00267 double ballRadiusConst_; 00268 00270 double ballRadiusMax_; 00271 00273 bool delayCC_; 00274 00275 }; 00276 00277 } 00278 } 00279 00280 #endif