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 00074 class RRTstar : public base::Planner 00075 { 00076 public: 00077 00078 RRTstar(const base::SpaceInformationPtr &si); 00079 00080 virtual ~RRTstar(void); 00081 00082 virtual void getPlannerData(base::PlannerData &data) const; 00083 00084 virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc); 00085 00086 virtual void clear(void); 00087 00097 void setGoalBias(double goalBias) 00098 { 00099 goalBias_ = goalBias; 00100 } 00101 00103 double getGoalBias(void) const 00104 { 00105 return goalBias_; 00106 } 00107 00113 void setRange(double distance) 00114 { 00115 maxDistance_ = distance; 00116 } 00117 00119 double getRange(void) const 00120 { 00121 return maxDistance_; 00122 } 00123 00133 void setBallRadiusConstant(double ballRadiusConstant) 00134 { 00135 ballRadiusConst_ = ballRadiusConstant; 00136 } 00137 00141 double getBallRadiusConstant(void) const 00142 { 00143 return ballRadiusConst_; 00144 } 00145 00154 void setMaxBallRadius(double maxBallRadius) 00155 { 00156 ballRadiusMax_ = maxBallRadius; 00157 } 00158 00161 double getMaxBallRadius(void) const 00162 { 00163 return ballRadiusMax_; 00164 } 00165 00167 template<template<typename T> class NN> 00168 void setNearestNeighbors(void) 00169 { 00170 nn_.reset(new NN<Motion*>()); 00171 } 00172 00180 void setDelayCC(bool delayCC) 00181 { 00182 delayCC_ = delayCC; 00183 } 00184 00186 bool getDelayCC(void) const 00187 { 00188 return delayCC_; 00189 } 00190 00191 virtual void setup(void); 00192 00193 protected: 00194 00195 00197 class Motion 00198 { 00199 public: 00200 00201 Motion(void) : state(NULL), parent(NULL), cost(0.0) 00202 { 00203 } 00204 00206 Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(NULL), cost(0.0) 00207 { 00208 } 00209 00210 ~Motion(void) 00211 { 00212 } 00213 00215 base::State *state; 00216 00218 Motion *parent; 00219 00221 double cost; 00222 00224 std::vector<Motion*> children; 00225 }; 00226 00228 void freeMemory(void); 00229 00231 static bool compareMotion(const Motion* a, const Motion* b) 00232 { 00233 return (a->cost < b->cost); 00234 } 00235 00237 double distanceFunction(const Motion* a, const Motion* b) const 00238 { 00239 return si_->distance(a->state, b->state); 00240 } 00241 00243 void removeFromParent(Motion *m); 00244 00246 void updateChildCosts(Motion *m, double delta); 00247 00249 base::StateSamplerPtr sampler_; 00250 00252 boost::shared_ptr< NearestNeighbors<Motion*> > nn_; 00253 00255 double goalBias_; 00256 00258 double maxDistance_; 00259 00261 RNG rng_; 00262 00264 double ballRadiusConst_; 00265 00267 double ballRadiusMax_; 00268 00270 bool delayCC_; 00271 00272 }; 00273 00274 } 00275 } 00276 00277 #endif