00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, 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: Ioan Sucan */ 00036 00037 #ifndef OMPL_CONTROL_SIMPLE_SETUP_ 00038 #define OMPL_CONTROL_SIMPLE_SETUP_ 00039 00040 #include "ompl/base/Planner.h" 00041 #include "ompl/control/SpaceInformation.h" 00042 #include "ompl/control/PlannerData.h" 00043 #include "ompl/base/ProblemDefinition.h" 00044 #include "ompl/control/PathControl.h" 00045 #include "ompl/geometric/PathGeometric.h" 00046 #include "ompl/util/Console.h" 00047 #include "ompl/util/Exception.h" 00048 00049 namespace ompl 00050 { 00051 00052 namespace control 00053 { 00055 ClassForward(SimpleSetup); 00057 00063 class SimpleSetup 00064 { 00065 public: 00066 00068 explicit 00069 SimpleSetup(const ControlSpacePtr &space); 00070 00071 virtual ~SimpleSetup(void) 00072 { 00073 } 00074 00076 const SpaceInformationPtr& getSpaceInformation(void) const 00077 { 00078 return si_; 00079 } 00080 00082 const base::ProblemDefinitionPtr& getProblemDefinition(void) const 00083 { 00084 return pdef_; 00085 } 00086 00088 const base::StateSpacePtr& getStateSpace(void) const 00089 { 00090 return si_->getStateSpace(); 00091 } 00092 00094 const ControlSpacePtr& getControlSpace(void) const 00095 { 00096 return si_->getControlSpace(); 00097 } 00098 00100 const base::StateValidityCheckerPtr& getStateValidityChecker(void) const 00101 { 00102 return si_->getStateValidityChecker(); 00103 } 00104 00105 const StatePropagatorPtr& getStatePropagator(void) const 00106 { 00107 return si_->getStatePropagator(); 00108 } 00109 00111 const base::GoalPtr& getGoal(void) const 00112 { 00113 return pdef_->getGoal(); 00114 } 00115 00117 const base::PlannerPtr& getPlanner(void) const 00118 { 00119 return planner_; 00120 } 00121 00123 const base::PlannerAllocator& getPlannerAllocator(void) const 00124 { 00125 return pa_; 00126 } 00127 00129 bool haveExactSolutionPath(void) const; 00130 00131 00133 bool haveSolutionPath(void) const 00134 { 00135 return getGoal()->getSolutionPath(); 00136 } 00137 00139 PathControl& getSolutionPath(void) const; 00140 00142 control::PlannerData getPlannerData(void) const; 00143 00145 void setStateValidityChecker(const base::StateValidityCheckerPtr &svc) 00146 { 00147 si_->setStateValidityChecker(svc); 00148 } 00149 00151 void setStateValidityChecker(const base::StateValidityCheckerFn &svc) 00152 { 00153 si_->setStateValidityChecker(svc); 00154 } 00155 00157 void setStatePropagator(const StatePropagatorFn &sp) 00158 { 00159 si_->setStatePropagator(sp); 00160 } 00161 00163 void setStatePropagator(const StatePropagatorPtr &sp) 00164 { 00165 si_->setStatePropagator(sp); 00166 } 00167 00169 void setStartAndGoalStates(const base::ScopedState<> &start, const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon()) 00170 { 00171 pdef_->setStartAndGoalStates(start, goal, threshold); 00172 } 00173 00175 void setGoalState(const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon()) 00176 { 00177 pdef_->setGoalState(goal, threshold); 00178 } 00179 00182 void addStartState(const base::ScopedState<> &state) 00183 { 00184 pdef_->addStartState(state); 00185 } 00186 00188 void clearStartStates(void) 00189 { 00190 pdef_->clearStartStates(); 00191 } 00192 00194 void setStartState(const base::ScopedState<> &state) 00195 { 00196 clearStartStates(); 00197 addStartState(state); 00198 } 00199 00202 void setGoal(const base::GoalPtr &goal) 00203 { 00204 pdef_->setGoal(goal); 00205 } 00206 00211 void setPlanner(const base::PlannerPtr &planner) 00212 { 00213 if (planner && planner->getSpaceInformation().get() != si_.get()) 00214 throw Exception("Planner instance does not match space information"); 00215 planner_ = planner; 00216 configured_ = false; 00217 } 00218 00222 void setPlannerAllocator(const base::PlannerAllocator &pa) 00223 { 00224 pa_ = pa; 00225 planner_.reset(); 00226 configured_ = false; 00227 } 00228 00230 virtual bool solve(double time = 1.0); 00231 00233 virtual bool solve(const base::PlannerTerminationCondition &ptc); 00234 00236 bool invalidLastRequest(void) const 00237 { 00238 return invalid_request_; 00239 } 00240 00242 double getLastPlanComputationTime(void) const 00243 { 00244 return planTime_; 00245 } 00246 00250 virtual void clear(void); 00251 00253 virtual void print(std::ostream &out = std::cout) const; 00254 00258 virtual void setup(void); 00259 00261 base::ParamSet& params(void) 00262 { 00263 return params_; 00264 } 00265 00267 const base::ParamSet& params(void) const 00268 { 00269 return params_; 00270 } 00271 00272 protected: 00273 00275 SpaceInformationPtr si_; 00276 00278 base::ProblemDefinitionPtr pdef_; 00279 00281 base::PlannerPtr planner_; 00282 00284 base::PlannerAllocator pa_; 00285 00287 bool configured_; 00288 00290 double planTime_; 00291 00293 bool invalid_request_; 00294 00296 base::ParamSet params_; 00297 00299 msg::Interface msg_; 00300 }; 00301 00303 base::PlannerPtr getDefaultPlanner(const base::GoalPtr &goal); 00304 } 00305 00306 } 00307 #endif