Skip to content
Snippets Groups Projects
Commit 0fb241cf authored by Florent Lamiraux's avatar Florent Lamiraux
Browse files

A few updates

  - In PRM, do not insert edges in the loop over the connected components,
  - replace deprecated call in script tutorial_2.py .
parent 65d78a62
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/// ///
/// <h1>Implementing a new path planning algorithm</h1> /// <h1>Implementing a new path planning algorithm</h1>
/// ///
/// The code of this tutorial can be found in \c src/tutorial.cc. /// The code of this tutorial can be found in \c src/tutorial_2.cc.
/// The compilation and installation instructions can be found in /// The compilation and installation instructions can be found in
/// \c CMakeLists.txt. /// \c CMakeLists.txt.
/// ///
......
...@@ -27,7 +27,7 @@ rank = robot.rankInConfiguration["r_elbow_flex_joint"] ...@@ -27,7 +27,7 @@ rank = robot.rankInConfiguration["r_elbow_flex_joint"]
q_goal[rank] = -0.5 q_goal[rank] = -0.5
vf(q_goal) vf(q_goal)
vf.loadObstacleModel("iai_maps", "kitchen_area", "kitchen") vf.loadObstacleModel("package://hpp_tutorial/urdf/kitchen_area.urdf", "kitchen")
ps.setInitialConfig(q_init) ps.setInitialConfig(q_init)
ps.addGoalConfig(q_goal) ps.addGoalConfig(q_goal)
......
...@@ -42,8 +42,8 @@ int main() { ...@@ -42,8 +42,8 @@ int main() {
// Add obstacle // Add obstacle
DevicePtr_t obstacle = Device::create("kitchen"); DevicePtr_t obstacle = Device::create("kitchen");
hpp::pinocchio::urdf::loadUrdfModel(obstacle, "anchor", "iai_maps", hpp::pinocchio::urdf::loadModel(obstacle, 0, "", "anchor",
"kitchen_area"); "package://hpp_tutorial/urdf/kitchen_area.urdf", "");
obstacle->controlComputation(JOINT_POSITION); obstacle->controlComputation(JOINT_POSITION);
ps->addObstacle(obstacle, true, true); ps->addObstacle(obstacle, true, true);
......
...@@ -58,6 +58,8 @@ class Planner : public core::PathPlanner { ...@@ -58,6 +58,8 @@ class Planner : public core::PathPlanner {
/// ///
/// We will see how to implement a basic PRM algorithm. /// We will see how to implement a basic PRM algorithm.
virtual void oneStep() { virtual void oneStep() {
using core::NodePtr_t;
using core::PathPtr_t;
// Retrieve the robot the problem has been defined for. // Retrieve the robot the problem has been defined for.
pinocchio::DevicePtr_t robot(problem()->robot()); pinocchio::DevicePtr_t robot(problem()->robot());
// Retrieve the path validation algorithm associated to the problem // Retrieve the path validation algorithm associated to the problem
...@@ -79,32 +81,39 @@ class Planner : public core::PathPlanner { ...@@ -79,32 +81,39 @@ class Planner : public core::PathPlanner {
shooter_->shoot(qrand); shooter_->shoot(qrand);
} while (!configValidations->validate(qrand, validationReport)); } while (!configValidations->validate(qrand, validationReport));
// Add qrand as a new node // Add qrand as a new node
core::NodePtr_t newNode = r->addNode(qrand); NodePtr_t newNode = r->addNode(qrand);
// try to connect the random configuration to each connected component // try to connect the random configuration to each connected component
// of the roadmap. // of the roadmap.
for (core::ConnectedComponents_t::const_iterator itcc =
r->connectedComponents().begin(); // Modifying the connected components of the graph while making a loop
itcc != r->connectedComponents().end(); ++itcc) { // over all of them is not correct. We therefore record the edges to
core::ConnectedComponentPtr_t cc = *itcc; // to insert and add them after the loop.
typedef std::tuple<NodePtr_t, NodePtr_t, PathPtr_t> DelayedEdge_t;
typedef std::vector<DelayedEdge_t> DelayedEdges_t;
DelayedEdges_t delayedEdges;
for (auto cc : r->connectedComponents()) {
// except its own connected component of course // except its own connected component of course
if (cc != newNode->connectedComponent()) { if (cc != newNode->connectedComponent()) {
value_type d; value_type d;
// Get nearest node to qrand in connected component // Get nearest node to qrand in connected component
core::NodePtr_t nearest = r->nearestNode(qrand, cc, d); NodePtr_t nearest = r->nearestNode(qrand, cc, d);
core::ConfigurationPtr_t qnear = nearest->configuration(); core::ConfigurationPtr_t qnear = nearest->configuration();
// Create local path between qnear and qrand // Create local path between qnear and qrand
core::PathPtr_t localPath = (*sm)(*qnear, qrand); PathPtr_t localPath = (*sm)(*qnear, qrand);
// validate local path // validate local path
core::PathPtr_t validPart; PathPtr_t validPart;
// report on path validation: unused here // report on path validation: unused here
core::PathValidationReportPtr_t report; core::PathValidationReportPtr_t report;
if (pathValidation->validate(localPath, false, validPart, report)) { if (pathValidation->validate(localPath, false, validPart, report)) {
// Create node and edges with qrand and the local path // Create node and edges with qrand and the local path
r->addEdge(nearest, newNode, localPath); delayedEdges.push_back(DelayedEdge_t(nearest, newNode, localPath));
r->addEdge(newNode, nearest, localPath->reverse());
} }
} }
} }
for(auto de : delayedEdges){
r->addEdge(std::get<0>(de), std::get<1>(de), std::get<2>(de));
r->addEdge(std::get<1>(de), std::get<0>(de), std::get<2>(de)->reverse());
}
} }
protected: protected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment