Skip to content
Snippets Groups Projects
Commit 55a34b3d authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Fix usage of cache in WaypointEdge

parent 7183d458
No related branches found
No related tags found
No related merge requests found
...@@ -258,7 +258,8 @@ namespace hpp { ...@@ -258,7 +258,8 @@ namespace hpp {
protected: protected:
WaypointEdge (const std::string& name) : WaypointEdge (const std::string& name) :
Edge (name) Edge (name),
lastSucceeded_ (false)
{ {
} }
/// Initialization of the object. /// Initialization of the object.
...@@ -273,6 +274,7 @@ namespace hpp { ...@@ -273,6 +274,7 @@ namespace hpp {
States_t states_; States_t states_;
mutable matrix_t configs_; mutable matrix_t configs_;
mutable bool lastSucceeded_;
WaypointEdgeWkPtr_t wkPtr_; WaypointEdgeWkPtr_t wkPtr_;
}; // class WaypointEdge }; // class WaypointEdge
......
...@@ -336,32 +336,35 @@ namespace hpp { ...@@ -336,32 +336,35 @@ namespace hpp {
graph_.lock ()->robot ()->numberDof ()); graph_.lock ()->robot ()->numberDof ());
// Many times, this will be called rigth after WaypointEdge::applyConstraints so config_ // Many times, this will be called rigth after WaypointEdge::applyConstraints so config_
// already satisfies the constraints. // already satisfies the constraints.
size_type n = edges_.size() - 1; size_type n = edges_.size();
bool useCache = configs_.col(0).isApprox (q1) assert (configs_.cols() == n + 1);
&& configs_.col(n).isApprox (q2); bool useCache = lastSucceeded_
if (!useCache) { && configs_.col(0).isApprox (q1)
configs_.col(0) = q1; && configs_.col(n).isApprox (q2);
configs_.col(n) = q2; configs_.col(0) = q1;
} configs_.col(n) = q2;
for (std::size_t i = 0; i < edges_.size (); ++i) { for (size_type i = 0; i < n; ++i) {
if (!useCache) configs_.col (i+1) = q2; if (i < (n-1) && !useCache) configs_.col (i+1) = q2;
if (!edges_[i]->applyConstraints (configs_.col(i), configs_.col (i+1))) { if (i < (n-1) && !edges_[i]->applyConstraints (configs_.col(i), configs_.col (i+1))) {
hppDout (info, "Waypoint edge " << name() << ": applyConstraints failed at waypoint " << i << "." hppDout (info, "Waypoint edge " << name() << ": applyConstraints failed at waypoint " << i << "."
<< "\nUse cache: " << useCache << "\nUse cache: " << useCache
); );
lastSucceeded_ = false;
return false; return false;
} }
if (!edges_[i]->build (p, configs_.col(i), configs_.col (i+1))) { if (!edges_[i]->build (p, configs_.col(i), configs_.col (i+1))) {
hppDout (info, "Waypoint edge " << name() << ": build failed at waypoint " << i << "." hppDout (info, "Waypoint edge " << name() << ": build failed at waypoint " << i << "."
<< "\nUse cache: " << useCache << "\nUse cache: " << useCache
); );
lastSucceeded_ = false;
return false; return false;
} }
pv->appendPath (p); pv->appendPath (p);
} }
path = pv; path = pv;
lastSucceeded_ = true;
return true; return true;
} }
...@@ -373,10 +376,12 @@ namespace hpp { ...@@ -373,10 +376,12 @@ namespace hpp {
configs_.col (i+1) = q; configs_.col (i+1) = q;
if (!edges_[i]->applyConstraints (configs_.col(i), configs_.col (i+1))) { if (!edges_[i]->applyConstraints (configs_.col(i), configs_.col (i+1))) {
q = configs_.col(i+1); q = configs_.col(i+1);
lastSucceeded_ = false;
return false; return false;
} }
} }
q = configs_.col(edges_.size()); q = configs_.col(edges_.size());
lastSucceeded_ = true;
return true; return true;
} }
......
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