All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
SimpleSetup.h
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_GEOMETRIC_SIMPLE_SETUP_
00038 #define OMPL_GEOMETRIC_SIMPLE_SETUP_
00039 
00040 #include "ompl/base/Planner.h"
00041 #include "ompl/base/SpaceInformation.h"
00042 #include "ompl/base/ProblemDefinition.h"
00043 #include "ompl/geometric/PathGeometric.h"
00044 #include "ompl/geometric/PathSimplifier.h"
00045 #include "ompl/util/Console.h"
00046 #include "ompl/util/Exception.h"
00047 
00048 namespace ompl
00049 {
00050 
00051     namespace geometric
00052     {
00053 
00056         class SimpleSetup
00057         {
00058         public:
00059 
00061             explicit
00062             SimpleSetup(const base::StateSpacePtr &space) : configured_(false), planTime_(0.0), simplifyTime_(0.0), msg_("SimpleSetup")
00063             {
00064                 si_.reset(new base::SpaceInformation(space));
00065                 pdef_.reset(new base::ProblemDefinition(si_));
00066                 psk_.reset(new PathSimplifier(si_));
00067             }
00068 
00069             virtual ~SimpleSetup(void)
00070             {
00071             }
00072 
00074             const base::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 base::StateValidityCheckerPtr& getStateValidityChecker(void) const
00093             {
00094                 return si_->getStateValidityChecker();
00095             }
00096 
00098             const base::GoalPtr& getGoal(void) const
00099             {
00100                 return pdef_->getGoal();
00101             }
00102 
00104             const base::PlannerPtr& getPlanner(void) const
00105             {
00106                 return planner_;
00107             }
00108 
00110             const PathSimplifierPtr& getPathSimplifier(void) const
00111             {
00112                 return psk_;
00113             }
00114 
00116             PathSimplifierPtr& getPathSimplifier(void)
00117             {
00118                 return psk_;
00119             }
00120 
00122             bool haveExactSolutionPath(void) const
00123             {
00124                 return haveSolutionPath() && !getGoal()->isApproximate();
00125             }
00126 
00128             bool haveSolutionPath(void) const
00129             {
00130                 return getGoal()->getSolutionPath();
00131             }
00132 
00134             PathGeometric& getSolutionPath(void) const;
00135 
00137             base::PlannerData getPlannerData(void) const;
00138 
00140             void setStateValidityChecker(const base::StateValidityCheckerPtr &svc)
00141             {
00142                 si_->setStateValidityChecker(svc);
00143             }
00144 
00146             void setStateValidityChecker(const base::StateValidityCheckerFn &svc)
00147             {
00148                 si_->setStateValidityChecker(svc);
00149             }
00150 
00152             void setStartAndGoalStates(const base::ScopedState<> &start, const base::ScopedState<> &goal,
00153                                        const double threshold = std::numeric_limits<double>::epsilon())
00154             {
00155                 pdef_->setStartAndGoalStates(start, goal, threshold);
00156             }
00157 
00160             void addStartState(const base::ScopedState<> &state)
00161             {
00162                 pdef_->addStartState(state);
00163             }
00164 
00166             void clearStartStates(void)
00167             {
00168                 pdef_->clearStartStates();
00169             }
00170 
00172             void setStartState(const base::ScopedState<> &state)
00173             {
00174                 clearStartStates();
00175                 addStartState(state);
00176             }
00177 
00179             void setGoalState(const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon())
00180             {
00181                 pdef_->setGoalState(goal, threshold);
00182             }
00183 
00186             void setGoal(const base::GoalPtr &goal)
00187             {
00188                 pdef_->setGoal(goal);
00189             }
00190 
00195             void setPlanner(const base::PlannerPtr &planner)
00196             {
00197                 if (planner && planner->getSpaceInformation().get() != si_.get())
00198                     throw Exception("Planner instance does not match space information");
00199                 planner_ = planner;
00200                 configured_ = false;
00201             }
00202 
00206             void setPlannerAllocator(const base::PlannerAllocator &pa)
00207             {
00208                 pa_ = pa;
00209                 planner_.reset();
00210                 configured_ = false;
00211             }
00212 
00214             virtual bool solve(double time = 1.0);
00215 
00217             double getLastPlanComputationTime(void) const
00218             {
00219                 return planTime_;
00220             }
00221 
00223             double getLastSimplificationTime(void) const
00224             {
00225                 return simplifyTime_;
00226             }
00227 
00229             void simplifySolution(void);
00230 
00234             virtual void clear(void);
00235 
00237             virtual void print(std::ostream &out = std::cout) const;
00238 
00242             virtual void setup(void);
00243 
00244         protected:
00245 
00247             base::SpaceInformationPtr     si_;
00248 
00250             base::ProblemDefinitionPtr    pdef_;
00251 
00253             base::PlannerPtr              planner_;
00254 
00256             base::PlannerAllocator        pa_;
00257 
00259             PathSimplifierPtr             psk_;
00260 
00262             bool                          configured_;
00263 
00265             double                        planTime_;
00266 
00268             double                        simplifyTime_;
00269 
00271             msg::Interface                msg_;
00272 
00273         };
00274 
00276         base::PlannerPtr getDefaultPlanner(const base::GoalPtr &goal);
00277     }
00278 
00279 }
00280 #endif