Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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