pSBL.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_pSBL_
38 #define OMPL_GEOMETRIC_PLANNERS_SBL_pSBL_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/base/ProjectionEvaluator.h"
42 #include "ompl/base/StateSamplerArray.h"
43 #include "ompl/datastructures/Grid.h"
44 #include "ompl/datastructures/PDF.h"
45 #include <thread>
46 #include <mutex>
47 #include <vector>
48 
49 namespace ompl
50 {
51 
52  namespace geometric
53  {
54 
88  class pSBL : public base::Planner
89  {
90  public:
91 
93 
94  virtual ~pSBL();
95 
98  void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
99  {
100  projectionEvaluator_ = projectionEvaluator;
101  }
102 
105  void setProjectionEvaluator(const std::string &name)
106  {
107  projectionEvaluator_ = si_->getStateSpace()->getProjection(name);
108  }
109 
112  {
113  return projectionEvaluator_;
114  }
115 
121  void setRange(double distance)
122  {
123  maxDistance_ = distance;
124  }
125 
127  double getRange() const
128  {
129  return maxDistance_;
130  }
131 
133  void setThreadCount(unsigned int nthreads);
134 
136  unsigned int getThreadCount() const
137  {
138  return threadCount_;
139  }
140 
141  virtual void setup();
142 
144 
145  virtual void clear();
146 
147  virtual void getPlannerData(base::PlannerData &data) const;
148 
149  protected:
150 
151  class Motion;
152  struct MotionInfo;
153 
156 
159 
160  class Motion
161  {
162  public:
163 
164  Motion() : root(nullptr), state(nullptr), parent(nullptr), valid(false)
165  {
166  }
167 
168  Motion(const base::SpaceInformationPtr &si) : root(nullptr), state(si->allocState()), parent(nullptr), valid(false)
169  {
170  }
171 
172  ~Motion()
173  {
174  }
175 
176  const base::State *root;
177  base::State *state;
178  Motion *parent;
179  bool valid;
180  std::vector<Motion*> children;
181  std::mutex lock;
182  };
183 
185  struct MotionInfo
186  {
187  Motion* operator[](unsigned int i)
188  {
189  return motions_[i];
190  }
191  std::vector<Motion*>::iterator begin()
192  {
193  return motions_.begin();
194  }
195  void erase(std::vector<Motion*>::iterator iter)
196  {
197  motions_.erase(iter);
198  }
199  void push_back(Motion *m)
200  {
201  motions_.push_back(m);
202  }
203  unsigned int size() const
204  {
205  return motions_.size();
206  }
207  bool empty() const
208  {
209  return motions_.empty();
210  }
211  std::vector<Motion*> motions_;
212  CellPDF::Element *elem_;
213  };
214 
215  struct TreeData
216  {
217  TreeData() : grid(0), size(0)
218  {
219  }
220 
221  Grid<MotionInfo> grid;
222  unsigned int size;
223  CellPDF pdf;
224  std::mutex lock;
225  };
226 
228  {
229  std::vector<Motion*> solution;
230  bool found;
231  std::mutex lock;
232  };
233 
235  {
236  TreeData *tree;
237  Motion *motion;
238  };
239 
241  {
242  std::vector<PendingRemoveMotion> motions;
243  std::mutex lock;
244  };
245 
246  void threadSolve(unsigned int tid, const base::PlannerTerminationCondition &ptc, SolutionInfo *sol);
247 
248  void freeMemory()
249  {
250  freeGridMotions(tStart_.grid);
251  freeGridMotions(tGoal_.grid);
252  }
253 
254  void freeGridMotions(Grid<MotionInfo> &grid);
255 
256  void addMotion(TreeData &tree, Motion *motion);
257  Motion* selectMotion(RNG &rng, TreeData &tree);
258  void removeMotion(TreeData &tree, Motion *motion, std::map<Motion*, bool> &seen);
259  bool isPathValid(TreeData &tree, Motion *motion);
260  bool checkSolution(RNG &rng, bool start, TreeData &tree, TreeData &otherTree, Motion *motion, std::vector<Motion*> &solution);
261 
262 
264  base::ProjectionEvaluatorPtr projectionEvaluator_;
265 
266  TreeData tStart_;
267  TreeData tGoal_;
268 
269  MotionsToBeRemoved removeList_;
270  std::mutex loopLock_;
271  std::mutex loopLockCounter_;
272  unsigned int loopCounter_;
273 
274  double maxDistance_;
275 
276  unsigned int threadCount_;
277 
279  std::pair<base::State*, base::State*> connectionPoint_;
280  };
281 
282  }
283 }
284 
285 #endif
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
Representation of a simple grid.
Definition: Grid.h:51
void setThreadCount(unsigned int nthreads)
Set the number of threads the planner should use. Default is 2.
Definition: pSBL.cpp:481
void setProjectionEvaluator(const std::string &name)
Set the projection evaluator (select one from the ones registered with the state space).
Definition: pSBL.h:105
void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
Set the projection evaluator. This class is able to compute the projection of a given state...
Definition: pSBL.h:98
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Main namespace. Contains everything in this library.
Definition: Cost.h:42
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: pSBL.cpp:192
virtual void clear()
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: pSBL.cpp:72
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
Base class for a planner.
Definition: Planner.h:230
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
const base::ProjectionEvaluatorPtr & getProjectionEvaluator() const
Get the projection evaluator.
Definition: pSBL.h:111
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
Definition of a cell in this grid.
Definition: Grid.h:59
unsigned int getThreadCount() const
Get the thread count.
Definition: pSBL.h:136
PDF< GridCell * > CellPDF
A PDF of grid cells.
Definition: pSBL.h:158
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: pSBL.cpp:452
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: pSBL.h:121
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: pSBL.cpp:61
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:398
Grid< MotionInfo >::Cell GridCell
A grid cell.
Definition: pSBL.h:152
Parallel Single-query Bi-directional Lazy collision checking planner.
Definition: pSBL.h:88
A struct containing an array of motions and a corresponding PDF element.
Definition: pSBL.h:185
double getRange() const
Get the range the planner is using.
Definition: pSBL.h:127
std::pair< base::State *, base::State * > connectionPoint_
The pair of states in each tree connected during planning. Used for PlannerData computation.
Definition: pSBL.h:279