44 static const rclcpp::Logger LOGGER = rclcpp::get_logger(
"moveit.ompl_planning.constrained_valid_state_sampler");
48 kinematic_constraints::KinematicConstraintSetPtr ks,
49 constraint_samplers::ConstraintSamplerPtr cs)
50 : ob::ValidStateSampler(pc->getOMPLSimpleSetup()->getSpaceInformation().get())
51 , planning_context_(pc)
52 , kinematic_constraint_set_(std::move(ks))
53 , constraint_sampler_(std::move(cs))
54 , work_state_(pc->getCompleteInitialRobotState())
56 if (!constraint_sampler_)
57 default_sampler_ = si_->allocStateSampler();
58 inv_dim_ = si_->getStateSpace()->getDimension() > 0 ? 1.0 / (double)si_->getStateSpace()->getDimension() : 1.0;
59 RCLCPP_DEBUG(LOGGER,
"Constructed a ValidConstrainedSampler instance at address %p",
this);
64 if (constraint_sampler_)
66 planning_context_->getOMPLStateSpace()->copyToRobotState(work_state_, state);
67 if (constraint_sampler_->project(work_state_, planning_context_->getMaximumStateSamplingAttempts()))
69 if (kinematic_constraint_set_->decide(work_state_).satisfied)
71 planning_context_->getOMPLStateSpace()->copyToOMPLState(state, work_state_);
81 if (constraint_sampler_)
83 if (constraint_sampler_->sample(work_state_, planning_context_->getCompleteInitialRobotState(),
84 planning_context_->getMaximumStateSamplingAttempts()))
86 if (kinematic_constraint_set_->decide(work_state_).satisfied)
88 planning_context_->getOMPLStateSpace()->copyToOMPLState(state, work_state_);
95 default_sampler_->sampleUniform(state);
96 planning_context_->getOMPLStateSpace()->copyToRobotState(work_state_, state);
97 if (kinematic_constraint_set_->decide(work_state_).satisfied)
109 double total_d = si_->distance(state, near);
112 double dist = pow(rng_.uniform01(), inv_dim_) *
distance;
113 si_->getStateSpace()->interpolate(near, state, dist / total_d, state);
114 planning_context_->getOMPLStateSpace()->copyToRobotState(work_state_, state);
115 if (!kinematic_constraint_set_->decide(work_state_).satisfied)
bool sample(ompl::base::State *state) override
virtual bool project(ompl::base::State *state)
ValidConstrainedSampler(const ModelBasedPlanningContext *pc, kinematic_constraints::KinematicConstraintSetPtr ks, constraint_samplers::ConstraintSamplerPtr cs=constraint_samplers::ConstraintSamplerPtr())
bool sampleNear(ompl::base::State *state, const ompl::base::State *near, const double distance) override
The MoveIt interface to OMPL.
double distance(const urdf::Pose &transform)