42 #ifndef DART_PLANNING_PATHPLANNER_HPP_
43 #define DART_PLANNING_PATHPLANNER_HPP_
60 template <
class R = RRT>
91 const Eigen::VectorXd &goal, std::list<Eigen::VectorXd> &path) {
92 std::vector<Eigen::VectorXd> startVector, goalVector;
93 startVector.push_back(start);
94 goalVector.push_back(goal);
95 return planPath(robot, dofs, startVector, goalVector, path);
100 const std::vector<Eigen::VectorXd> &goal, std::list<Eigen::VectorXd> &path);
106 const std::vector<Eigen::VectorXd> &start,
const Eigen::VectorXd &goal,
107 std::list<Eigen::VectorXd> &path);
116 const std::vector<Eigen::VectorXd> &start,
const std::vector<Eigen::VectorXd> &goal,
117 std::list<Eigen::VectorXd> &path);
123 const std::vector<Eigen::VectorXd> &start,
const std::vector<Eigen::VectorXd> &goal,
124 std::list<Eigen::VectorXd> &path) {
126 Eigen::VectorXd savedConfiguration = robot->
getPositions(dofs);
132 std::vector<Eigen::VectorXd> feasibleStart;
133 for(
unsigned int i = 0; i < start.size(); i++) {
135 if(!world->checkCollision()) feasibleStart.push_back(start[i]);
139 if(feasibleStart.empty()) {
140 printf(
"WARNING: PathPlanner: Feasible start points are empty!\n");
145 std::vector<Eigen::VectorXd> feasibleGoal;
146 for(
unsigned int i = 0; i < goal.size(); i++) {
148 if(!world->checkCollision()) feasibleGoal.push_back(goal[i]);
152 if(feasibleGoal.empty()) {
153 printf(
"WARNING: PathPlanner: Feasible goal points are empty!\n");
163 result = planBidirectionalRrt(robot, dofs, feasibleStart, feasibleGoal, path);
165 if(feasibleGoal.size() > 1) fprintf(stderr,
"WARNING: planPath is using ONLY the first goal!\n");
166 result = planSingleTreeRrt(robot, dofs, feasibleStart, feasibleGoal.front(), path);
178 const std::vector<Eigen::VectorXd> &start,
const Eigen::VectorXd &goal,
179 std::list<Eigen::VectorXd> &path) {
181 const bool debug =
false;
184 start_rrt =
new R (world, robot, dofs, start, stepSize);
187 typename R::StepResult
result = R::STEP_PROGRESS;
188 double smallestGap = std::numeric_limits<double>::infinity();
189 std::size_t numNodes = start_rrt->getSize();
190 while(numNodes <= maxNodes) {
193 Eigen::VectorXd target;
194 double randomValue = ((double) rand()) / RAND_MAX;
195 if(randomValue < goalBias) target = goal;
196 else target = start_rrt->getRandomConfig();
199 if(connect) start_rrt->connect(target);
200 else start_rrt->tryStep(target);
203 double gap = start_rrt->getGap(goal);
205 if(
debug) std::cout <<
"Returning true, reached the goal" << std::endl;
206 start_rrt->tracePath(start_rrt->activeNode, path);
211 numNodes = start_rrt->getSize();
214 if(
debug) printf(
"numNodes: %lu\n", numNodes);
223 const std::vector<Eigen::VectorXd> &start,
const std::vector<Eigen::VectorXd> &goal,
224 std::list<Eigen::VectorXd> &path) {
226 const bool debug =
false;
231 start_rrt =
new R(world, robot, dofs, start, stepSize);
232 goal_rrt =
new R(world, robot, dofs, goal, stepSize);
237 double smallestGap = std::numeric_limits<double>::infinity();
238 std::size_t numNodes = rrt1->getSize() + rrt2->getSize();
239 while(numNodes < maxNodes) {
248 Eigen::VectorXd target;
249 double randomValue = ((double) rand()) / RAND_MAX;
250 if(randomValue < goalBias) target = goal[0];
251 else target = rrt1->getRandomConfig();
254 if(connect) rrt1->connect(target);
255 else rrt1->tryStep(target);
261 bool treesMet =
false;
262 const Eigen::VectorXd& rrt2target = *(rrt1->configVector[rrt1->activeNode]);
263 if(connect) treesMet = rrt2->connect(rrt2target);
264 else treesMet = (rrt2->tryStep(rrt2target) == R::STEP_REACHED);
268 start_rrt->tracePath(start_rrt->activeNode, path);
269 goal_rrt->tracePath(goal_rrt->activeNode, path,
true);
274 numNodes = rrt1->getSize() + rrt2->getSize();
278 double gap = rrt2->getGap(*(rrt1->configVector[rrt1->activeNode]));
279 if(gap < smallestGap) {
281 std::cout <<
"Gap: " << smallestGap <<
" Sizes: " << start_rrt->configVector.size()
282 <<
"/" << goal_rrt->configVector.size() << std::endl;
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:157
class Skeleton
Definition: Skeleton.hpp:59
The path planner class - a common interface to motion planners.
Definition: PathPlanner.hpp:61
virtual ~PathPlanner()
The destructor.
Definition: PathPlanner.hpp:87
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:81
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:222
std::size_t maxNodes
Maximum number of iterations the sampling would continue.
Definition: PathPlanner.hpp:68
R * goal_rrt
The second rrt if bidirectional search is executed.
Definition: PathPlanner.hpp:73
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:90
simulation::WorldPtr world
The world that the robot is in (for obstacles and etc.)
Definition: PathPlanner.hpp:69
bool bidirectional
Whether two trees try to meet each other or one goes for the goal.
Definition: PathPlanner.hpp:65
double goalBias
Choose btw goal and random value (for goal-biased search)
Definition: PathPlanner.hpp:67
PathPlanner()
The default constructor.
Definition: PathPlanner.hpp:78
double stepSize
Step size from a node in the tree to the random/goal node.
Definition: PathPlanner.hpp:66
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:177
bool connect
Whether we take a small step or shoot for the target node.
Definition: PathPlanner.hpp:64
R * start_rrt
The rrt for unidirectional search.
Definition: PathPlanner.hpp:72
class World
Definition: World.hpp:83
std::shared_ptr< World > WorldPtr
Definition: SmartPointer.hpp:41
Definition: BulletCollisionDetector.cpp:63
const bool debug
Definition: urdf_world_parser.cpp:52