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

Fix bug: add collisions between robots from different URDF.

parent d4aae937
No related branches found
No related tags found
No related merge requests found
...@@ -63,6 +63,9 @@ namespace hpp { ...@@ -63,6 +63,9 @@ namespace hpp {
return os; return os;
} }
/// \name Accessors to container elements
/// \{
/// Get an element of a container /// Get an element of a container
template <typename Element> template <typename Element>
const Element& get (const std::string& name) const const Element& get (const std::string& name) const
...@@ -84,13 +87,34 @@ namespace hpp { ...@@ -84,13 +87,34 @@ namespace hpp {
Container <Element>::add (name, element); Container <Element>::add (name, element);
} }
/// \}
/// \name Collisions
/// \{
/// Cache joint vector
void prepareInsertRobot ()
{
didPrepare_ = true;
jointCache_ = getJointVector ();
}
/// Add collisions
/// between the joint vector cache initialized by prepareInsertRobot()
/// add the current Robot.
/// When creating a robot from several URDF files, this enables
/// collisions between joints from different files.
void didInsertRobot ();
/// \}
protected: protected:
/// Constructor /// Constructor
/// \param name of the new instance, /// \param name of the new instance,
/// \param robot Robots that manipulate objects, /// \param robot Robots that manipulate objects,
/// \param objects Set of objects manipulated by the robot. /// \param objects Set of objects manipulated by the robot.
Device (const std::string& name) : Device (const std::string& name) :
Parent_t (name) Parent_t (name), jointCache_ (), didPrepare_ (false)
{} {}
void init (const DeviceWkPtr_t& self) void init (const DeviceWkPtr_t& self)
...@@ -101,6 +125,9 @@ namespace hpp { ...@@ -101,6 +125,9 @@ namespace hpp {
private: private:
DeviceWkPtr_t self_; DeviceWkPtr_t self_;
model::JointVector_t jointCache_;
bool didPrepare_;
}; // class Device }; // class Device
} // namespace manipulation } // namespace manipulation
} // namespace hpp } // namespace hpp
......
...@@ -25,6 +25,7 @@ ADD_LIBRARY(${LIBRARY_NAME} SHARED ...@@ -25,6 +25,7 @@ ADD_LIBRARY(${LIBRARY_NAME} SHARED
manipulation-planner.cc manipulation-planner.cc
problem-solver.cc problem-solver.cc
roadmap.cc roadmap.cc
device.cc
graph-path-validation.cc graph-path-validation.cc
graph-steering-method.cc graph-steering-method.cc
......
///
/// Copyright (c) 2015 CNRS
/// Authors: Joseph Mirabel
///
///
// This file is part of hpp-manipulation.
// hpp-manipulation is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-manipulation is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-manipulation. If not, see
// <http://www.gnu.org/licenses/>.
#include <hpp/manipulation/device.hh>
#include <hpp/model/joint.hh>
namespace hpp {
namespace manipulation {
void Device::didInsertRobot ()
{
if (!didPrepare_) {
hppDout (error, "You must call prepareInsertRobot before.");
}
didPrepare_ = false;
/// Build list of new joints
const model::JointVector_t jv = getJointVector ();
model::JointVector_t newj;
model::JointVector_t::const_iterator retFind, it1, it2;
for (it1 = jv.begin (); it1 != jv.end (); ++it1) {
retFind = find (jointCache_.begin (), jointCache_.end (), *it1);
if (retFind == jointCache_.end ())
newj.push_back (*it1);
}
/// Add collision between old joints and new ones.
for (it1 = newj.begin (); it1 != newj.end (); ++it1) {
if (!(*it1)->linkedBody ()) continue;
for (it2 = jointCache_.begin (); it2 != jointCache_.end (); ++it2) {
if (!(*it2)->linkedBody ()) continue;
addCollisionPairs (*it1, *it2, model::COLLISION);
addCollisionPairs (*it1, *it2, model::DISTANCE);
}
}
jointCache_.clear ();
}
} // namespace manipulation
} // namespace hpp
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