All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
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 
49  namespace geometric
50  {
51 
85  class SBL : public base::Planner
86  {
87  public:
88 
90  SBL(const base::SpaceInformationPtr &si);
91 
92  virtual ~SBL(void);
93 
96  void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
97  {
98  projectionEvaluator_ = projectionEvaluator;
99  }
100 
103  void setProjectionEvaluator(const std::string &name)
104  {
105  projectionEvaluator_ = si_->getStateSpace()->getProjection(name);
106  }
107 
110  {
111  return projectionEvaluator_;
112  }
113 
119  void setRange(double distance)
120  {
121  maxDistance_ = distance;
122  }
123 
125  double getRange(void) const
126  {
127  return maxDistance_;
128  }
129 
130  virtual void setup(void);
131 
133 
134  virtual void clear(void);
135 
136  virtual void getPlannerData(base::PlannerData &data) const;
137 
138  protected:
139 
140  struct MotionInfo;
141 
144 
147 
149  class Motion
150  {
151  public:
152 
154  Motion(void) : root(NULL), state(NULL), parent(NULL), valid(false)
155  {
156  }
157 
159  Motion(const base::SpaceInformationPtr &si) : root(NULL), state(si->allocState()), parent(NULL), valid(false)
160  {
161  }
162 
165 
168 
171 
173  bool valid;
174 
176  std::vector<Motion*> children;
177  };
178 
180  struct MotionInfo
181  {
182  Motion* operator[](unsigned int i)
183  {
184  return motions_[i];
185  }
186  std::vector<Motion*>::iterator begin (void)
187  {
188  return motions_.begin ();
189  }
190  void erase (std::vector<Motion*>::iterator iter)
191  {
192  motions_.erase (iter);
193  }
194  void push_back(Motion* m)
195  {
196  motions_.push_back(m);
197  }
198  unsigned int size(void) const
199  {
200  return motions_.size();
201  }
202  bool empty(void) const
203  {
204  return motions_.empty();
205  }
206 
207  std::vector<Motion*> motions_;
208  CellPDF::Element* elem_;
209  };
210 
212  struct TreeData
213  {
214  TreeData(void) : grid(0), size(0)
215  {
216  }
217 
220 
222  unsigned int size;
223 
226  };
227 
229  void freeMemory(void)
230  {
233  }
234 
236  void freeGridMotions(Grid<MotionInfo> &grid);
237 
239  void addMotion(TreeData &tree, Motion *motion);
240 
242  Motion* selectMotion(TreeData &tree);
243 
245  void removeMotion(TreeData &tree, Motion *motion);
246 
252  bool isPathValid(TreeData &tree, Motion *motion);
253 
255  bool checkSolution(bool start, TreeData &tree, TreeData &otherTree, Motion *motion, std::vector<Motion*> &solution);
256 
259 
262 
265 
268 
270  double maxDistance_;
271 
274 
276  std::pair<base::State*, base::State*> connectionPoint_;
277  };
278 
279  }
280 }
281 
282 #endif
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:164
TreeData tGoal_
The goal tree.
Definition: SBL.h:267
Motion * parent
The parent motion – it contains the state this motion originates at.
Definition: SBL.h:170
Representation of a simple grid.
Definition: Grid.h:51
A boost shared pointer wrapper for ompl::base::ValidStateSampler.
void addMotion(TreeData &tree, Motion *motion)
Add a motion to a tree.
Definition: SBL.cpp:329
std::vector< Motion * > children
The set of motions descending from the current motion.
Definition: SBL.h:176
virtual void setup(void)
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: SBL.cpp:57
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
const base::ProjectionEvaluatorPtr & getProjectionEvaluator(void) const
Get the projection evaluator.
Definition: SBL.h:109
base::ProjectionEvaluatorPtr projectionEvaluator_
The employed projection evaluator.
Definition: SBL.h:261
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:241
base::State * state
The state this motion leads to.
Definition: SBL.h:167
Motion * selectMotion(TreeData &tree)
Select a motion from a tree.
Definition: SBL.cpp:267
void freeMemory(void)
Free the memory allocated by the planner.
Definition: SBL.h:229
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:96
CellPDF pdf
The PDF used for selecting a cell from which to sample a motion.
Definition: SBL.h:225
unsigned int size
The number of motions (in total) from the tree.
Definition: SBL.h:222
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: SBL.h:125
A struct containing an array of motions and a corresponding PDF element.
Definition: SBL.h:180
Base class for a planner.
Definition: Planner.h:227
Motion(void)
Default constructor. Allocates no memory.
Definition: SBL.h:154
A boost 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:164
A boost shared pointer wrapper for ompl::base::SpaceInformation.
void removeMotion(TreeData &tree, Motion *motion)
Remove a motion from a tree.
Definition: SBL.cpp:273
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:50
Grid< MotionInfo > grid
The grid of motions corresponding to this tree.
Definition: SBL.h:219
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:184
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: SBL.h:119
Definition of a cell in this grid.
Definition: Grid.h:59
base::ValidStateSamplerPtr sampler_
The employed state sampler.
Definition: SBL.h:258
std::pair< base::State *, base::State * > connectionPoint_
The pair of states in each tree connected during planning. Used for PlannerData computation.
Definition: SBL.h:276
Grid< MotionInfo >::Cell GridCell
A grid cell.
Definition: SBL.h:140
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates storage for a state.
Definition: SBL.h:159
bool valid
Flag indicating whether this motion has been checked for validity.
Definition: SBL.h:173
RNG rng_
The random number generator to be used.
Definition: SBL.h:273
Representation of a motion.
Definition: SBL.h:149
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: SBL.cpp:367
Representation of a search tree. Two instances will be used. One for start and one for goal...
Definition: SBL.h:212
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:392
void setProjectionEvaluator(const std::string &name)
Set the projection evaluator (select one from the ones registered with the state space).
Definition: SBL.h:103
Single-Query Bi-Directional Probabilistic Roadmap Planner with Lazy Collision Checking.
Definition: SBL.h:85
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: SBL.cpp:81
PDF< GridCell * > CellPDF
A PDF of grid cells.
Definition: SBL.h:146
double maxDistance_
The maximum length of a motion to be added in the tree.
Definition: SBL.h:270
virtual void clear(void)
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: SBL.cpp:349
TreeData tStart_
The start tree.
Definition: SBL.h:264