ompl/extensions/opende/OpenDEStateSpace.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_EXTENSION_OPENDE_STATE_SPACE_ 00038 #define OMPL_EXTENSION_OPENDE_STATE_SPACE_ 00039 00040 #include "ompl/base/StateSpace.h" 00041 #include "ompl/base/spaces/RealVectorStateSpace.h" 00042 #include "ompl/base/spaces/SO3StateSpace.h" 00043 #include "ompl/extensions/opende/OpenDEEnvironment.h" 00044 00045 namespace ompl 00046 { 00047 namespace control 00048 { 00049 00051 class OpenDEStateSpace : public base::CompoundStateSpace 00052 { 00053 public: 00054 00055 enum 00056 { 00058 STATE_COLLISION_KNOWN_BIT = 0, 00060 STATE_COLLISION_VALUE_BIT = 1, 00062 STATE_VALIDITY_KNOWN_BIT = 2, 00064 STATE_VALIDITY_VALUE_BIT = 3, 00065 }; 00066 00068 class StateType : public base::CompoundStateSpace::StateType 00069 { 00070 public: 00071 StateType() : base::CompoundStateSpace::StateType(), collision(0) 00072 { 00073 } 00074 00076 const double* getBodyPosition(unsigned int body) const 00077 { 00078 return as<base::RealVectorStateSpace::StateType>(body * 4)->values; 00079 } 00080 00082 double* getBodyPosition(unsigned int body) 00083 { 00084 return as<base::RealVectorStateSpace::StateType>(body * 4)->values; 00085 } 00086 00088 const base::SO3StateSpace::StateType& getBodyRotation(unsigned int body) const 00089 { 00090 return *as<base::SO3StateSpace::StateType>(body * 4 + 3); 00091 } 00092 00094 base::SO3StateSpace::StateType& getBodyRotation(unsigned int body) 00095 { 00096 return *as<base::SO3StateSpace::StateType>(body * 4 + 3); 00097 } 00098 00100 const double* getBodyLinearVelocity(unsigned int body) const 00101 { 00102 return as<base::RealVectorStateSpace::StateType>(body * 4 + 1)->values; 00103 } 00104 00106 double* getBodyLinearVelocity(unsigned int body) 00107 { 00108 return as<base::RealVectorStateSpace::StateType>(body * 4 + 1)->values; 00109 } 00110 00112 const double* getBodyAngularVelocity(unsigned int body) const 00113 { 00114 return as<base::RealVectorStateSpace::StateType>(body * 4 + 2)->values; 00115 } 00116 00118 double* getBodyAngularVelocity(unsigned int body) 00119 { 00120 return as<base::RealVectorStateSpace::StateType>(body * 4 + 2)->values; 00121 } 00122 00129 mutable int collision; 00130 00131 }; 00132 00148 OpenDEStateSpace(const OpenDEEnvironmentPtr &env, 00149 double positionWeight = 1.0, double linVelWeight = 0.5, 00150 double angVelWeight = 0.5, double orientationWeight = 1.0); 00151 00152 virtual ~OpenDEStateSpace() 00153 { 00154 } 00155 00157 const OpenDEEnvironmentPtr& getEnvironment() const 00158 { 00159 return env_; 00160 } 00161 00163 unsigned int getNrBodies() const 00164 { 00165 return env_->stateBodies_.size(); 00166 } 00167 00173 void setDefaultBounds(); 00174 00176 void setVolumeBounds(const base::RealVectorBounds &bounds); 00177 00179 void setLinearVelocityBounds(const base::RealVectorBounds &bounds); 00180 00182 void setAngularVelocityBounds(const base::RealVectorBounds &bounds); 00183 00186 virtual void readState(base::State *state) const; 00187 00192 virtual void writeState(const base::State *state) const; 00193 00201 bool satisfiesBoundsExceptRotation(const StateType *state) const; 00202 00203 virtual base::State* allocState() const; 00204 virtual void freeState(base::State *state) const; 00205 virtual void copyState(base::State *destination, const base::State *source) const; 00206 virtual void interpolate(const base::State *from, const base::State *to, const double t, base::State *state) const; 00207 00208 virtual base::StateSamplerPtr allocDefaultStateSampler() const; 00209 virtual base::StateSamplerPtr allocStateSampler() const; 00210 00213 virtual bool evaluateCollision(const base::State *source) const; 00214 00215 protected: 00216 00218 OpenDEEnvironmentPtr env_; 00219 }; 00220 } 00221 } 00222 00223 00224 #endif