what(): There are no goals to sample error
Original report by Anonymous.
I am getting the error: what(): There are no goals to sample
when I try to run a modified rrt with the following code: (I am sampling two states instead of one and choosing the state closer to the goal to consider to grow the tree)
OMPL_INFORM("%s: Starting RRT planning with %u states already in datastructure", getName().c_str(), nn_->size());
Motion *solution = nullptr;
Motion *approxsol = nullptr;
double approxdif = std::numeric_limits<double>::infinity();
Motion *rmotion = new Motion(si_);
base::State *rstate = rmotion->state;
base::State *rstate1 = rmotion->state; //Added code
base::State *rstate2 = rmotion->state;//Added code
base::State *mygoal = rmotion->state;//Added code
base::State *xstate = si_->allocState();
/* find closest state in the tree */
Motion *nmotion = nn_->nearest(rmotion); //Added code
base::State *dstate = rstate;//Added code
goal_s->sampleGoal(mygoal);//Added code
double d = si_->distance(mygoal, rstate);//Added code
double d1 = si_->distance(mygoal, rstate1);//Added code
double d2 = si_->distance(mygoal, rstate2);//Added code
while (ptc == false)
{
/* sample random state (with goal biasing) */
if (goal_s && rng_.uniform01() < goalBias_ && goal_s->canSample())
goal_s->sampleGoal(rstate);
else
{
sampler_->sampleUniform(rstate1);//Added code
sampler_->sampleUniform(rstate2);//Added code
d1 = si_->distance(mygoal, rstate1);//Added code
d2 = si_->distance(mygoal, rstate2);//Added code
if (d1 < d2) //Added code
rstate = rstate1; //Added code
else //Added code
rstate = rstate2; //Added code
} //Added code
/* find closest state in the tree */
Motion *nmotion = nn_->nearest(rmotion);
base::State *dstate = rstate;
/* find state to add */
d = si_->distance(nmotion->state, rstate);
if (d > maxDistance_)
{
si_->getStateSpace()->interpolate(nmotion->state, rstate, maxDistance_ / d, xstate);
dstate = xstate;
Original comment by Mark Moll (Bitbucket: mamoll, GitHub: mamoll).
rstate1 and rstate2 point to the same memory location. I don't think this code does what you think it does.
Original comment by David Boon (Bitbucket: boonflies, GitHub: boonflies).
Mark, I updated the code a bit and the error got resolved. But does it serve what I am trying to do?
As I need two states before choosing one, I am using the lines, base::State *rstate1 = rmotion->state; //Added code base::State *rstate2 = rmotion->state;//Added code
to initialize the two states from which I will choose one.
And in the lines within the else, I am updating the two states with unique values. sampler_->sampleUniform(rstate1);//Added code sampler_->sampleUniform(rstate2);//Added code
start of code* OMPL_INFORM("%s: Starting RRT planning with %u states already in datastructure", getName().c_str(), nn_->size());
Motion *solution = nullptr;
Motion *approxsol = nullptr;
double approxdif = std::numeric_limits<double>::infinity();
Motion *rmotion = new Motion(si_);
base::State *rstate = rmotion->state;
base::State *rstate1 = rmotion->state; //Added code - just to initialize state1
base::State *rstate2 = rmotion->state; //Added code - just to initialize state2
base::State *xstate = si_->allocState();
while (ptc == false)
{
/* sample random state (with goal biasing) */
if (goal_s && rng_.uniform01() < goalBias_ && goal_s->canSample())
goal_s->sampleGoal(rstate);
else
{
sampler_->sampleUniform(rstate1); //Added code - updating state1 with unique state
sampler_->sampleUniform(rstate2);//Added code - updating state2 with unique state
double d1 = 0.0; //Added code
double d2 = 0.0; //Added code
bool sat1 = goal->isSatisfied(rstate1, &d1); //Added code - compute dist. of state1 to goal
bool sat2 = goal->isSatisfied(rstate2, &d2); //Added code - compute dist. of state2 to goal
if (d1 < d2) //Added code
rstate = rstate1; //Added code - set state1 as the state to consider for further processing
else // Added code
rstate = rstate2; //Added code - set state2 as the state to consider for further processing
}
/* find closest state in the tree */
Motion *nmotion = nn_->nearest(rmotion);
base::State *dstate = rstate;
/* find state to add */
double d = si_->distance(nmotion->state, rstate);
Does it seem right?
Original comment by Mark Moll (Bitbucket: mamoll, GitHub: mamoll).
use si_->allocState() to allocate different memory for rstate1 and rstate2.
Original comment by David Boon (Bitbucket: boonflies, GitHub: boonflies).
Thanks Mark, I updated the code to allocate different memory for the two states. base::State rstate1 = si_->allocState(); //Added code base::State rstate2 = si_->allocState(); //Added code
Does the code, now satisfy the approach of choosing one out of the two states that is closer to the goal?