37 #include "ompl/geometric/planners/rrt/RRT.h"
38 #include "ompl/base/goals/GoalSampleableRegion.h"
39 #include "ompl/tools/config/SelfConfig.h"
55 ompl::geometric::RRT::~RRT(
void)
67 lastGoalMotion_ = NULL;
77 nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Motion*>(si_->getStateSpace()));
85 std::vector<Motion*> motions;
87 for (
unsigned int i = 0 ; i < motions.size() ; ++i)
89 if (motions[i]->state)
90 si_->freeState(motions[i]->state);
105 si_->copyState(motion->
state, st);
109 if (nn_->size() == 0)
111 OMPL_ERROR(
"%s: There are no valid initial states!", getName().c_str());
116 sampler_ = si_->allocStateSampler();
118 OMPL_INFORM(
"%s: Starting with %u states", getName().c_str(), nn_->size());
122 double approxdif = std::numeric_limits<double>::infinity();
131 if (goal_s && rng_.uniform01() < goalBias_ && goal_s->
canSample())
134 sampler_->sampleUniform(rstate);
137 Motion *nmotion = nn_->nearest(rmotion);
141 double d = si_->distance(nmotion->
state, rstate);
142 if (d > maxDistance_)
144 si_->getStateSpace()->interpolate(nmotion->
state, rstate, maxDistance_ / d, xstate);
148 if (si_->checkMotion(nmotion->
state, dstate))
152 si_->copyState(motion->
state, dstate);
164 if (dist < approxdif)
173 bool approximate =
false;
174 if (solution == NULL)
176 solution = approxsol;
180 if (solution != NULL)
182 lastGoalMotion_ = solution;
185 std::vector<Motion*> mpath;
186 while (solution != NULL)
188 mpath.push_back(solution);
189 solution = solution->parent;
194 for (
int i = mpath.size() - 1 ; i >= 0 ; --i)
195 path->
append(mpath[i]->state);
196 pdef_->addSolutionPath(
base::PathPtr(path), approximate, approxdif);
200 si_->freeState(xstate);
202 si_->freeState(rmotion->
state);
205 OMPL_INFORM(
"%s: Created %u states", getName().c_str(), nn_->size());
212 Planner::getPlannerData(data);
214 std::vector<Motion*> motions;
221 for (
unsigned int i = 0 ; i < motions.size() ; ++i)
223 if (motions[i]->parent == NULL)
double maxDistance_
The maximum length of a motion to be added to a tree.
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.
double getGoalBias(void) const
Get the goal bias the planner is using.
void freeMemory(void)
Free the memory allocated by this planner.
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Motion * parent
The parent motion in the exploration tree.
void setRange(double distance)
Set the range the planner is supposed to use.
unsigned int addGoalVertex(const PlannerDataVertex &v)
Adds the given vertex to the graph data, and marks it as a start vertex. The vertex index is returned...
Abstract definition of goals.
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
void append(const base::State *state)
Append state to the end of this path. The memory for state is copied.
virtual void getPlannerData(base::PlannerData &data) const
Get information about the current run of the motion planner. Repeated calls to this function will upd...
bool directed
Flag indicating whether the planner is able to account for the fact that the validity of a motion fro...
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.
double getRange(void) const
Get the range the planner is using.
Abstract definition of a goal region that can be sampled.
#define OMPL_ERROR(fmt,...)
Log a formatted error string.
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
virtual void clear(void)
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
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.
Motion * lastGoalMotion_
The most recent goal motion. Used for PlannerData computation.
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)
virtual void setup(void)
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Representation of a motion.
RRT(const base::SpaceInformationPtr &si)
Constructor.
Definition of a geometric path.
double goalBias_
The fraction of time the goal is picked as the state to expand towards (if such a state is available)...
void setGoalBias(double goalBias)
Set the goal bias.
A boost shared pointer wrapper for ompl::base::Path.
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...
base::State * state
The state contained by the motion.
#define OMPL_INFORM(fmt,...)
Log a formatted information string.