All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
LazyRRT.h
00001 
00002 /*********************************************************************
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2008, Willow Garage, Inc.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of the Willow Garage nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *********************************************************************/
00035 
00036 /* Author: Ioan Sucan */
00037 
00038 #ifndef OMPL_GEOMETRIC_PLANNERS_RRT_LAZY_RRT_
00039 #define OMPL_GEOMETRIC_PLANNERS_RRT_LAZY_RRT_
00040 
00041 #include "ompl/geometric/planners/PlannerIncludes.h"
00042 #include "ompl/datastructures/NearestNeighbors.h"
00043 #include <vector>
00044 
00045 namespace ompl
00046 {
00047 
00048     namespace geometric
00049     {
00050 
00081         class LazyRRT : public base::Planner
00082         {
00083         public:
00084 
00086             LazyRRT(const base::SpaceInformationPtr &si) : base::Planner(si, "LazyRRT")
00087             {
00088                 goalBias_ = 0.05;
00089                 maxDistance_ = 0.0;
00090             }
00091 
00092             virtual ~LazyRRT(void)
00093             {
00094                 freeMemory();
00095             }
00096 
00097             virtual void getPlannerData(base::PlannerData &data) const;
00098 
00099             virtual bool solve(const base::PlannerTerminationCondition &ptc);
00100 
00101             virtual void clear(void);
00102 
00112             void setGoalBias(double goalBias)
00113             {
00114                 goalBias_ = goalBias;
00115             }
00116 
00118             double getGoalBias(void) const
00119             {
00120                 return goalBias_;
00121             }
00122 
00128             void setRange(double distance)
00129             {
00130                 maxDistance_ = distance;
00131             }
00132 
00134             double getRange(void) const
00135             {
00136                 return maxDistance_;
00137             }
00138 
00140             template<template<typename T> class NN>
00141             void setNearestNeighbors(void)
00142             {
00143                 nn_.reset(new NN<Motion*>());
00144             }
00145 
00146             virtual void setup(void);
00147 
00148         protected:
00149 
00151             class Motion
00152             {
00153             public:
00154 
00155                 Motion(void) : state(NULL), parent(NULL), valid(false)
00156                 {
00157                 }
00158 
00160                 Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(NULL), valid(false)
00161                 {
00162                 }
00163 
00164                 ~Motion(void)
00165                 {
00166                 }
00167 
00169                 base::State          *state;
00170 
00172                 Motion               *parent;
00173 
00175                 bool                  valid;
00176 
00178                 std::vector<Motion*>  children;
00179             };
00180 
00182             void freeMemory(void);
00183 
00185             void removeMotion(Motion *motion);
00186 
00188             double distanceFunction(const Motion* a, const Motion* b) const
00189             {
00190                 return si_->distance(a->state, b->state);
00191             }
00192 
00194             base::StateSamplerPtr                          sampler_;
00195 
00197             boost::shared_ptr< NearestNeighbors<Motion*> > nn_;
00198 
00200             double                                         goalBias_;
00201 
00203             double                                         maxDistance_;
00204 
00206             RNG                                            rng_;
00207 
00208         };
00209 
00210     }
00211 }
00212 
00213 #endif