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 /* Author: Ryan Luna */ 00036 00037 #ifndef OMPL_CONTROL_PLANNERS_EST_EST_ 00038 #define OMPL_CONTROL_PLANNERS_EST_EST_ 00039 00040 #include "ompl/datastructures/Grid.h" 00041 #include "ompl/control/planners/PlannerIncludes.h" 00042 #include "ompl/base/ProjectionEvaluator.h" 00043 #include "ompl/datastructures/PDF.h" 00044 #include <boost/unordered_map.hpp> 00045 #include <vector> 00046 00047 namespace ompl 00048 { 00049 00050 namespace control 00051 { 00052 00077 class EST : public base::Planner 00078 { 00079 public: 00080 00082 EST(const SpaceInformationPtr &si); 00083 00084 virtual ~EST(void); 00085 00086 virtual bool solve(const base::PlannerTerminationCondition &ptc); 00087 00088 virtual void clear(void); 00089 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 00126 void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator) 00127 { 00128 projectionEvaluator_ = projectionEvaluator; 00129 } 00130 00133 void setProjectionEvaluator(const std::string &name) 00134 { 00135 projectionEvaluator_ = si_->getStateSpace()->getProjection(name); 00136 } 00137 00139 const base::ProjectionEvaluatorPtr& getProjectionEvaluator(void) const 00140 { 00141 return projectionEvaluator_; 00142 } 00143 00144 virtual void setup(void); 00145 00146 virtual void getPlannerData(base::PlannerData &data) const; 00147 00148 protected: 00149 00154 class Motion 00155 { 00156 public: 00157 00158 Motion(void) : state(NULL), control(NULL), steps(0), parent(NULL) 00159 { 00160 } 00161 00163 Motion(const SpaceInformation *si) : state(si->allocState()), control(si->allocControl()), steps(0), parent(NULL) 00164 { 00165 } 00166 00167 ~Motion(void) 00168 { 00169 } 00170 00172 base::State *state; 00173 00175 Control *control; 00176 00178 unsigned int steps; 00179 00181 Motion *parent; 00182 }; 00183 00184 struct MotionInfo; 00185 00187 typedef Grid<MotionInfo>::Cell GridCell; 00188 00190 typedef PDF<GridCell*> CellPDF; 00191 00193 struct MotionInfo 00194 { 00195 Motion* operator[](unsigned int i) 00196 { 00197 return motions_[i]; 00198 } 00199 const Motion* operator[](unsigned int i) const 00200 { 00201 return motions_[i]; 00202 } 00203 void push_back(Motion* m) 00204 { 00205 motions_.push_back(m); 00206 } 00207 unsigned int size(void) const 00208 { 00209 return motions_.size(); 00210 } 00211 bool empty(void) const 00212 { 00213 return motions_.empty(); 00214 } 00215 std::vector<Motion*> motions_; 00216 CellPDF::Element* elem_; 00217 }; 00218 00220 struct TreeData 00221 { 00222 TreeData(void) : grid(0), size(0) 00223 { 00224 } 00225 00227 Grid<MotionInfo> grid; 00228 00230 unsigned int size; 00231 }; 00232 00234 void freeMemory(void); 00235 00237 void addMotion(Motion *motion); 00238 00240 Motion* selectMotion(void); 00241 00243 base::ValidStateSamplerPtr sampler_; 00244 00246 DirectedControlSamplerPtr controlSampler_; 00247 00249 const SpaceInformation *siC_; 00250 00252 TreeData tree_; 00253 00255 base::ProjectionEvaluatorPtr projectionEvaluator_; 00256 00258 double goalBias_; 00259 00261 double maxDistance_; 00262 00264 RNG rng_; 00265 00267 CellPDF pdf_; 00268 }; 00269 00270 } 00271 } 00272 00273 #endif