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_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/base/ProblemDefinition.h"
00043 #include "ompl/control/PathControl.h"
00044 #include "ompl/geometric/PathGeometric.h"
00045 #include "ompl/util/Console.h"
00046 #include "ompl/util/Exception.h"
00047 
00048 namespace ompl
00049 {
00050 
00051     namespace control
00052     {
00053 
00056         class SimpleSetup
00057         {
00058         public:
00059 
00061             explicit
00062             SimpleSetup(const ControlManifoldPtr &manifold) : configured_(false), planTime_(0.0), msg_("SimpleSetup")
00063             {
00064                 si_.reset(new SpaceInformation(manifold->getStateManifold(), manifold));
00065                 pdef_.reset(new base::ProblemDefinition(si_));
00066             }
00067 
00068             virtual ~SimpleSetup(void)
00069             {
00070             }
00071 
00073             const SpaceInformationPtr& getSpaceInformation(void) const
00074             {
00075                 return si_;
00076             }
00077 
00079             const base::ProblemDefinitionPtr& getProblemDefinition(void) const
00080             {
00081                 return pdef_;
00082             }
00083 
00085             const base::StateManifoldPtr& getStateManifold(void) const
00086             {
00087                 return si_->getStateManifold();
00088             }
00089 
00091             const ControlManifoldPtr& getControlManifold(void) const
00092             {
00093                 return si_->getControlManifold();
00094             }
00095 
00097             const base::StateValidityCheckerPtr& getStateValidityChecker(void) const
00098             {
00099                 return si_->getStateValidityChecker();
00100             }
00101 
00103             const base::GoalPtr& getGoal(void) const
00104             {
00105                 return pdef_->getGoal();
00106             }
00107 
00109             const base::PlannerPtr& getPlanner(void) const
00110             {
00111                 return planner_;
00112             }
00113 
00115             bool haveExactSolutionPath(void) const
00116             {
00117                 return haveSolutionPath() && !getGoal()->isApproximate();
00118             }
00119 
00121             bool haveSolutionPath(void) const
00122             {
00123                 return getGoal()->getSolutionPath();
00124             }
00125 
00127             PathControl& getSolutionPath(void) const;
00128 
00130             base::PlannerData getPlannerData(void) const;
00131 
00133             void setStateValidityChecker(const base::StateValidityCheckerPtr &svc)
00134             {
00135                 si_->setStateValidityChecker(svc);
00136             }
00137 
00139             void setStateValidityChecker(const base::StateValidityCheckerFn &svc)
00140             {
00141                 si_->setStateValidityChecker(svc);
00142             }
00143 
00145             void setStartAndGoalStates(const base::ScopedState<> &start, const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon())
00146             {
00147                 pdef_->setStartAndGoalStates(start, goal, threshold);
00148             }
00149 
00151             void setGoalState(const base::ScopedState<> &goal, const double threshold = std::numeric_limits<double>::epsilon())
00152             {
00153                 pdef_->setGoalState(goal, threshold);
00154             }
00155 
00158             void addStartState(const base::ScopedState<> &state)
00159             {
00160                 pdef_->addStartState(state);
00161             }
00162 
00164             void clearStartStates(void)
00165             {
00166                 pdef_->clearStartStates();
00167             }
00168 
00170             void setStartState(const base::ScopedState<> &state)
00171             {
00172                 clearStartStates();
00173                 addStartState(state);
00174             }
00175 
00178             void setGoal(const base::GoalPtr &goal)
00179             {
00180                 pdef_->setGoal(goal);
00181             }
00182 
00187             void setPlanner(const base::PlannerPtr &planner)
00188             {
00189                 if (planner && planner->getSpaceInformation().get() != si_.get())
00190                     throw Exception("Planner instance does not match space information");
00191                 planner_ = planner;
00192                 configured_ = false;
00193             }
00194 
00198             void setPlannerAllocator(const base::PlannerAllocator &pa)
00199             {
00200                 pa_ = pa;
00201                 planner_.reset();
00202                 configured_ = false;
00203             }
00204 
00208             void updateProjectionCellSizes(void);
00209 
00211             virtual bool solve(double time = 1.0);
00212 
00214             double getLastPlanComputationTime(void) const
00215             {
00216                 return planTime_;
00217             }
00218 
00222             virtual void clear(void);
00223 
00225             virtual void print(std::ostream &out = std::cout) const
00226             {
00227                 if (si_)
00228                     si_->printSettings(out);
00229                 if (pdef_)
00230                     pdef_->print(out);
00231             }
00232 
00236             virtual void setup(void);
00237 
00238         protected:
00239 
00241             SpaceInformationPtr           si_;
00242 
00244             base::ProblemDefinitionPtr    pdef_;
00245 
00247             base::PlannerPtr              planner_;
00248 
00250             base::PlannerAllocator        pa_;
00251 
00253             bool                          configured_;
00254 
00256             double                        planTime_;
00257 
00259             msg::Interface                msg_;
00260         };
00261 
00263         base::PlannerPtr getDefaultPlanner(const base::GoalPtr &goal);
00264     }
00265 
00266 }
00267 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator