SBL.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: Ioan Sucan */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_SBL_SBL_
38 #define OMPL_GEOMETRIC_PLANNERS_SBL_SBL_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/base/ProjectionEvaluator.h"
42 #include "ompl/datastructures/Grid.h"
43 #include "ompl/datastructures/PDF.h"
44 #include <vector>
45 
46 namespace ompl
47 {
48  namespace geometric
49  {
84  class SBL : public base::Planner
85  {
86  public:
88  SBL(const base::SpaceInformationPtr &si);
89 
90  ~SBL() override;
91 
94  void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
95  {
96  projectionEvaluator_ = projectionEvaluator;
97  }
98 
101  void setProjectionEvaluator(const std::string &name)
102  {
103  projectionEvaluator_ = si_->getStateSpace()->getProjection(name);
104  }
105 
108  {
109  return projectionEvaluator_;
110  }
111 
117  void setRange(double distance)
118  {
119  maxDistance_ = distance;
120  }
121 
123  double getRange() const
124  {
125  return maxDistance_;
126  }
127 
128  void setup() override;
129 
131 
132  void clear() override;
133 
134  void getPlannerData(base::PlannerData &data) const override;
135 
136  protected:
137  struct MotionInfo;
138 
141 
144 
146  class Motion
147  {
148  public:
150  Motion() : root(nullptr), state(nullptr), parent(nullptr), valid(false)
151  {
152  }
153 
156  : root(nullptr), state(si->allocState()), parent(nullptr), valid(false)
157  {
158  }
159 
162 
165 
168 
170  bool valid;
171 
173  std::vector<Motion *> children;
174  };
175 
177  struct MotionInfo
178  {
179  Motion *operator[](unsigned int i)
180  {
181  return motions_[i];
182  }
183  std::vector<Motion *>::iterator begin()
184  {
185  return motions_.begin();
186  }
187  void erase(std::vector<Motion *>::iterator iter)
188  {
189  motions_.erase(iter);
190  }
191  void push_back(Motion *m)
192  {
193  motions_.push_back(m);
194  }
195  unsigned int size() const
196  {
197  return motions_.size();
198  }
199  bool empty() const
200  {
201  return motions_.empty();
202  }
203 
204  std::vector<Motion *> motions_;
205  CellPDF::Element *elem_;
206  };
207 
209  struct TreeData
210  {
211  TreeData() : grid(0), size(0)
212  {
213  }
214 
217 
219  unsigned int size;
220 
222  CellPDF pdf;
223  };
224 
226  void freeMemory()
227  {
230  }
231 
233  void freeGridMotions(Grid<MotionInfo> &grid);
234 
236  void addMotion(TreeData &tree, Motion *motion);
237 
239  Motion *selectMotion(TreeData &tree);
240 
242  void removeMotion(TreeData &tree, Motion *motion);
243 
249  bool isPathValid(TreeData &tree, Motion *motion);
250 
252  bool checkSolution(bool start, TreeData &tree, TreeData &otherTree, Motion *motion,
253  std::vector<Motion *> &solution);
254 
257 
260 
263 
266 
268  double maxDistance_;
269 
272 
274  std::pair<base::State *, base::State *> connectionPoint_;
275  };
276  }
277 }
278 
279 #endif
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:174
TreeData tGoal_
The goal tree.
Definition: SBL.h:265
void getPlannerData(base::PlannerData &data) const override
Get information about the current run of the motion planner. Repeated calls to this function will upd...
Definition: SBL.cpp:370
Motion * parent
The parent motion – it contains the state this motion originates at.
Definition: SBL.h:167
std::vector< Motion * > children
The set of motions descending from the current motion.
Definition: SBL.h:173
Representation of a simple grid.
Definition: Grid.h:50
A shared pointer wrapper for ompl::base::ValidStateSampler.
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...
Definition: SBL.cpp:81
Motion()
Default constructor. Allocates no memory.
Definition: SBL.h:150
bool checkSolution(bool start, TreeData &tree, TreeData &otherTree, Motion *motion, std::vector< Motion *> &solution)
Check if a solution can be obtained by connecting two trees using a specified motion.
Definition: SBL.cpp:185
void addMotion(TreeData &tree, Motion *motion)
Add a motion to a tree.
Definition: SBL.cpp:332
void freeMemory()
Free the memory allocated by the planner.
Definition: SBL.h:226
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
base::ProjectionEvaluatorPtr projectionEvaluator_
The employed projection evaluator.
Definition: SBL.h:259
bool isPathValid(TreeData &tree, Motion *motion)
Since solutions are computed in a lazy fashion, once trees are connected, the solution found needs to...
Definition: SBL.cpp:244
base::State * state
The state this motion leads to.
Definition: SBL.h:164
Motion * selectMotion(TreeData &tree)
Select a motion from a tree.
Definition: SBL.cpp:270
void freeGridMotions(Grid< MotionInfo > &grid)
Free the memory used by the motions contained in a grid.
Definition: SBL.cpp:68
void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
Set the projection evaluator. This class is able to compute the projection of a given state...
Definition: SBL.h:94
CellPDF pdf
The PDF used for selecting a cell from which to sample a motion.
Definition: SBL.h:222
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
unsigned int size
The number of motions (in total) from the tree.
Definition: SBL.h:219
double getRange() const
Get the range the planner is using.
Definition: SBL.h:123
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
A struct containing an array of motions and a corresponding PDF element.
Definition: SBL.h:177
Base class for a planner.
Definition: Planner.h:232
void setup() override
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: SBL.cpp:57
const base::ProjectionEvaluatorPtr & getProjectionEvaluator() const
Get the projection evaluator.
Definition: SBL.h:107
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
const base::State * root
The root of the tree this motion would get to, if we were to follow parent pointers.
Definition: SBL.h:161
A shared pointer wrapper for ompl::base::SpaceInformation.
void removeMotion(TreeData &tree, Motion *motion)
Remove a motion from a tree.
Definition: SBL.cpp:276
PDF< GridCell * > CellPDF
A PDF of grid cells.
Definition: SBL.h:143
SBL(const base::SpaceInformationPtr &si)
The constructor needs the instance of the space information.
Definition: SBL.cpp:43
Definition of an abstract state.
Definition: State.h:49
Grid< MotionInfo > grid
The grid of motions corresponding to this tree.
Definition: SBL.h:216
A class that will hold data contained in the PDF.
Definition: PDF.h:52
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: SBL.h:117
Definition of a cell in this grid.
Definition: Grid.h:57
base::ValidStateSamplerPtr sampler_
The employed state sampler.
Definition: SBL.h:256
Grid< MotionInfo >::Cell GridCell
A grid cell.
Definition: SBL.h:137
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates storage for a state.
Definition: SBL.h:155
bool valid
Flag indicating whether this motion has been checked for validity.
Definition: SBL.h:170
RNG rng_
The random number generator to be used.
Definition: SBL.h:271
void clear() override
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: SBL.cpp:352
Representation of a motion.
Definition: SBL.h:146
Representation of a search tree. Two instances will be used. One for start and one for goal...
Definition: SBL.h:209
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:415
void setProjectionEvaluator(const std::string &name)
Set the projection evaluator (select one from the ones registered with the state space).
Definition: SBL.h:101
std::pair< base::State *, base::State * > connectionPoint_
The pair of states in each tree connected during planning. Used for PlannerData computation.
Definition: SBL.h:274
Single-Query Bi-Directional Probabilistic Roadmap Planner with Lazy Collision Checking.
Definition: SBL.h:84
double maxDistance_
The maximum length of a motion to be added in the tree.
Definition: SBL.h:268
TreeData tStart_
The start tree.
Definition: SBL.h:262