model_based_state_space.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2012, Willow Garage, Inc.
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 Willow Garage 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 MOVEIT_OMPL_INTERFACE_PARAMETERIZATION_MODEL_BASED_STATE_SPACE_
00038 #define MOVEIT_OMPL_INTERFACE_PARAMETERIZATION_MODEL_BASED_STATE_SPACE_
00039 
00040 #include <moveit/ompl_interface/parameterization/model_based_joint_state_space.h>
00041 #include <moveit/kinematic_constraints/kinematic_constraint.h>
00042 #include <moveit/constraint_samplers/constraint_sampler.h>
00043 
00044 namespace ompl_interface
00045 {
00046 
00047 typedef boost::function<bool(const ompl::base::State *from, const ompl::base::State *to, const double t, ompl::base::State *state)> InterpolationFunction;
00048 typedef boost::function<double(const ompl::base::State *state1, const ompl::base::State *state2)> DistanceFunction;
00049 
00050 struct ModelBasedStateSpaceSpecification
00051 {
00052   ModelBasedStateSpaceSpecification(const robot_model::RobotModelConstPtr &kmodel,
00053                                     const robot_model::JointModelGroup *jmg) :
00054     kmodel_(kmodel), joint_model_group_(jmg)
00055   {
00056   }
00057 
00058   ModelBasedStateSpaceSpecification(const robot_model::RobotModelConstPtr &kmodel,
00059                                     const std::string &group_name) :
00060     kmodel_(kmodel), joint_model_group_(kmodel_->getJointModelGroup(group_name))
00061   {
00062     if (!joint_model_group_)
00063       throw std::runtime_error("Group '" + group_name + "'  was not found");
00064   }
00065 
00066   robot_model::RobotModelConstPtr kmodel_;
00067   const robot_model::JointModelGroup *joint_model_group_;
00068   std::vector<robot_model::JointModel::Bounds> joints_bounds_;
00069 };
00070 
00071 class ModelBasedStateSpace : public ompl::base::CompoundStateSpace
00072 {
00073 public:
00074 
00075   class StateType : public ompl::base::CompoundState
00076   {
00077   public:
00078 
00079     enum
00080       {
00081         VALIDITY_KNOWN = 1,
00082         GOAL_DISTANCE_KNOWN = 2,
00083         VALIDITY_TRUE = 4,
00084         IS_START_STATE = 8,
00085         IS_GOAL_STATE = 16
00086       };
00087 
00088     StateType() : ompl::base::CompoundState(), tag(-1), flags(0), distance(0.0)
00089     {
00090     }
00091 
00092     void markValid(double d)
00093     {
00094       distance = d;
00095       flags |= GOAL_DISTANCE_KNOWN;
00096       markValid();
00097     }
00098 
00099     void markValid()
00100     {
00101       flags |= (VALIDITY_KNOWN | VALIDITY_TRUE);
00102     }
00103 
00104     void markInvalid(double d)
00105     {
00106       distance = d;
00107       flags |= GOAL_DISTANCE_KNOWN;
00108       markInvalid();
00109     }
00110 
00111     void markInvalid()
00112     {
00113       flags &= ~VALIDITY_TRUE;
00114       flags |= VALIDITY_KNOWN;
00115     }
00116 
00117     bool isValidityKnown() const
00118     {
00119       return flags & VALIDITY_KNOWN;
00120     }
00121 
00122     void clearKnownInformation()
00123     {
00124       flags = 0;
00125     }
00126 
00127     bool isMarkedValid() const
00128     {
00129       return flags & VALIDITY_TRUE;
00130     }
00131 
00132     bool isGoalDistanceKnown() const
00133     {
00134       return flags & GOAL_DISTANCE_KNOWN;
00135     }
00136 
00137     bool isStartState() const
00138     {
00139       return flags & IS_START_STATE;
00140     }
00141 
00142     bool isGoalState() const
00143     {
00144       return flags & IS_GOAL_STATE;
00145     }
00146 
00147     bool isInputState() const
00148     {
00149       return flags & (IS_START_STATE | IS_GOAL_STATE);
00150     }
00151 
00152     void markStartState()
00153     {
00154       flags |= IS_START_STATE;
00155     }
00156 
00157     void markGoalState()
00158     {
00159       flags |= IS_GOAL_STATE;
00160     }
00161 
00162     int tag;
00163     int flags;
00164     double distance;
00165   };
00166 
00167   ModelBasedStateSpace(const ModelBasedStateSpaceSpecification &spec);
00168   virtual ~ModelBasedStateSpace();
00169 
00170   void setInterpolationFunction(const InterpolationFunction &fun)
00171   {
00172     interpolation_function_ = fun;
00173   }
00174 
00175   void setDistanceFunction(const DistanceFunction &fun)
00176   {
00177     distance_function_ = fun;
00178   }
00179 
00180   virtual ompl::base::State* allocState() const;
00181   virtual void freeState(ompl::base::State *state) const;
00182   virtual void copyState(ompl::base::State *destination, const ompl::base::State *source) const;
00183   virtual void interpolate(const ompl::base::State *from, const ompl::base::State *to, const double t, ompl::base::State *state) const;
00184   virtual double distance(const ompl::base::State *state1, const ompl::base::State *state2) const;
00185   virtual double getMaximumExtent() const;
00186 
00187   virtual unsigned int getSerializationLength() const;
00188   virtual void serialize(void *serialization, const ompl::base::State *state) const;
00189   virtual void deserialize(ompl::base::State *state, const void *serialization) const;
00190 
00191   virtual ompl::base::StateSamplerPtr allocStateSampler() const;
00192   virtual ompl::base::StateSamplerPtr allocSubspaceStateSampler(const ompl::base::StateSpace *subspace) const;
00193 
00194   const robot_model::RobotModelConstPtr& getRobotModel() const
00195   {
00196     return spec_.kmodel_;
00197   }
00198 
00199   const robot_model::JointModelGroup* getJointModelGroup() const
00200   {
00201     return spec_.joint_model_group_;
00202   }
00203 
00204   const std::string& getJointModelGroupName() const
00205   {
00206     return getJointModelGroup()->getName();
00207   }
00208 
00209   const ModelBasedStateSpaceSpecification& getSpecification() const
00210   {
00211     return spec_;
00212   }
00213 
00214   virtual void printState(const ompl::base::State *state, std::ostream &out) const;
00215 
00217   virtual void setPlanningVolume(double minX, double maxX, double minY, double maxY, double minZ, double maxZ);
00218 
00219   const std::vector<robot_model::JointModel::Bounds>& getJointsBounds() const
00220   {
00221     return spec_.joints_bounds_;
00222   }
00223 
00225   virtual void copyToRobotState(robot_state::JointStateGroup* jsg, const ompl::base::State *state) const;
00226 
00228   void copyToRobotState(robot_state::RobotState &kstate, const ompl::base::State *state) const
00229   {
00230     copyToRobotState(kstate.getJointStateGroup(getJointModelGroupName()), state);
00231   }
00232 
00234   //  virtual void copyToOMPLState(ob::State *state, const std::vector<double> &values) const = 0;
00235 
00237   void copyToOMPLState(ompl::base::State *state, const robot_state::RobotState &kstate) const
00238   {
00239     copyToOMPLState(state, kstate.getJointStateGroup(getJointModelGroupName()));
00240   }
00241 
00243   virtual void copyToOMPLState(ompl::base::State *state, const robot_state::JointStateGroup* jsg) const;
00244 
00245   double getTagSnapToSegment() const;
00246   void setTagSnapToSegment(double snap);
00247 
00248 protected:
00249   friend class WrappedStateSampler;
00250 
00251   virtual void afterStateSample(ompl::base::State *sample) const;
00252 
00253   ModelBasedStateSpaceSpecification spec_;
00254   unsigned int jointSubspaceCount_;
00255 
00256   InterpolationFunction interpolation_function_;
00257   DistanceFunction distance_function_;
00258 
00259   double tag_snap_to_segment_;
00260   double tag_snap_to_segment_complement_;
00261 
00262 };
00263 
00264 typedef boost::shared_ptr<ModelBasedStateSpace> ModelBasedStateSpacePtr;
00265 
00266 }
00267 
00268 #endif


ompl
Author(s): Ioan Sucan
autogenerated on Mon Oct 6 2014 11:12:03