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 #include <moveit/ompl_interface/parameterization/model_based_joint_state_space.h>
00038
00039 ompl_interface::ModelBasedJointStateSpace::ModelBasedJointStateSpace(const robot_model::JointModel *joint_model,
00040 const robot_model::JointModel::Bounds &joint_bounds) :
00041 ompl::base::StateSpace(), joint_model_(joint_model), joint_bounds_(joint_bounds)
00042 {
00043
00044 setName(joint_model_->getName());
00045
00046 if (joint_bounds_.size() != joint_model_->getVariableBounds().size())
00047 {
00048 logError("Joint '%s' from group has incorrect bounds specified. Using the default bounds instead.", joint_model_->getName().c_str());
00049 joint_bounds_ = joint_model_->getVariableBounds();
00050 }
00051 }
00052
00053 ompl_interface::ModelBasedJointStateSpace::ModelBasedJointStateSpace(const robot_model::JointModel *joint_model) :
00054 ompl::base::StateSpace(), joint_model_(joint_model)
00055 {
00056
00057 setName(joint_model_->getName());
00058 joint_bounds_ = joint_model_->getVariableBounds();
00059 }
00060
00061 ompl_interface::ModelBasedJointStateSpace::~ModelBasedJointStateSpace()
00062 {
00063 }
00064
00065 ompl::base::State* ompl_interface::ModelBasedJointStateSpace::allocState() const
00066 {
00067 StateType *st = new StateType();
00068 st->joint_state = new robot_state::JointState(joint_model_);
00069 return st;
00070 }
00071
00072 void ompl_interface::ModelBasedJointStateSpace::freeState(ompl::base::State *state) const
00073 {
00074 delete state->as<StateType>()->joint_state;
00075 delete state->as<StateType>();
00076 }
00077
00078 unsigned int ompl_interface::ModelBasedJointStateSpace::getDimension() const
00079 {
00080 return joint_model_->getStateSpaceDimension();
00081 }
00082
00083 double ompl_interface::ModelBasedJointStateSpace::getMaximumExtent() const
00084 {
00085 return joint_model_->getMaximumExtent(joint_bounds_);
00086 }
00087
00088 void ompl_interface::ModelBasedJointStateSpace::enforceBounds(ompl::base::State *state) const
00089 {
00090 joint_model_->enforceBounds(state->as<StateType>()->joint_state->getVariableValues(), joint_bounds_);
00091 }
00092
00093 bool ompl_interface::ModelBasedJointStateSpace::satisfiesBounds(const ompl::base::State *state) const
00094 {
00095 return joint_model_->satisfiesBounds(state->as<StateType>()->joint_state->getVariableValues(), joint_bounds_, std::numeric_limits<double>::epsilon());
00096 }
00097
00098 void ompl_interface::ModelBasedJointStateSpace::copyState(ompl::base::State *destination, const ompl::base::State *source) const
00099 {
00100 *destination->as<StateType>()->joint_state = *source->as<StateType>()->joint_state;
00101 }
00102
00103 double ompl_interface::ModelBasedJointStateSpace::distance(const ompl::base::State *state1, const ompl::base::State *state2) const
00104 {
00105 return state1->as<StateType>()->joint_state->distance(state2->as<StateType>()->joint_state);
00106 }
00107
00108 bool ompl_interface::ModelBasedJointStateSpace::equalStates(const ompl::base::State *state1, const ompl::base::State *state2) const
00109 {
00110 return state1->as<StateType>()->joint_state->getVariableValues() == state2->as<StateType>()->joint_state->getVariableValues();
00111 }
00112
00113 void ompl_interface::ModelBasedJointStateSpace::interpolate(const ompl::base::State *from, const ompl::base::State *to, const double t, ompl::base::State *state) const
00114 {
00115 from->as<StateType>()->joint_state->interpolate(to->as<StateType>()->joint_state, t, state->as<StateType>()->joint_state);
00116 propagateJointStateUpdate(state);
00117 }
00118
00119 unsigned int ompl_interface::ModelBasedJointStateSpace::getSerializationLength() const
00120 {
00121 return sizeof(double) * joint_model_->getVariableCount();
00122 }
00123
00124 void ompl_interface::ModelBasedJointStateSpace::serialize(void *serialization, const ompl::base::State *state) const
00125 {
00126 memcpy(serialization, &state->as<StateType>()->joint_state->getVariableValues()[0], joint_model_->getVariableCount() * sizeof(double));
00127 }
00128
00129 void ompl_interface::ModelBasedJointStateSpace::deserialize(ompl::base::State *state, const void *serialization) const
00130 {
00131 memcpy(&state->as<StateType>()->joint_state->getVariableValues()[0], serialization, joint_model_->getVariableCount() * sizeof(double));
00132 propagateJointStateUpdate(state);
00133 }
00134
00135 void ompl_interface::ModelBasedJointStateSpace::setPlanningVolume(double minX, double maxX, double minY, double maxY, double minZ, double maxZ)
00136 {
00137 if (joint_model_->getType() == robot_model::JointModel::PLANAR)
00138 {
00139 joint_bounds_[0].first = minX;
00140 joint_bounds_[0].second = maxX;
00141 joint_bounds_[1].first = minY;
00142 joint_bounds_[1].second = maxY;
00143 }
00144 else
00145 if (joint_model_->getType() == robot_model::JointModel::FLOATING)
00146 {
00147 joint_bounds_[0].first = minX;
00148 joint_bounds_[0].second = maxX;
00149 joint_bounds_[1].first = minY;
00150 joint_bounds_[1].second = maxY;
00151 joint_bounds_[2].first = minZ;
00152 joint_bounds_[2].second = maxZ;
00153 }
00154 }
00155
00156 double* ompl_interface::ModelBasedJointStateSpace::getValueAddressAtIndex(ompl::base::State *state, const unsigned int index) const
00157 {
00158 if (index >= joint_model_->getVariableCount())
00159 return NULL;
00160 return &state->as<StateType>()->joint_state->getVariableValues()[index];
00161 }
00162
00163 void ompl_interface::ModelBasedJointStateSpace::printState(const ompl::base::State *state, std::ostream &out) const
00164 {
00165 out << "JointState(" << joint_model_->getName() << ") = [ ";
00166 for (std::size_t j = 0 ; j < state->as<StateType>()->joint_state->getVariableValues().size() ; ++j)
00167 out << state->as<StateType>()->joint_state->getVariableValues()[j] << " ";
00168 out << "]" << std::endl;
00169 }
00170
00171 void ompl_interface::ModelBasedJointStateSpace::printSettings(std::ostream &out) const
00172 {
00173 out << "ModelBasedJointStateSpace '" << getName() << "' at " << this << std::endl;
00174 }
00175
00176 void ompl_interface::ModelBasedJointStateSpace::propagateJointStateUpdate(ompl::base::State *state) const
00177 {
00178
00179 joint_model_->updateTransform(state->as<StateType>()->joint_state->getVariableValues(), state->as<StateType>()->joint_state->getVariableTransform());
00180
00181
00182 state->as<StateType>()->joint_state->updateMimicJoints();
00183 }
00184
00185 ompl::base::StateSamplerPtr ompl_interface::ModelBasedJointStateSpace::allocDefaultStateSampler() const
00186 {
00187 class DefaultStateSampler : public ompl::base::StateSampler
00188 {
00189 public:
00190
00191 DefaultStateSampler(const ompl::base::StateSpace *space) : ompl::base::StateSampler(space),
00192 values_(space->as<ModelBasedJointStateSpace>()->getJointModel()->getVariableCount())
00193 {
00194 }
00195
00196 virtual void sampleUniform(ompl::base::State *state)
00197 {
00198 std::vector<double> &values = state->as<ModelBasedJointStateSpace::StateType>()->joint_state->getVariableValues();
00199 values.clear();
00200
00201
00202 space_->as<ModelBasedJointStateSpace>()->getJointModel()->getVariableRandomValues(moveit_rng_, values, space_->as<ModelBasedJointStateSpace>()->getJointBounds());
00203
00204
00205 space_->as<ModelBasedJointStateSpace>()->propagateJointStateUpdate(state);
00206 }
00207
00208 virtual void sampleUniformNear(ompl::base::State *state, const ompl::base::State *near, const double distance)
00209 {
00210 std::vector<double> &values = state->as<ModelBasedJointStateSpace::StateType>()->joint_state->getVariableValues();
00211 values.clear();
00212
00213
00214 space_->as<ModelBasedJointStateSpace>()->getJointModel()->getVariableRandomValuesNearBy(moveit_rng_, values, space_->as<ModelBasedJointStateSpace>()->getJointBounds(),
00215 near->as<ModelBasedJointStateSpace::StateType>()->joint_state->getVariableValues(),
00216 distance);
00217
00218 space_->as<ModelBasedJointStateSpace>()->propagateJointStateUpdate(state);
00219 }
00220
00221 virtual void sampleGaussian(ompl::base::State *state, const ompl::base::State *mean, const double stdDev)
00222 {
00223 sampleUniformNear(state, mean, rng_.gaussian(0.0, stdDev));
00224 }
00225
00226 protected:
00227 std::vector<double> values_;
00228 random_numbers::RandomNumberGenerator moveit_rng_;
00229 };
00230
00231 return ompl::base::StateSamplerPtr(static_cast<ompl::base::StateSampler*>(new DefaultStateSampler(this)));
00232 }