Loading...
Searching...
No Matches
STRRTstar.h
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2021, Technische Universität Berlin (TU Berlin)
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 TU Berlin 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: Francesco Grothe */
36
37#ifndef OMPL_GEOMETRIC_PLANNERS_RRT_STRRT_STAR_
38#define OMPL_GEOMETRIC_PLANNERS_RRT_STRRT_STAR_
39
40#include <ompl/datastructures/NearestNeighbors.h>
41#include <ompl/base/goals/GoalSampleableRegion.h>
42#include <ompl/geometric/planners/PlannerIncludes.h>
43#include <ompl/base/OptimizationObjective.h>
44#include <ompl/base/spaces/SpaceTimeStateSpace.h>
45#include <ompl/base/objectives/MinimizeArrivalTime.h>
46#include <ompl/base/samplers/ConditionalStateSampler.h>
47#include <ompl/tools/config/SelfConfig.h>
48#include <ompl/util/GeometricEquations.h>
49#include <boost/math/constants/constants.hpp>
50
51namespace ompl
52{
53 namespace geometric
54 {
63
65 class STRRTstar : public base::Planner
66 {
67 public:
69
71 explicit STRRTstar(const ompl::base::SpaceInformationPtr &si);
72
73 ~STRRTstar() override;
74
75 void clear() override;
76
77 void getPlannerData(base::PlannerData &data) const override;
78
80
86 void setRange(double distance);
87
89 double getRange() const;
90
92 double getOptimumApproxFactor() const;
93
96 void setOptimumApproxFactor(double optimumApproxFactor);
97
98 std::string getRewiringState() const;
99
101 void setRewiringToOff();
102
104 void setRewiringToRadius();
105
108
109 double getRewireFactor() const;
110
111 void setRewireFactor(double v);
112
114 unsigned int getBatchSize() const;
115
116 void setBatchSize(int v);
117
119 void setTimeBoundFactorIncrease(double f);
120
122 void setInitialTimeBoundFactor(double f);
123
125 void setSampleUniformForUnboundedTime(bool uniform);
126
127 void setup() override;
128
130 using TreeData = std::shared_ptr<ompl::NearestNeighbors<Motion *>>;
131
132 protected:
135 {
136 base::State *xstate;
137 Motion *xmotion;
138 bool start;
139 };
140
151
153 GrowState growTreeSingle(TreeData &tree, TreeGrowingInfo &tgi, Motion *rmotion, Motion *nmotion);
154
160 GrowState growTree(TreeData &tree, TreeGrowingInfo &tgi, Motion *rmotion, std::vector<Motion *> &nbh,
161 bool connect);
162
164 void increaseTimeBound(bool hasEqualBounds, double &oldBatchTimeBoundFactor,
165 double &newBatchTimeBoundFactor, bool &startTree, unsigned int &batchSize,
166 int &numBatchSamples);
167
169 void getNeighbors(TreeData &tree, Motion *motion, std::vector<Motion *> &nbh) const;
170
172 void freeMemory();
173
175 double distanceFunction(const Motion *a, const Motion *b) const
176 {
177 return si_->distance(a->state, b->state);
178 }
179
181 void pruneStartTree();
182
186 Motion *pruneGoalTree();
187
189 static Motion *computeSolutionMotion(Motion *motion);
190
192 void removeInvalidGoals(const std::vector<Motion *> &invalidGoals);
193
196
199
202
204 double maxDistance_{0.};
205
208
210 base::PathPtr bestSolution_{nullptr};
211
213 double bestTime_ = std::numeric_limits<double>::infinity();
214
216 unsigned int numIterations_ = 0;
217
220
222 double minimumTime_ = std::numeric_limits<double>::infinity();
223
226
229
231 Motion *startMotion_{nullptr};
232
234 std::vector<Motion *> goalMotions_{};
235
238 std::vector<Motion *> newBatchGoalMotions_{};
239
245
246 base::State *tempState_{nullptr}; // temporary sampled goal states are stored here.
247
249 base::State *nextGoal(int n, double oldBatchTimeBoundFactor, double newBatchTimeBoundFactor);
250
252 base::State *nextGoal(const base::PlannerTerminationCondition &ptc, double oldBatchTimeBoundFactor,
253 double newBatchTimeBoundFactor);
254
256 base::State *nextGoal(const base::PlannerTerminationCondition &ptc, int n, double oldBatchTimeBoundFactor,
257 double newBatchTimeBoundFactor);
258
261 bool sampleGoalTime(base::State *goal, double oldBatchTimeBoundFactor, double newBatchTimeBoundFactor);
262
264 static void removeFromParent(Motion *m);
265
268 static void addDescendants(Motion *m, const TreeData &tree);
269
270 void constructSolution(Motion *startMotion, Motion *goalMotion,
271 const base::ReportIntermediateSolutionFn &intermediateSolutionCallback,
273
274 enum RewireState
275 {
276 // use r-disc search for rewiring
277 RADIUS,
278 // use k-nearest for rewiring
279 KNEAREST,
280 // don't use any rewiring
281 OFF
282 };
283
284 RewireState rewireState_ = KNEAREST;
285
288 double rewireFactor_{1.1};
289
291 double k_rrt_{0u};
292
294 double r_rrt_{0.};
295
298
299 bool rewireGoalTree(Motion *addedMotion);
300
303
306
308 unsigned int initialBatchSize_ = 512;
309
313
316
317 bool sampleOldBatch_ = true;
318
322
325
328 };
329 } // namespace geometric
330} // namespace ompl
331
332#endif
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
The Conditional Sampler samples feasible Space-Time States. First, a space configuration is sampled....
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique,...
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Base class for a planner.
Definition Planner.h:216
SpaceInformationPtr si_
The space information for which planning is done.
Definition Planner.h:401
Definition of an abstract state.
Definition State.h:50
TreeData tGoal_
The goal tree.
Definition STRRTstar.h:201
double k_rrt_
A constant for k-nearest rewiring calculations.
Definition STRRTstar.h:291
GrowState growTreeSingle(TreeData &tree, TreeGrowingInfo &tgi, Motion *rmotion, Motion *nmotion)
Grow a tree towards a random state for a single nearest state.
void setOptimumApproxFactor(double optimumApproxFactor)
Set the Optimum Approximation factor. This allows the planner to converge more quickly,...
unsigned int initialBatchSize_
Number of samples of the first batch.
Definition STRRTstar.h:308
void freeMemory()
Free the memory allocated by this planner.
Definition STRRTstar.cpp:91
double bestTime_
The current best time i.e. cost of all found solutions.
Definition STRRTstar.h:213
base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc) override
Function that can solve the motion planning problem. This function can be called multiple times on th...
TreeData tStart_
The start tree.
Definition STRRTstar.h:198
GrowState
The state of the tree after an attempt to extend it.
Definition STRRTstar.h:143
@ ADVANCED
progress has been made towards the randomly sampled state
Definition STRRTstar.h:147
@ TRAPPED
no progress has been made
Definition STRRTstar.h:145
@ REACHED
the randomly sampled state was reached
Definition STRRTstar.h:149
void calculateRewiringLowerBounds()
Calculate the k_RRG* and r_RRG* terms.
void setSampleUniformForUnboundedTime(bool uniform)
Whether the state space is sampled uniformly or centered at lower time values.
double r_rrt_
A constant for r-disc rewiring calculations.
Definition STRRTstar.h:294
int goalStateSampleRatio_
The ratio, a goal state is sampled compared to the size of the goal tree.
Definition STRRTstar.h:324
double getOptimumApproxFactor() const
The Optimum Approximation factor (0 - 1).
unsigned int numIterations_
The number of while loop iterations.
Definition STRRTstar.h:216
Motion * startMotion_
The start Motion, used for conditional sampling and start tree pruning.
Definition STRRTstar.h:231
double upperTimeBound_
Upper bound for the time up to which solutions are searched for.
Definition STRRTstar.h:225
static void addDescendants(Motion *m, const TreeData &tree)
Adds given all descendants of the given motion to given tree and checks whether one of the added moti...
std::vector< Motion * > newBatchGoalMotions_
The goal Motions, that were added in the current expansion step, used for uniform sampling over a gro...
Definition STRRTstar.h:238
double optimumApproxFactor_
The factor to which found solution times need to be reduced compared to minimum time,...
Definition STRRTstar.h:228
double rewireFactor_
The rewiring factor, s, so that r_rrt = s \times r_rrt* > r_rrt* (or k_rrt = s \times k_rrt* > k_rrt*...
Definition STRRTstar.h:288
double timeBoundFactorIncrease_
The factor, the time bound is increased with after the batch is full.
Definition STRRTstar.h:315
bool sampleUniformForUnboundedTime_
Whether the samples are uniformly distributed over the whole space or are centered at lower times.
Definition STRRTstar.h:321
double getRange() const
Get the range the planner is using.
void getNeighbors(TreeData &tree, Motion *motion, std::vector< Motion * > &nbh) const
Gets the neighbours of a given motion, using either k-nearest or radius_ as appropriate.
void setTimeBoundFactorIncrease(double f)
The value by which the time bound factor is multiplied in each increase step.
double distanceBetweenTrees_
Distance between the nearest pair of start tree and goal tree nodes.
Definition STRRTstar.h:207
void setInitialTimeBoundFactor(double f)
The initial time bound factor.
base::PathPtr bestSolution_
The current best solution path with respect to shortest time.
Definition STRRTstar.h:210
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition STRRTstar.h:204
void pruneStartTree()
Prune the start tree after a solution was found.
void clear() override
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
int numSolutions_
The number of found solutions.
Definition STRRTstar.h:219
void getPlannerData(base::PlannerData &data) const override
Get information about the current run of the motion planner. Repeated calls to this function will upd...
std::shared_ptr< ompl::NearestNeighbors< Motion * > > TreeData
A nearest-neighbor datastructure representing a tree of motions.
Definition STRRTstar.h:130
GrowState growTree(TreeData &tree, TreeGrowingInfo &tgi, Motion *rmotion, std::vector< Motion * > &nbh, bool connect)
Attempt to grow a tree towards a random state for the neighborhood of the random state....
STRRTstar(const ompl::base::SpaceInformationPtr &si)
Constructor.
Definition STRRTstar.cpp:41
static void removeFromParent(Motion *m)
Removes the given motion from the parent's child list.
void setup() override
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition STRRTstar.cpp:60
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states).
Definition STRRTstar.h:175
void setRewiringToOff()
Do not rewire at all.
bool sampleGoalTime(base::State *goal, double oldBatchTimeBoundFactor, double newBatchTimeBoundFactor)
Samples the time component of a goal state dependant on its space component. Returns false,...
ompl::RNG rng_
The random number generator.
Definition STRRTstar.h:327
void removeInvalidGoals(const std::vector< Motion * > &invalidGoals)
Remove invalid goal states from the goal set.
base::State * nextGoal(int n, double oldBatchTimeBoundFactor, double newBatchTimeBoundFactor)
N tries to sample a goal.
base::ConditionalStateSampler sampler_
State sampler.
Definition STRRTstar.h:195
double initialTimeBoundFactor_
Initial factor, the minimum time of each goal is multiplied with to calculate the upper time bound.
Definition STRRTstar.h:312
double minimumTime_
Minimum Time at which any goal can be reached, if moving on a straight line.
Definition STRRTstar.h:222
void setRewiringToRadius()
Rewire by radius.
void setRewiringToKNearest()
Rewire by k-nearest.
std::vector< Motion * > goalMotions_
The goal Motions, used for conditional sampling and pruning.
Definition STRRTstar.h:234
bool isTimeBounded_
Whether the time is bounded or not. The first solution automatically bounds the time.
Definition STRRTstar.h:302
static Motion * computeSolutionMotion(Motion *motion)
Find the solution (connecting) motion for a motion that is indirectly connected.
void setRange(double distance)
Set the range the planner is supposed to use.
unsigned int getBatchSize() const
The number of samples before the time bound is increased.
double initialTimeBound_
The time bound the planner is initialized with. Used to reset for repeated planning.
Definition STRRTstar.h:305
Motion * pruneGoalTree()
Prune the goal tree after a solution was found. Return the goal motion, that is connected to the star...
std::function< void(const Planner *, const std::vector< const base::State * > &, const Cost)> ReportIntermediateSolutionFn
When a planner has an intermediate solution (e.g., optimizing planners), a function with this signatu...
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.
A class to store the exit status of Planner::solve().
Information attached to growing a tree of motions (used internally).
Definition STRRTstar.h:135