TRRT.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
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 Willow Garage 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 /* Author: Dave Coleman, Ryan Luna */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_RRT_TRRT_
38 #define OMPL_GEOMETRIC_PLANNERS_RRT_TRRT_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/datastructures/NearestNeighbors.h"
42 #include "ompl/base/OptimizationObjective.h"
43 
44 /*
45  NOTES:
46  **Variable Names that have been converted to longer versions from standards:
47  nearest_neighbors_ -> nn_
48  planner_termination_condition -> ptc
49 
50  **Inherited Member Variables Key:
51  si_ -> SpaceInformation
52  pdef_ -> ProblemDefinition
53  pis_ -> PlannerInputStates - Utility class to extract valid input states
54 */
55 
56 
57 namespace ompl
58 {
59 
60  namespace geometric
61  {
80  class TRRT : public base::Planner
81  {
82  public:
83 
86 
87  virtual ~TRRT();
88 
89  virtual void getPlannerData(base::PlannerData &data) const;
90 
91  virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &plannerTerminationCondition);
92 
93  virtual void clear();
94 
104  void setGoalBias(double goalBias)
105  {
106  goalBias_ = goalBias;
107  }
108 
110  double getGoalBias() const
111  {
112  return goalBias_;
113  }
114 
120  void setRange(double distance)
121  {
122  maxDistance_ = distance;
123  }
124 
126  double getRange() const
127  {
128  return maxDistance_;
129  }
130 
136  void setTempChangeFactor( double factor )
137  {
138  tempChangeFactor_ = exp(factor);
139  }
140 
142  double getTempChangeFactor( void ) const
143  {
144  return log(tempChangeFactor_);
145  }
146 
150  void setCostThreshold( double maxCost )
151  {
152  costThreshold_ = base::Cost(maxCost);
153  }
154 
158  double getCostThreshold() const
159  {
160  return costThreshold_.value();
161  }
162 
165  void setInitTemperature( double initTemperature )
166  {
167  initTemperature_ = initTemperature;
168  }
169 
171  double getInitTemperature( void ) const
172  {
173  return initTemperature_;
174  }
175 
178  void setFrontierThreshold( double frontier_threshold )
179  {
180  frontierThreshold_ = frontier_threshold;
181  }
182 
185  double getFrontierThreshold( void ) const
186  {
187  return frontierThreshold_;
188  }
189 
192  void setFrontierNodeRatio( double frontierNodeRatio )
193  {
194  frontierNodeRatio_ = frontierNodeRatio;
195  }
196 
199  double getFrontierNodeRatio( void ) const
200  {
201  return frontierNodeRatio_;
202  }
203 
205  template<template<typename T> class NN>
207  {
208  nearestNeighbors_.reset(new NN<Motion*>());
209  }
210 
211  virtual void setup();
212 
213  protected:
214 
215 
220  class Motion
221  {
222  public:
223 
224  Motion() : state(nullptr), parent(nullptr)
225  {
226  }
227 
229  Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(nullptr)
230  {
231  }
232 
233  ~Motion()
234  {
235  }
236 
239 
242 
245 
246  };
247 
249  void freeMemory();
250 
252  double distanceFunction(const Motion *a, const Motion *b) const
253  {
254  return si_->distance(a->state, b->state);
255  }
256 
260  bool transitionTest( const base::Cost& motionCost );
261 
263  bool minExpansionControl( double randMotionDistance );
264 
267 
269  std::shared_ptr< NearestNeighbors<Motion*> > nearestNeighbors_;
270 
272  double goalBias_;
273 
275  double maxDistance_;
276 
279 
282 
283  // *********************************************************************************************************
284  // TRRT-Specific Variables
285  // *********************************************************************************************************
286 
287  // Transtion Test -----------------------------------------------------------------------
288 
292  double temp_;
293 
296 
299 
302 
306 
309 
310  // Minimum Expansion Control --------------------------------------------------------------
311 
316 
320 
323 
326  };
327  }
328 }
329 
330 #endif
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
double getFrontierThreshold(void) const
Get the distance between a new state and the nearest neighbor that qualifies that state as being a fr...
Definition: TRRT.h:185
double initTemperature_
The initial value of temp_.
Definition: TRRT.h:308
void log(const char *file, int line, LogLevel level, const char *m,...)
Root level logging function. This should not be invoked directly, but rather used via a logging macro...
Definition: Console.cpp:120
A shared pointer wrapper for ompl::base::StateSampler.
void setNearestNeighbors()
Set a different nearest neighbors datastructure.
Definition: TRRT.h:206
double temp_
Temperature parameter used to control the difficulty level of transition tests. Low temperatures limi...
Definition: TRRT.h:292
double getFrontierNodeRatio(void) const
Get the ratio between adding nonfrontier nodes to frontier nodes, for example .1 is 1/10 or one nonfr...
Definition: TRRT.h:199
double getGoalBias() const
Get the goal bias the planner is using.
Definition: TRRT.h:110
base::Cost worstCost_
The least desirable (e.g., maximum) cost value in the search tree.
Definition: TRRT.h:298
double getCostThreshold() const
Get the cost threshold (default is infinity). Any motion cost that is not better than this cost (acco...
Definition: TRRT.h:158
Motion * parent
The parent motion in the exploration tree.
Definition: TRRT.h:241
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
RNG rng_
The random number generator.
Definition: TRRT.h:278
void setTempChangeFactor(double factor)
Set the factor by which the temperature is increased after a failed transition test. This value should be in the range (0, 1], typically close to zero (default is 0.1). This value is an exponential (e^factor) that is multiplied with the current temperature.
Definition: TRRT.h:136
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition: TRRT.h:275
double frontierThreshold_
The distance between an old state and a new state that qualifies it as a frontier state...
Definition: TRRT.h:319
std::shared_ptr< NearestNeighbors< Motion * > > nearestNeighbors_
A nearest-neighbors datastructure containing the tree of motions.
Definition: TRRT.h:269
double getInitTemperature(void) const
Get the temperature at the start of planning.
Definition: TRRT.h:171
bool transitionTest(const base::Cost &motionCost)
Filter irrelevant configuration regarding the search of low-cost paths before inserting into tree...
Definition: TRRT.cpp:387
TRRT(const base::SpaceInformationPtr &si)
Constructor.
Definition: TRRT.cpp:44
void setGoalBias(double goalBias)
Set the goal bias.
Definition: TRRT.h:104
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
base::Cost costThreshold_
All motion costs must be better than this cost (default is infinity)
Definition: TRRT.h:301
double getRange() const
Get the range the planner is using.
Definition: TRRT.h:126
Representation of a motion.
Definition: TRRT.h:220
Motion * lastGoalMotion_
The most recent goal motion. Used for PlannerData computation.
Definition: TRRT.h:281
Base class for a planner.
Definition: Planner.h:230
base::Cost cost
Cost of the state.
Definition: TRRT.h:244
ompl::base::OptimizationObjectivePtr opt_
The optimization objective being optimized by TRRT.
Definition: TRRT.h:325
double value() const
The value of the cost.
Definition: Cost.h:54
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: TRRT.h:120
base::State * state
The state contained by the motion.
Definition: TRRT.h:238
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
base::StateSamplerPtr sampler_
State sampler.
Definition: TRRT.h:266
A shared pointer wrapper for ompl::base::SpaceInformation.
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: TRRT.cpp:366
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
Definition: TRRT.h:252
double getTempChangeFactor(void) const
Get the factor by which the temperature rises based on current acceptance/rejection rate...
Definition: TRRT.h:142
Definition of an abstract state.
Definition: State.h:50
virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &plannerTerminationCondition)
Function that can solve the motion planning problem. This function can be called multiple times on th...
Definition: TRRT.cpp:151
double frontierCount_
The number of frontier nodes in the search tree.
Definition: TRRT.h:315
double goalBias_
The fraction of time the goal is picked as the state to expand towards (if such a state is available)...
Definition: TRRT.h:272
A shared pointer wrapper for ompl::base::OptimizationObjective.
void setFrontierNodeRatio(double frontierNodeRatio)
Set the ratio between adding nonfrontier nodes to frontier nodes, for example .1 is 1/10 or one nonfr...
Definition: TRRT.h:192
base::Cost bestCost_
The most desirable (e.g., minimum) cost value in the search tree.
Definition: TRRT.h:295
bool minExpansionControl(double randMotionDistance)
Use ratio to prefer frontier nodes to nonfrontier ones.
Definition: TRRT.cpp:414
void setInitTemperature(double initTemperature)
Set the initial temperature at the beginning of the algorithm. Should be high to allow for initial ex...
Definition: TRRT.h:165
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates memory for the state.
Definition: TRRT.h:229
Transition-based Rapidly-exploring Random Trees.
Definition: TRRT.h:80
double nonfrontierCount_
The number of non-frontier nodes in the search tree.
Definition: TRRT.h:313
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:398
double tempChangeFactor_
The value of the expression exp^T_rate. The temperature is increased by this factor whenever the tran...
Definition: TRRT.h:305
void freeMemory()
Free the memory allocated by this planner.
Definition: TRRT.cpp:134
double frontierNodeRatio_
Target ratio of non-frontier nodes to frontier nodes. rho.
Definition: TRRT.h:322
void setCostThreshold(double maxCost)
Set the cost threshold (default is infinity). Any motion cost that is not better than this cost (acco...
Definition: TRRT.h:150
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: TRRT.cpp:93
virtual void clear()
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: TRRT.cpp:76
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
void setFrontierThreshold(double frontier_threshold)
Set the distance between a new state and the nearest neighbor that qualifies that state as being a fr...
Definition: TRRT.h:178