ompl/control/planners/est/EST.h
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 00074 class EST : public base::Planner 00075 { 00076 public: 00077 00079 EST(const SpaceInformationPtr &si); 00080 00081 virtual ~EST(); 00082 00083 virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc); 00084 00085 virtual void clear(); 00086 00094 void setGoalBias(double goalBias) 00095 { 00096 goalBias_ = goalBias; 00097 } 00098 00100 double getGoalBias() const 00101 { 00102 return goalBias_; 00103 } 00104 00110 void setRange(double distance) 00111 { 00112 maxDistance_ = distance; 00113 } 00114 00116 double getRange() const 00117 { 00118 return maxDistance_; 00119 } 00120 00123 void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator) 00124 { 00125 projectionEvaluator_ = projectionEvaluator; 00126 } 00127 00130 void setProjectionEvaluator(const std::string &name) 00131 { 00132 projectionEvaluator_ = si_->getStateSpace()->getProjection(name); 00133 } 00134 00136 const base::ProjectionEvaluatorPtr& getProjectionEvaluator() const 00137 { 00138 return projectionEvaluator_; 00139 } 00140 00141 virtual void setup(); 00142 00143 virtual void getPlannerData(base::PlannerData &data) const; 00144 00145 protected: 00146 00151 class Motion 00152 { 00153 public: 00154 00155 Motion() : state(NULL), control(NULL), steps(0), parent(NULL) 00156 { 00157 } 00158 00160 Motion(const SpaceInformation *si) : state(si->allocState()), control(si->allocControl()), steps(0), parent(NULL) 00161 { 00162 } 00163 00164 ~Motion() 00165 { 00166 } 00167 00169 base::State *state; 00170 00172 Control *control; 00173 00175 unsigned int steps; 00176 00178 Motion *parent; 00179 }; 00180 00181 struct MotionInfo; 00182 00184 typedef Grid<MotionInfo>::Cell GridCell; 00185 00187 typedef PDF<GridCell*> CellPDF; 00188 00190 struct MotionInfo 00191 { 00192 Motion* operator[](unsigned int i) 00193 { 00194 return motions_[i]; 00195 } 00196 const Motion* operator[](unsigned int i) const 00197 { 00198 return motions_[i]; 00199 } 00200 void push_back(Motion *m) 00201 { 00202 motions_.push_back(m); 00203 } 00204 unsigned int size() const 00205 { 00206 return motions_.size(); 00207 } 00208 bool empty() const 00209 { 00210 return motions_.empty(); 00211 } 00212 std::vector<Motion*> motions_; 00213 CellPDF::Element *elem_; 00214 }; 00215 00217 struct TreeData 00218 { 00219 TreeData() : grid(0), size(0) 00220 { 00221 } 00222 00224 Grid<MotionInfo> grid; 00225 00227 unsigned int size; 00228 }; 00229 00231 void freeMemory(); 00232 00234 void addMotion(Motion *motion); 00235 00237 Motion* selectMotion(); 00238 00240 base::ValidStateSamplerPtr sampler_; 00241 00243 DirectedControlSamplerPtr controlSampler_; 00244 00246 const SpaceInformation *siC_; 00247 00249 TreeData tree_; 00250 00252 base::ProjectionEvaluatorPtr projectionEvaluator_; 00253 00255 double goalBias_; 00256 00258 double maxDistance_; 00259 00261 RNG rng_; 00262 00264 CellPDF pdf_; 00265 00267 Motion *lastGoalMotion_; 00268 }; 00269 00270 } 00271 } 00272 00273 #endif