ompl/base/spaces/ReedsSheppStateSpace.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: Mark Moll */ 00036 00037 #ifndef OMPL_BASE_SPACES_REEDS_SHEPP_STATE_SPACE_ 00038 #define OMPL_BASE_SPACES_REEDS_SHEPP_STATE_SPACE_ 00039 00040 #include "ompl/base/spaces/SE2StateSpace.h" 00041 #include "ompl/base/MotionValidator.h" 00042 #include <boost/math/constants/constants.hpp> 00043 00044 namespace ompl 00045 { 00046 namespace base 00047 { 00048 00064 class ReedsSheppStateSpace : public SE2StateSpace 00065 { 00066 public: 00067 00069 enum ReedsSheppPathSegmentType { RS_NOP=0, RS_LEFT=1, RS_STRAIGHT=2, RS_RIGHT=3 }; 00071 static const ReedsSheppPathSegmentType reedsSheppPathType[18][5]; 00073 class ReedsSheppPath 00074 { 00075 public: 00076 ReedsSheppPath(const ReedsSheppPathSegmentType* type=reedsSheppPathType[0], 00077 double t=std::numeric_limits<double>::max(), double u=0., double v=0., 00078 double w=0., double x=0.); 00079 double length() const { return totalLength_; } 00080 00082 const ReedsSheppPathSegmentType* type_; 00084 double length_[5]; 00086 double totalLength_; 00087 }; 00088 00089 ReedsSheppStateSpace(double turningRadius = 1.0) 00090 : SE2StateSpace(), rho_(turningRadius) 00091 { 00092 } 00093 00094 virtual double distance(const State *state1, const State *state2) const; 00095 00096 virtual void interpolate(const State *from, const State *to, const double t, 00097 State *state) const; 00098 virtual void interpolate(const State *from, const State *to, const double t, 00099 bool &firstTime, ReedsSheppPath &path, State *state) const; 00100 00101 virtual void sanityChecks() const 00102 { 00103 double zero = std::numeric_limits<double>::epsilon(); 00104 double eps = .1; // rarely such a large error will occur 00105 StateSpace::sanityChecks(zero, eps, ~STATESPACE_INTERPOLATION); 00106 } 00107 00109 ReedsSheppPath reedsShepp(const State *state1, const State *state2) const; 00110 00111 protected: 00112 virtual void interpolate(const State *from, const ReedsSheppPath &path, const double t, 00113 State *state) const; 00114 00116 double rho_; 00117 }; 00118 00125 class ReedsSheppMotionValidator : public MotionValidator 00126 { 00127 public: 00128 ReedsSheppMotionValidator(SpaceInformation *si) : MotionValidator(si) 00129 { 00130 defaultSettings(); 00131 } 00132 ReedsSheppMotionValidator(const SpaceInformationPtr &si) : MotionValidator(si) 00133 { 00134 defaultSettings(); 00135 } 00136 virtual ~ReedsSheppMotionValidator() 00137 { 00138 } 00139 virtual bool checkMotion(const State *s1, const State *s2) const; 00140 virtual bool checkMotion(const State *s1, const State *s2, std::pair<State*, double> &lastValid) const; 00141 private: 00142 ReedsSheppStateSpace *stateSpace_; 00143 void defaultSettings(); 00144 }; 00145 00146 } 00147 } 00148 00149 #endif