42 #ifndef DART_PLANNING_PATHPLANNER_HPP_
43 #define DART_PLANNING_PATHPLANNER_HPP_
61 template <
class R = RRT>
91 bool bidirectional_ =
true,
93 double stepSize_ = 0.1,
94 std::size_t maxNodes_ = 1e6,
95 double goalBias_ = 0.3)
113 const std::vector<int>& dofs,
114 const Eigen::VectorXd& start,
115 const Eigen::VectorXd& goal,
116 std::list<Eigen::VectorXd>& path)
118 std::vector<Eigen::VectorXd> startVector, goalVector;
119 startVector.push_back(start);
120 goalVector.push_back(goal);
121 return planPath(robot, dofs, startVector, goalVector, path);
127 const std::vector<std::size_t>& dofs,
128 const std::vector<Eigen::VectorXd>& start,
129 const std::vector<Eigen::VectorXd>& goal,
130 std::list<Eigen::VectorXd>& path);
136 const std::vector<int>& dofs,
137 const std::vector<Eigen::VectorXd>& start,
138 const Eigen::VectorXd& goal,
139 std::list<Eigen::VectorXd>& path);
150 const std::vector<int>& dofs,
151 const std::vector<Eigen::VectorXd>& start,
152 const std::vector<Eigen::VectorXd>& goal,
153 std::list<Eigen::VectorXd>& path);
161 const std::vector<std::size_t>& dofs,
162 const std::vector<Eigen::VectorXd>& start,
163 const std::vector<Eigen::VectorXd>& goal,
164 std::list<Eigen::VectorXd>& path)
167 Eigen::VectorXd savedConfiguration = robot->
getPositions(dofs);
174 std::vector<Eigen::VectorXd> feasibleStart;
175 for (
unsigned int i = 0; i < start.size(); i++)
178 if (!world->checkCollision())
179 feasibleStart.push_back(start[i]);
183 if (feasibleStart.empty())
185 printf(
"WARNING: PathPlanner: Feasible start points are empty!\n");
191 std::vector<Eigen::VectorXd> feasibleGoal;
192 for (
unsigned int i = 0; i < goal.size(); i++)
195 if (!world->checkCollision())
196 feasibleGoal.push_back(goal[i]);
200 if (feasibleGoal.empty())
202 printf(
"WARNING: PathPlanner: Feasible goal points are empty!\n");
213 = planBidirectionalRrt(robot, dofs, feasibleStart, feasibleGoal, path);
216 if (feasibleGoal.size() > 1)
217 fprintf(stderr,
"WARNING: planPath is using ONLY the first goal!\n");
218 result = planSingleTreeRrt(
219 robot, dofs, feasibleStart, feasibleGoal.front(), path);
233 const std::vector<int>& dofs,
234 const std::vector<Eigen::VectorXd>& start,
235 const Eigen::VectorXd& goal,
236 std::list<Eigen::VectorXd>& path)
239 const bool debug =
false;
242 start_rrt =
new R(world, robot, dofs, start, stepSize);
245 typename R::StepResult
result = R::STEP_PROGRESS;
246 double smallestGap = std::numeric_limits<double>::infinity();
247 std::size_t numNodes = start_rrt->getSize();
248 while (numNodes <= maxNodes)
252 Eigen::VectorXd target;
253 double randomValue = ((double)rand()) / RAND_MAX;
254 if (randomValue < goalBias)
257 target = start_rrt->getRandomConfig();
262 start_rrt->connect(target);
264 start_rrt->tryStep(target);
267 double gap = start_rrt->getGap(goal);
271 std::cout <<
"Returning true, reached the goal" << std::endl;
272 start_rrt->tracePath(start_rrt->activeNode, path);
277 numNodes = start_rrt->getSize();
281 printf(
"numNodes: %lu\n", numNodes);
292 const std::vector<int>& dofs,
293 const std::vector<Eigen::VectorXd>& start,
294 const std::vector<Eigen::VectorXd>& goal,
295 std::list<Eigen::VectorXd>& path)
298 const bool debug =
false;
303 start_rrt =
new R(world, robot, dofs, start, stepSize);
304 goal_rrt =
new R(world, robot, dofs, goal, stepSize);
309 double smallestGap = std::numeric_limits<double>::infinity();
310 std::size_t numNodes = rrt1->getSize() + rrt2->getSize();
311 while (numNodes < maxNodes)
322 Eigen::VectorXd target;
323 double randomValue = ((double)rand()) / RAND_MAX;
324 if (randomValue < goalBias)
327 target = rrt1->getRandomConfig();
332 rrt1->connect(target);
334 rrt1->tryStep(target);
341 bool treesMet =
false;
342 const Eigen::VectorXd& rrt2target = *(rrt1->configVector[rrt1->activeNode]);
344 treesMet = rrt2->connect(rrt2target);
346 treesMet = (rrt2->tryStep(rrt2target) == R::STEP_REACHED);
351 start_rrt->tracePath(start_rrt->activeNode, path);
352 goal_rrt->tracePath(goal_rrt->activeNode, path,
true);
357 numNodes = rrt1->getSize() + rrt2->getSize();
362 double gap = rrt2->getGap(*(rrt1->configVector[rrt1->activeNode]));
363 if (gap < smallestGap)
366 std::cout <<
"Gap: " << smallestGap
367 <<
" Sizes: " << start_rrt->configVector.size() <<
"/"
368 << goal_rrt->configVector.size() << std::endl;
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:160
class Skeleton
Definition: Skeleton.hpp:59
The path planner class - a common interface to motion planners.
Definition: PathPlanner.hpp:63
virtual ~PathPlanner()
The destructor.
Definition: PathPlanner.hpp:106
PathPlanner(simulation::World &world, bool bidirectional_=true, bool connect_=true, double stepSize_=0.1, std::size_t maxNodes_=1e6, double goalBias_=0.3)
The desired constructor - you should use this one.
Definition: PathPlanner.hpp:89
bool planBidirectionalRrt(dynamics::Skeleton *robot, const std::vector< int > &dofs, const std::vector< Eigen::VectorXd > &start, const std::vector< Eigen::VectorXd > &goal, std::list< Eigen::VectorXd > &path)
Performs bidirectional RRT with the given options.
Definition: PathPlanner.hpp:290
std::size_t maxNodes
Maximum number of iterations the sampling would continue.
Definition: PathPlanner.hpp:73
R * goal_rrt
The second rrt if bidirectional search is executed.
Definition: PathPlanner.hpp:80
bool planPath(dynamics::Skeleton *robot, const std::vector< int > &dofs, const Eigen::VectorXd &start, const Eigen::VectorXd &goal, std::list< Eigen::VectorXd > &path)
Plan a path from a single start configuration to a single goal.
Definition: PathPlanner.hpp:111
simulation::WorldPtr world
The world that the robot is in (for obstacles and etc.)
Definition: PathPlanner.hpp:75
bool bidirectional
Whether two trees try to meet each other or one goes for the goal.
Definition: PathPlanner.hpp:66
double goalBias
Choose btw goal and random value (for goal-biased search)
Definition: PathPlanner.hpp:71
PathPlanner()
The default constructor.
Definition: PathPlanner.hpp:84
double stepSize
Step size from a node in the tree to the random/goal node.
Definition: PathPlanner.hpp:69
bool planSingleTreeRrt(dynamics::Skeleton *robot, const std::vector< int > &dofs, const std::vector< Eigen::VectorXd > &start, const Eigen::VectorXd &goal, std::list< Eigen::VectorXd > &path)
Performs a unidirectional RRT with the given options.
Definition: PathPlanner.hpp:231
bool connect
Whether we take a small step or shoot for the target node.
Definition: PathPlanner.hpp:65
R * start_rrt
The rrt for unidirectional search.
Definition: PathPlanner.hpp:79
class World
Definition: World.hpp:84
std::shared_ptr< World > WorldPtr
Definition: SmartPointer.hpp:41
Definition: BulletCollisionDetector.cpp:65
const bool debug
Definition: urdf_world_parser.cpp:52