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 { 00054 00057 class SimpleSetup 00058 { 00059 public: 00060 00062 explicit 00063 SimpleSetup(const ControlSpacePtr &space) : configured_(false), planTime_(0.0), msg_("SimpleSetup") 00064 { 00065 si_.reset(new SpaceInformation(space->getStateSpace(), space)); 00066 pdef_.reset(new base::ProblemDefinition(si_)); 00067 } 00068 00069 virtual ~SimpleSetup(void) 00070 { 00071 } 00072 00074 const SpaceInformationPtr& getSpaceInformation(void) const 00075 { 00076 return si_; 00077 } 00078 00080 const base::ProblemDefinitionPtr& getProblemDefinition(void) const 00081 { 00082 return pdef_; 00083 } 00084 00086 const base::StateSpacePtr& getStateSpace(void) const 00087 { 00088 return si_->getStateSpace(); 00089 } 00090 00092 const ControlSpacePtr& getControlSpace(void) const 00093 { 00094 return si_->getControlSpace(); 00095 } 00096 00098 const base::StateValidityCheckerPtr& getStateValidityChecker(void) const 00099 { 00100 return si_->getStateValidityChecker(); 00101 } 00102 00103 const StatePropagatorPtr& getStatePropagator(void) const 00104 { 00105 return si_->getStatePropagator(); 00106 } 00107 00109 const base::GoalPtr& getGoal(void) const 00110 { 00111 return pdef_->getGoal(); 00112 } 00113 00115 const base::PlannerPtr& getPlanner(void) const 00116 { 00117 return planner_; 00118 } 00119 00121 bool haveExactSolutionPath(void) const 00122 { 00123 return haveSolutionPath() && !getGoal()->isApproximate(); 00124 } 00125 00127 bool haveSolutionPath(void) const 00128 { 00129 return getGoal()->getSolutionPath(); 00130 } 00131 00133 PathControl& getSolutionPath(void) const; 00134 00136 control::PlannerData getPlannerData(void) const; 00137 00139 void setStateValidityChecker(const base::StateValidityCheckerPtr &svc) 00140 { 00141 si_->setStateValidityChecker(svc); 00142 } 00143 00145 void setStateValidityChecker(const base::StateValidityCheckerFn &svc) 00146 { 00147 si_->setStateValidityChecker(svc); 00148 } 00149 00151 void setStatePropagator(const StatePropagatorFn &sp) 00152 { 00153 si_->setStatePropagator(sp); 00154 } 00155 00157 void setStatePropagator(const StatePropagatorPtr &sp) 00158 { 00159 si_->setStatePropagator(sp); 00160 } 00161 00163 void setStartAndGoalStates(const base::ScopedState<> &start, const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon()) 00164 { 00165 pdef_->setStartAndGoalStates(start, goal, threshold); 00166 } 00167 00169 void setGoalState(const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon()) 00170 { 00171 pdef_->setGoalState(goal, threshold); 00172 } 00173 00176 void addStartState(const base::ScopedState<> &state) 00177 { 00178 pdef_->addStartState(state); 00179 } 00180 00182 void clearStartStates(void) 00183 { 00184 pdef_->clearStartStates(); 00185 } 00186 00188 void setStartState(const base::ScopedState<> &state) 00189 { 00190 clearStartStates(); 00191 addStartState(state); 00192 } 00193 00196 void setGoal(const base::GoalPtr &goal) 00197 { 00198 pdef_->setGoal(goal); 00199 } 00200 00205 void setPlanner(const base::PlannerPtr &planner) 00206 { 00207 if (planner && planner->getSpaceInformation().get() != si_.get()) 00208 throw Exception("Planner instance does not match space information"); 00209 planner_ = planner; 00210 configured_ = false; 00211 } 00212 00216 void setPlannerAllocator(const base::PlannerAllocator &pa) 00217 { 00218 pa_ = pa; 00219 planner_.reset(); 00220 configured_ = false; 00221 } 00222 00224 virtual bool solve(double time = 1.0); 00225 00227 double getLastPlanComputationTime(void) const 00228 { 00229 return planTime_; 00230 } 00231 00235 virtual void clear(void); 00236 00238 virtual void print(std::ostream &out = std::cout) const; 00239 00243 virtual void setup(void); 00244 00245 protected: 00246 00248 SpaceInformationPtr si_; 00249 00251 base::ProblemDefinitionPtr pdef_; 00252 00254 base::PlannerPtr planner_; 00255 00257 base::PlannerAllocator pa_; 00258 00260 bool configured_; 00261 00263 double planTime_; 00264 00266 msg::Interface msg_; 00267 }; 00268 00270 base::PlannerPtr getDefaultPlanner(const base::GoalPtr &goal); 00271 } 00272 00273 } 00274 #endif