37 #include "ompl/geometric/planners/stride/STRIDE.h"
40 #include "ompl/datastructures/NearestNeighborsGNAT.h"
41 #include "ompl/base/goals/GoalSampleableRegion.h"
42 #include "ompl/tools/config/SelfConfig.h"
47 bool useProjectedDistance,
48 unsigned int degree,
unsigned int minDegree,
49 unsigned int maxDegree,
unsigned int maxNumPtsPerLeaf,
double estimatedDimension)
50 : base::Planner(si,
"STRIDE"), goalBias_(0.05), maxDistance_(0.),
51 useProjectedDistance_(useProjectedDistance),
52 degree_(degree), minDegree_(minDegree), maxDegree_(maxDegree),
53 maxNumPtsPerLeaf_(maxNumPtsPerLeaf), estimatedDimension_(estimatedDimension),
54 minValidPathFraction_(0.2)
72 ompl::geometric::STRIDE::~STRIDE(
void)
89 if (useProjectedDistance_)
107 std::vector<Motion*> motions;
108 tree_->list(motions);
109 for (std::size_t i = 0 ; i < motions.size() ; ++i)
111 if (motions[i]->state)
112 si_->freeState(motions[i]->state);
128 si_->copyState(motion->
state, st);
132 if (tree_->size() == 0)
134 OMPL_ERROR(
"%s: There are no valid initial states!", getName().c_str());
139 sampler_ = si_->allocValidStateSampler();
141 OMPL_INFORM(
"%s: Starting with %u states", getName().c_str(), tree_->size());
145 double approxdif = std::numeric_limits<double>::infinity();
151 Motion *existing = selectMotion();
155 if (goal_s && rng_.uniform01() < goalBias_ && goal_s->
canSample())
158 if (!sampler_->sampleNear(xstate, existing->
state, maxDistance_))
161 std::pair<base::State*, double> fail(xstate, 0.0);
162 bool keep = si_->checkMotion(existing->
state, xstate, fail) || fail.second > minValidPathFraction_;
168 si_->copyState(motion->
state, xstate);
169 motion->
parent = existing;
180 if (dist < approxdif)
189 bool approximate =
false;
190 if (solution == NULL)
192 solution = approxsol;
196 if (solution != NULL)
199 std::vector<Motion*> mpath;
200 while (solution != NULL)
202 mpath.push_back(solution);
203 solution = solution->parent;
208 for (
int i = mpath.size() - 1 ; i >= 0 ; --i)
209 path->
append(mpath[i]->state);
210 pdef_->addSolutionPath(
base::PathPtr(path), approximate, approxdif);
214 si_->freeState(xstate);
216 OMPL_INFORM(
"%s: Created %u states", getName().c_str(), tree_->size());
228 return tree_->sample(rng_);
233 Planner::getPlannerData(data);
235 std::vector<Motion*> motions;
236 tree_->list(motions);
237 for (std::vector<Motion*>::iterator it=motions.begin(); it!=motions.end(); it++)
239 if((*it)->parent == NULL)
bool approximateSolutions
Flag indicating whether the planner is able to compute approximate solutions.
bool canSample(void) const
Return true if maxSampleCount() > 0, since in this case samples can certainly be produced.
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
bool getUseProjectedDistance(void) const
Return whether nearest neighbors are computed based on distances in a projection of the state rather ...
Motion * parent
The parent motion in the exploration tree.
The definition of a motion.
double estimatedDimension_
Estimate of the local dimensionality of the free space around a state.
void setMinDegree(unsigned int minDegree)
Set minimum degree of a node in the GNAT.
void setEstimatedDimension(double estimatedDimension)
Set estimated dimension of the free space, which is needed to compute the sampling weight for a node ...
Abstract definition of goals.
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Geometric Near-neighbor Access Tree (GNAT), a data structure for nearest neighbor search...
unsigned int getDegree(void) const
Get desired degree of a node in the GNAT.
unsigned int getMaxNumPtsPerLeaf(void) const
Get maximum number of elements stored in a leaf node of the GNAT.
void append(const base::State *state)
Append state to the end of this path. The memory for state is copied.
virtual void setup(void)
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
virtual void sampleGoal(State *st) const =0
Sample a state in the goal region.
Base class for a vertex in the PlannerData structure. All derived classes must implement the clone an...
Invalid start state or no start state specified.
Abstract definition of a goal region that can be sampled.
unsigned int getMinDegree(void) const
Get minimum degree of a node in the GNAT.
void setDegree(unsigned int degree)
Set desired degree of a node in the GNAT.
void setMaxNumPtsPerLeaf(unsigned int maxNumPtsPerLeaf)
Set maximum number of elements stored in a leaf node of the GNAT.
#define OMPL_ERROR(fmt,...)
Log a formatted error string.
A class to store the exit status of Planner::solve()
virtual bool addEdge(unsigned int v1, unsigned int v2, const PlannerDataEdge &edge=PlannerDataEdge(), Cost weight=Cost(1.0))
Adds a directed edge between the given vertex indexes. An optional edge structure and weight can be s...
unsigned int addStartVertex(const PlannerDataVertex &v)
Adds the given vertex to the graph data, and marks it as a start vertex. The vertex index is returned...
Definition of an abstract state.
void setRange(double distance)
Set the range the planner is supposed to use.
double getMinValidPathFraction(void) const
Get the value of the fraction set by setMinValidPathFraction()
virtual bool isSatisfied(const State *st) const =0
Return true if the state satisfies the goal constraints.
PlannerSpecs specs_
The specifications of the planner (its capabilities)
STRIDE(const base::SpaceInformationPtr &si, bool useProjectedDistance=false, unsigned int degree=16, unsigned int minDegree=12, unsigned int maxDegree=18, unsigned int maxNumPtsPerLeaf=6, double estimatedDimension=0.0)
Constructor.
virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc)
Function that can solve the motion planning problem. This function can be called multiple times on th...
double projectedDistanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between projections of contained states) ...
Motion * selectMotion(void)
Select a motion to continue the expansion of the tree from.
virtual void clear(void)
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
unsigned int getMaxDegree(void) const
Set maximum degree of a node in the GNAT.
void setupTree(void)
Initialize GNAT data structure.
Definition of a geometric path.
void freeMemory(void)
Free the memory allocated by this planner.
void setMinValidPathFraction(double fraction)
When extending a motion, the planner can decide to keep the first valid part of it, even if invalid states are found, as long as the valid part represents a sufficiently large fraction from the original motion. This function sets the minimum acceptable fraction (between 0 and 1).
double getGoalBias(void) const
Get the goal bias the planner is using.
double getRange(void) const
Get the range the planner is using.
base::State * state
The state contained by the motion.
double getEstimatedDimension(void) const
Get estimated dimension of the free space, which is needed to compute the sampling weight for a node ...
virtual void getPlannerData(base::PlannerData &data) const
Get information about the current run of the motion planner. Repeated calls to this function will upd...
void setUseProjectedDistance(bool useProjectedDistance)
Set whether nearest neighbors are computed based on distances in a projection of the state rather dis...
void setMaxDegree(unsigned int maxDegree)
Set maximum degree of a node in the GNAT.
void setGoalBias(double goalBias)
In the process of randomly selecting states in the state space to attempt to go towards, the algorithm may in fact choose the actual goal state, if it knows it, with some probability. This probability is a real number between 0.0 and 1.0; its value should usually be around 0.05 and should not be too large. It is probably a good idea to use the default value.
void addMotion(Motion *motion)
Add a motion to the exploration tree.
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
A boost shared pointer wrapper for ompl::base::Path.
#define OMPL_INFORM(fmt,...)
Log a formatted information string.