All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
RRTstar.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Authors: Alejandro Perez, Sertac Karaman, Ryan Luna, Luis G. Torres, Ioan Sucan */
36 
37 #ifndef OMPL_CONTRIB_RRT_STAR_RRTSTAR_
38 #define OMPL_CONTRIB_RRT_STAR_RRTSTAR_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/base/OptimizationObjective.h"
42 #include "ompl/datastructures/NearestNeighbors.h"
43 #include <limits>
44 #include <vector>
45 #include <utility>
46 
47 
48 namespace ompl
49 {
50 
51  namespace geometric
52  {
53 
75  class RRTstar : public base::Planner
76  {
77  public:
78 
80 
81  virtual ~RRTstar(void);
82 
83  virtual void getPlannerData(base::PlannerData &data) const;
84 
86 
87  virtual void clear(void);
88 
98  void setGoalBias(double goalBias)
99  {
100  goalBias_ = goalBias;
101  }
102 
104  double getGoalBias(void) const
105  {
106  return goalBias_;
107  }
108 
114  void setRange(double distance)
115  {
116  maxDistance_ = distance;
117  }
118 
120  double getRange(void) const
121  {
122  return maxDistance_;
123  }
124 
126  template<template<typename T> class NN>
128  {
129  nn_.reset(new NN<Motion*>());
130  }
131 
139  void setDelayCC(bool delayCC)
140  {
141  delayCC_ = delayCC;
142  }
143 
145  bool getDelayCC(void) const
146  {
147  return delayCC_;
148  }
149 
150  virtual void setup(void);
151 
153  // Planner progress property functions
154  std::string getIterationCount(void) const;
155 
156  std::string getCollisionCheckCount(void) const;
157 
158  std::string getBestCost(void) const;
160 
161  protected:
162 
164  class Motion
165  {
166  public:
169  state(si->allocState()),
170  parent(NULL)
171  {
172  }
173 
174  ~Motion(void)
175  {
176  }
177 
180 
183 
186 
189 
191  std::vector<Motion*> children;
192  };
193 
195  void freeMemory(void);
196 
197  // For sorting a list of costs and getting only their sorted indices
199  {
200  CostIndexCompare(const std::vector<base::Cost>& costs,
201  const base::OptimizationObjective& opt) :
202  costs_(costs), opt_(opt)
203  {}
204  bool operator()(unsigned i, unsigned j)
205  {
206  return opt_.isCostBetterThan(costs_[i],costs_[j]);
207  }
208  const std::vector<base::Cost>& costs_;
209  const base::OptimizationObjective& opt_;
210  };
211 
212  enum DistanceDirection { FROM_NEIGHBORS, TO_NEIGHBORS };
213 
215  double distanceFunction(const Motion* a, const Motion* b) const
216  {
217  switch (distanceDirection_)
218  {
219  case FROM_NEIGHBORS:
220  return si_->distance(a->state, b->state);
221  case TO_NEIGHBORS:
222  return si_->distance(b->state, a->state);
223  }
224  }
225 
227  void removeFromParent(Motion *m);
228 
230  void updateChildCosts(Motion *m);
231 
234 
236  boost::shared_ptr< NearestNeighbors<Motion*> > nn_;
237 
239  double goalBias_;
240 
242  double maxDistance_;
243 
246 
248  bool delayCC_;
249 
252 
255 
257  std::vector<Motion*> goalMotions_;
258 
260  // Planner progress properties
261 
263  unsigned int iterations_;
264 
266  unsigned int collisionChecks_;
267 
270 
274  DistanceDirection distanceDirection_;
275  };
276 
277  }
278 }
279 
280 #endif
bool getDelayCC(void) const
Get the state of the delayed collision checking option.
Definition: RRTstar.h:145
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:164
Optimal Rapidly-exploring Random Trees.
Definition: RRTstar.h:75
void setDelayCC(bool delayCC)
Option that delays collision checking procedures. When it is enabled, all neighbors are sorted by cos...
Definition: RRTstar.h:139
void setNearestNeighbors(void)
Set a different nearest neighbors datastructure.
Definition: RRTstar.h:127
void updateChildCosts(Motion *m)
Updates the cost of the children of this node if the cost up to this node has changed.
Definition: RRTstar.cpp:503
base::OptimizationObjectivePtr opt_
Objective we're optimizing.
Definition: RRTstar.h:251
A boost shared pointer wrapper for ompl::base::StateSampler.
double goalBias_
The fraction of time the goal is picked as the state to expand towards (if such a state is available)...
Definition: RRTstar.h:239
base::Cost cost
The cost up to this motion.
Definition: RRTstar.h:185
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: RRTstar.h:114
Motion * lastGoalMotion_
The most recent goal motion. Used for PlannerData computation.
Definition: RRTstar.h:254
boost::shared_ptr< NearestNeighbors< Motion * > > nn_
A nearest-neighbors datastructure containing the tree of motions.
Definition: RRTstar.h:236
double getGoalBias(void) const
Get the goal bias the planner is using.
Definition: RRTstar.h:104
base::Cost bestCost_
Best cost found so far by algorithm.
Definition: RRTstar.h:269
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition: RRTstar.h:242
Representation of a motion.
Definition: RRTstar.h:164
base::State * state
The state contained by the motion.
Definition: RRTstar.h:179
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:54
double getRange(void) const
Get the range the planner is using.
Definition: RRTstar.h:120
Base class for a planner.
Definition: Planner.h:227
virtual void getPlannerData(base::PlannerData &data) const
Get information about the current run of the motion planner. Repeated calls to this function will upd...
Definition: RRTstar.cpp:527
virtual bool isCostBetterThan(Cost c1, Cost c2) const
Check whether the the cost c1 is considered better than the cost c2. By default, this returns true on...
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
A boost shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
std::vector< Motion * > children
The set of motions descending from the current motion.
Definition: RRTstar.h:191
Abstract definition of optimization objectives.
base::StateSamplerPtr sampler_
State sampler.
Definition: RRTstar.h:233
A boost shared pointer wrapper for ompl::base::OptimizationObjective.
RNG rng_
The random number generator.
Definition: RRTstar.h:245
unsigned int collisionChecks_
Number of collisions checks performed by the algorithm.
Definition: RRTstar.h:266
void freeMemory(void)
Free the memory allocated by this planner.
Definition: RRTstar.cpp:512
Motion * parent
The parent motion in the exploration tree.
Definition: RRTstar.h:182
bool delayCC_
Option to delay and reduce collision checking within iterations.
Definition: RRTstar.h:248
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...
Definition: RRTstar.cpp:120
void removeFromParent(Motion *m)
Removes the given motion from the parent's child list.
Definition: RRTstar.cpp:488
void setGoalBias(double goalBias)
Set the goal bias.
Definition: RRTstar.h:98
virtual void clear(void)
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: RRTstar.cpp:103
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:392
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates memory for the state. This constructor automatically allocates memory for ...
Definition: RRTstar.h:168
virtual void setup(void)
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: RRTstar.cpp:78
std::vector< Motion * > goalMotions_
A list of states in the tree that satisfy the goal condition.
Definition: RRTstar.h:257
base::Cost incCost
The incremental cost of this motion's parent to this motion (this is stored to save distance computat...
Definition: RRTstar.h:188
unsigned int iterations_
Number of iterations the algorithm performed.
Definition: RRTstar.h:263
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
Definition: RRTstar.h:215
DistanceDirection distanceDirection_
Directionality of distance computation for nearest neighbors. Either from neighbors to new state...
Definition: RRTstar.h:274