46 constexpr
char LOGNAME[] =
"constrained_goal_sampler";
50 kinematic_constraints::KinematicConstraintSetPtr ks,
51 constraint_samplers::ConstraintSamplerPtr cs)
52 : ob::GoalLazySamples(
53 pc->getOMPLSimpleSetup()->getSpaceInformation(),
54 [this](const GoalLazySamples* gls, ompl::base::State* state) {
58 , planning_context_(pc)
59 , kinematic_constraint_set_(std::move(ks))
60 , constraint_sampler_(std::move(cs))
61 , work_state_(pc->getCompleteInitialRobotState())
62 , invalid_sampled_constraints_(0)
63 , warned_invalid_samples_(
false)
66 if (!constraint_sampler_)
67 default_sampler_ = si_->allocStateSampler();
76 planning_context_->getOMPLStateSpace()->copyToOMPLState(new_goal, state);
83 const double* jpos,
bool verbose)
const
89 return checkStateValidity(new_goal, solution_state,
verbose);
97 unsigned int max_attempts = planning_context_->getMaximumGoalSamplingAttempts();
98 unsigned int attempts_so_far = gls->samplingAttemptsCount();
101 if (attempts_so_far >= max_attempts)
105 if (gls->getStateCount() >= planning_context_->getMaximumGoalSamples())
109 if (planning_context_->getOMPLSimpleSetup()->getProblemDefinition()->hasSolution())
112 unsigned int max_attempts_div2 = max_attempts / 2;
113 for (
unsigned int a = gls->samplingAttemptsCount(); a < max_attempts && gls->isSampling(); ++a)
116 if (gls->getStateCount() == 0 && a >= max_attempts_div2)
117 if (verbose_display_ < 1)
123 if (constraint_sampler_)
129 const double* joint_group_variable_values) {
130 return stateValidityCallback(new_goal, robot_state, joint_group, joint_group_variable_values,
verbose);
132 constraint_sampler_->setGroupStateValidityCallback(gsvcf);
134 if (constraint_sampler_->sample(work_state_, planning_context_->getMaximumStateSamplingAttempts()))
136 work_state_.update();
137 if (kinematic_constraint_set_->decide(work_state_,
verbose).satisfied)
139 if (checkStateValidity(new_goal, work_state_,
verbose))
144 invalid_sampled_constraints_++;
145 if (!warned_invalid_samples_ && invalid_sampled_constraints_ >= (attempts_so_far * 8) / 10)
147 warned_invalid_samples_ =
true;
149 "fail to satisfy the constraints imposed on the goal sampler. "
150 "Is the constrained sampler working correctly?");
157 default_sampler_->sampleUniform(new_goal);
160 planning_context_->getOMPLStateSpace()->copyToRobotState(work_state_, new_goal);
161 if (kinematic_constraint_set_->decide(work_state_,
verbose).satisfied)