ompl/control/SpaceInformation.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_SPACE_INFORMATION_ 00038 #define OMPL_CONTROL_SPACE_INFORMATION_ 00039 00040 #include "ompl/base/SpaceInformation.h" 00041 #include "ompl/control/ControlSpace.h" 00042 #include "ompl/control/ControlSampler.h" 00043 #include "ompl/control/DirectedControlSampler.h" 00044 #include "ompl/control/StatePropagator.h" 00045 #include "ompl/control/Control.h" 00046 #include "ompl/util/ClassForward.h" 00047 00048 namespace ompl 00049 { 00050 00053 namespace control 00054 { 00055 00057 00058 OMPL_CLASS_FORWARD(SpaceInformation); 00060 00066 typedef boost::function<void(const base::State*, const Control*, const double, base::State*)> StatePropagatorFn; 00067 00069 class SpaceInformation : public base::SpaceInformation 00070 { 00071 public: 00072 00074 SpaceInformation(const base::StateSpacePtr &stateSpace, const ControlSpacePtr &controlSpace) : 00075 base::SpaceInformation(stateSpace), controlSpace_(controlSpace), 00076 minSteps_(0), maxSteps_(0), stepSize_(0.0) 00077 { 00078 } 00079 00080 virtual ~SpaceInformation() 00081 { 00082 } 00083 00085 const ControlSpacePtr& getControlSpace() const 00086 { 00087 return controlSpace_; 00088 } 00089 00094 Control* allocControl() const 00095 { 00096 return controlSpace_->allocControl(); 00097 } 00098 00100 void freeControl(Control *control) const 00101 { 00102 controlSpace_->freeControl(control); 00103 } 00104 00106 void copyControl(Control *destination, const Control *source) const 00107 { 00108 controlSpace_->copyControl(destination, source); 00109 } 00110 00112 Control* cloneControl(const Control *source) const 00113 { 00114 Control *copy = controlSpace_->allocControl(); 00115 controlSpace_->copyControl(copy, source); 00116 return copy; 00117 } 00118 00125 void printControl(const Control *control, std::ostream &out = std::cout) const 00126 { 00127 controlSpace_->printControl(control, out); 00128 } 00129 00131 bool equalControls(const Control *control1, const Control *control2) const 00132 { 00133 return controlSpace_->equalControls(control1, control2); 00134 } 00135 00137 void nullControl(Control *control) const 00138 { 00139 controlSpace_->nullControl(control); 00140 } 00141 00148 ControlSamplerPtr allocControlSampler() const 00149 { 00150 return controlSpace_->allocControlSampler(); 00151 } 00152 00154 void setMinMaxControlDuration(unsigned int minSteps, unsigned int maxSteps) 00155 { 00156 minSteps_ = minSteps; 00157 maxSteps_ = maxSteps; 00158 } 00159 00161 unsigned int getMinControlDuration() const 00162 { 00163 return minSteps_; 00164 } 00165 00167 unsigned int getMaxControlDuration() const 00168 { 00169 return maxSteps_; 00170 } 00171 00174 DirectedControlSamplerPtr allocDirectedControlSampler() const; 00175 00177 void setDirectedControlSamplerAllocator(const DirectedControlSamplerAllocator &dcsa); 00178 00180 void clearDirectedSamplerAllocator(); 00181 00188 const StatePropagatorPtr& getStatePropagator() const 00189 { 00190 return statePropagator_; 00191 } 00192 00194 void setStatePropagator(const StatePropagatorFn &fn); 00195 00197 void setStatePropagator(const StatePropagatorPtr &sp); 00198 00201 void setPropagationStepSize(double stepSize) 00202 { 00203 stepSize_ = stepSize; 00204 } 00205 00207 double getPropagationStepSize() const 00208 { 00209 return stepSize_; 00210 } 00221 void propagate(const base::State *state, const Control *control, int steps, base::State *result) const; 00222 00227 bool canPropagateBackward() const; 00228 00236 unsigned int propagateWhileValid(const base::State *state, const Control *control, int steps, base::State *result) const; 00237 00246 void propagate(const base::State *state, const Control *control, int steps, std::vector<base::State*> &result, bool alloc) const; 00247 00260 unsigned int propagateWhileValid(const base::State *state, const Control *control, int steps, std::vector<base::State*> &result, bool alloc) const; 00261 00265 virtual void printSettings(std::ostream &out = std::cout) const; 00266 00268 virtual void setup(); 00269 00270 protected: 00271 00273 ControlSpacePtr controlSpace_; 00274 00276 StatePropagatorPtr statePropagator_; 00277 00279 unsigned int minSteps_; 00280 00282 unsigned int maxSteps_; 00283 00285 DirectedControlSamplerAllocator dcsa_; 00286 00288 double stepSize_; 00289 00290 }; 00291 00292 } 00293 00294 } 00295 00296 #endif