pRRT.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_RRT_pRRT_
38 #define OMPL_GEOMETRIC_PLANNERS_RRT_pRRT_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/base/StateSamplerArray.h"
42 #include "ompl/datastructures/NearestNeighbors.h"
43 #include <thread>
44 #include <mutex>
45 
46 namespace ompl
47 {
48 
49  namespace geometric
50  {
51 
68  class pRRT : public base::Planner
69  {
70  public:
71 
73 
74  virtual ~pRRT();
75 
76  virtual void getPlannerData(base::PlannerData &data) const;
77 
79 
80  virtual void clear();
81 
91  void setGoalBias(double goalBias)
92  {
93  goalBias_ = goalBias;
94  }
95 
97  double getGoalBias() const
98  {
99  return goalBias_;
100  }
101 
107  void setRange(double distance)
108  {
109  maxDistance_ = distance;
110  }
111 
113  double getRange() const
114  {
115  return maxDistance_;
116  }
117 
119  void setThreadCount(unsigned int nthreads);
120 
121  unsigned int getThreadCount() const
122  {
123  return threadCount_;
124  }
125 
127  template<template<typename T> class NN>
129  {
130  nn_.reset(new NN<Motion*>());
131  }
132 
133  virtual void setup();
134 
135  protected:
136 
137  class Motion
138  {
139  public:
140 
141  Motion() : state(nullptr), parent(nullptr)
142  {
143  }
144 
145  Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(nullptr)
146  {
147  }
148 
149  ~Motion()
150  {
151  }
152 
153  base::State *state;
154  Motion *parent;
155 
156  };
157 
159  {
160  Motion *solution;
161  Motion *approxsol;
162  double approxdif;
163  std::mutex lock;
164  };
165 
166  void threadSolve(unsigned int tid, const base::PlannerTerminationCondition &ptc, SolutionInfo *sol);
167  void freeMemory();
168 
169  double distanceFunction(const Motion *a, const Motion *b) const
170  {
171  return si_->distance(a->state, b->state);
172  }
173 
175  std::shared_ptr< NearestNeighbors<Motion*> > nn_;
176  std::mutex nnLock_;
177 
178  unsigned int threadCount_;
179 
180  double goalBias_;
181  double maxDistance_;
182 
185  };
186 
187  }
188 }
189 
190 #endif
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
double getGoalBias() const
Get the goal bias the planner is using.
Definition: pRRT.h:97
void setGoalBias(double goalBias)
Set the goal bias.
Definition: pRRT.h:91
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Motion * lastGoalMotion_
The most recent goal motion. Used for PlannerData computation.
Definition: pRRT.h:184
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: pRRT.cpp:249
void setThreadCount(unsigned int nthreads)
Set the number of threads the planner should use. Default is 2.
Definition: pRRT.cpp:270
virtual void clear()
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: pRRT.cpp:75
Base class for a planner.
Definition: Planner.h:230
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: pRRT.h:107
void setNearestNeighbors()
Set a different nearest neighbors datastructure.
Definition: pRRT.h:128
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
double getRange() const
Get the range the planner is using.
Definition: pRRT.h:113
Parallel RRT.
Definition: pRRT.h:68
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:398
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: pRRT.cpp:172
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: pRRT.cpp:64