7 #include "pinocchio/multibody/model.hpp" 8 #include "pinocchio/multibody/data.hpp" 10 #include "pinocchio/multibody/geometry.hpp" 11 #include "pinocchio/algorithm/kinematics.hpp" 12 #include "pinocchio/algorithm/geometry.hpp" 13 #include "pinocchio/parsers/urdf.hpp" 14 #include "pinocchio/parsers/srdf.hpp" 17 #include <boost/test/unit_test.hpp> 24 typedef std::map <std::pair < std::string , std::string >, fcl::DistanceResult >
PairDistanceMap_t;
31 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
50 shared_ptr<fcl::Box> sample(
new fcl::Box(1, 1, 1));
54 model.
getBodyId(
"planar1_body"),joint_parent_1,
60 shared_ptr<fcl::Box> sample2(
new fcl::Box(1, 1, 1));
64 model.
getBodyId(
"planar2_body"),joint_parent_2,
69 shared_ptr<fcl::Box> universe_body_geometry(
new fcl::Box(1, 1, 1));
75 model.
getBodyId(
"universe_body"),joint_parent_3,
76 universe_body_geometry,universe_body_placement,
"", Eigen::Vector3d::Ones()),
87 std::cout <<
"------ Model ------ " << std::endl;
89 std::cout <<
"------ Geom ------ " << std::endl;
90 std::cout << geomModel;
91 std::cout <<
"------ DataGeom ------ " << std::endl;
92 std::cout << geomData;
99 BOOST_CHECK(geomData.oMg[idx_geom3].isApprox(universe_body_placement));
100 BOOST_CHECK(computeCollision(geomModel,geomData,0) ==
true);
106 BOOST_CHECK(computeCollision(geomModel,geomData,0) ==
false);
112 BOOST_CHECK(computeCollision(geomModel,geomData,0) ==
true);
118 BOOST_CHECK(computeCollision(geomModel,geomData,0) ==
false);
120 geomModel.removeGeometryObject(
"ff2_collision_object");
123 BOOST_CHECK(geomModel.ngeoms == 2);
124 BOOST_CHECK(geomModel.geometryObjects.size() == 2);
125 BOOST_CHECK(geomModel.collisionPairs.size() == 1);
126 BOOST_CHECK((geomModel.collisionPairs[0].first == 0 && geomModel.collisionPairs[0].second == 1) ||
127 (geomModel.collisionPairs[0].first == 1 && geomModel.collisionPairs[0].second == 0));
128 BOOST_CHECK(geomData.activeCollisionPairs.size() == 1);
129 BOOST_CHECK(geomData.distanceRequests.size() == 1);
130 BOOST_CHECK(geomData.distanceResults.size() == 1);
131 BOOST_CHECK(geomData.distanceResults.size() == 1);
132 BOOST_CHECK(geomData.collisionResults.size() == 1);
143 std::vector < std::string > packageDirs;
145 packageDirs.push_back(meshDir);
149 GeometryModel geomModel;
154 BOOST_CHECK(geomModelOther == geomModel);
157 GeometryData geomData(geomModel);
158 fcl::CollisionResult result;
161 q << 0, 0, 0.840252, 0, 0, 0, 1, 0, 0, -0.3490658, 0.6981317, -0.3490658, 0, 0, 0, -0.3490658,
162 0.6981317, -0.3490658, 0, 0, 1.5, 0.6, -0.5, -1.05, -0.4, -0.3, -0.2, 0, 0, 0, 0,
163 1.5, -0.6, 0.5, 1.05, -0.4, -0.3, -0.2 ;
167 BOOST_CHECK(computeCollision(geomModel,geomData,idx) ==
false);
169 fcl::DistanceResult distance_res = computeDistance(geomModel,geomData,idx);
170 BOOST_CHECK(distance_res.min_distance > 0.);
182 package_dirs.push_back(mesh_dir);
195 collision_map((Eigen::DenseIndex)cp.first,(Eigen::DenseIndex)cp.second) =
true;
199 GeometryModel geom_model_copy, geom_model_copy_lower;
235 GeometryData
geom_data(geom_model), geom_data_copy(geom_model), geom_data_copy_lower(geom_model);
236 geom_data_copy.deactivateAllCollisionPairs();
240 for(
size_t k = 0; k <
geom_data.activeCollisionPairs.size(); ++k)
243 collision_map((Eigen::DenseIndex)cp.first,(Eigen::DenseIndex)cp.second) =
geom_data.activeCollisionPairs[k];
247 geom_data_copy.setActiveCollisionPairs(geom_model, collision_map);
248 BOOST_CHECK(geom_data_copy.activeCollisionPairs ==
geom_data.activeCollisionPairs);
256 GeometryData geom_data_upper(geom_model), geom_data_lower(geom_model);
260 security_margin_map_upper.triangularView<Eigen::Lower>().
fill(0.);
262 geom_data_upper.setSecurityMargins(geom_model, security_margin_map);
263 for(
size_t k = 0; k < geom_data_upper.collisionRequests.size(); ++k)
265 BOOST_CHECK(geom_data_upper.collisionRequests[k].security_margin == 1.);
268 geom_data_lower.setSecurityMargins(geom_model, security_margin_map,
false);
269 for(
size_t k = 0; k < geom_data_lower.collisionRequests.size(); ++k)
271 BOOST_CHECK(geom_data_lower.collisionRequests[k].security_margin == 1.);
284 if(cp.first == 0 || cp.second == 0)
305 if(cp.first == 0 || cp.second == 0)
325 const std::string
filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
326 std::vector < std::string > packageDirs;
328 packageDirs.push_back(meshDir);
349 for(
size_t cp_index = 0; cp_index < geom_model.
collisionPairs.size(); ++cp_index)
356 computeCollision(geom_model,geom_data,cp_index);
361 fcl::collide(obj1.geometry.get(), oM1,
362 obj2.geometry.get(), oM2,
363 geom_data.collisionRequests[cp_index],
368 BOOST_CHECK(res.isCollision() == other_res.
isCollision());
369 BOOST_CHECK(!res.isCollision());
387 const std::string
filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
388 std::vector < std::string > packageDirs;
390 packageDirs.push_back(meshDir);
408 BOOST_CHECK(computeDistances(geom_model,geom_data) < geom_model.
collisionPairs.size());
413 BOOST_CHECK(computeDistances(model,data,geom_model,geom_data,q) < geom_model.
collisionPairs.size());
422 const std::string
filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
423 std::vector < std::string > packageDirs;
425 packageDirs.push_back(meshDir);
429 GeometryModel geom_model1;
432 GeometryModel geom_model2;
436 BOOST_CHECK(geom_model2.
ngeoms == 2*geom_model1.
ngeoms);
448 GeometryModel geom_model_empty;
450 BOOST_CHECK(geom_model_empty.
ngeoms == 0);
452 BOOST_CHECK(geom_model.
ngeoms== 0);
456 #if defined(PINOCCHIO_WITH_URDFDOM) && defined(PINOCCHIO_WITH_HPP_FCL) 459 std::vector < std::string > packageDirs;
463 packageDirs.push_back(meshDir);
473 pinocchio::computeBodyRadius(model, geom, geomData);
474 BOOST_FOREACH(
double radius, geomData.radius) BOOST_CHECK(radius>=0.);
476 #endif // if defined(PINOCCHIO_WITH_URDFDOM) && defined(PINOCCHIO_WITH_HPP_FCL) 478 BOOST_AUTO_TEST_SUITE_END ()
void loadReferenceConfigurations(ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const bool verbose=false)
Get the reference configurations of a given model associated to a SRDF file. It throws if the SRDF fi...
Eigen::Matrix< bool, Eigen::Dynamic, Eigen::Dynamic, Options > MatrixXb
Eigen::Matrix< bool, Eigen::Dynamic, Eigen::Dynamic, Options > MatrixXb
FrameIndex addJointFrame(const JointIndex &joint_index, int previous_frame_index=-1)
Add a joint to the frame tree.
std::vector< std::string > getBodiesList()
void removeCollisionPairs(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, GeometryModel &geom_model, const std::string &filename, const bool verbose=false)
Deactive all possible collision pairs mentioned in the SRDF file. It throws if the SRDF file is incor...
static InertiaTpl Random()
CollisionPairVector collisionPairs
Vector of collision pairs.
void appendGeometryModel(GeometryModel &geom_model1, const GeometryModel &geom_model2)
void deactivateAllCollisionPairs()
Deactivate all collision pairs.
bool existCollisionPair(const CollisionPair &pair) const
Check if a collision pair exists in collisionPairs. See also findCollisitionPair(const CollisionPair ...
FrameVector frames
Vector of operational frames registered on the model.
std::vector< bool > activeCollisionPairs
Vector of collision pairs.
PairIndex findCollisionPair(const CollisionPair &pair) const
Return the index of a given collision pair in collisionPairs.
void setActiveCollisionPairs(const GeometryModel &geom_model, const MatrixXb &collision_map, const bool upper=true)
Set the collision pair association from a given input array. Each entry of the input matrix defines t...
#define PINOCCHIO_MODEL_DIR
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
std::map< std::string, pinocchio::SE3 > GeometryPositionsMap_t
ConfigVectorMap referenceConfigurations
Map of reference configurations, indexed by user given names.
void setGeometryCollisionStatus(const GeometryModel &geom_model, const GeomIndex geom_id, bool enable_collision)
Enable or disable collision for the given geometry given by its geometry id with all the other geomet...
bool computeCollisions(const int num_threads, const GeometryModel &geom_model, GeometryData &geom_data, const bool stopAtFirstCollision=false)
JointPositionsMap_t fillPinocchioJointPositions(const pinocchio::Model &model, const pinocchio::Data &data)
pinocchio::FrameIndex FrameIndex
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name)
Add a joint to the kinematic tree with infinite bounds.
GeometryModel & buildGeom(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const std::string &filename, const GeometryType type, GeometryModel &geom_model, const std::vector< std::string > &package_paths=std::vector< std::string >(), ::hpp::fcl::MeshLoaderPtr mesh_loader=::hpp::fcl::MeshLoaderPtr())
Build The GeometryModel from a URDF file. Search for meshes in the directories specified by the user ...
void activateAllCollisionPairs()
Activate all collision pairs.
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
std::map< std::string, pinocchio::SE3 > JointPositionsMap_t
pinocchio::JointIndex JointIndex
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
Index ngeoms
The number of GeometryObjects.
void addAllCollisionPairs()
Add all possible collision pairs.
void setCollisionPairs(const MatrixXb &collision_map, const bool upper=true)
Set the collision pairs from a given input array. Each entry of the input matrix defines the activati...
hpp::fcl::Transform3f toFclTransform3f(const SE3 &m)
Main pinocchio namespace.
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
FrameIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.
std::map< std::string, pinocchio::SE3 > PositionsMap_t
GeometryPositionsMap_t fillPinocchioGeometryPositions(const pinocchio::GeometryModel &geomModel, const pinocchio::GeometryData &geomData)
void updateGeometryPlacements(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const GeometryModel &geom_model, GeometryData &geom_data, const Eigen::MatrixBase< ConfigVectorType > &q)
Apply a forward kinematics and update the placement of the geometry objects.
void appendBodyToJoint(const JointIndex joint_index, const Inertia &Y, const SE3 &body_placement=SE3::Identity())
Append a body to a given joint of the kinematic tree.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
JointCollectionTpl & model
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Options > MatrixXs
int nq
Dimension of the configuration vector representation.
JointModelPlanarTpl< double > JointModelPlanar
GeomIndex addGeometryObject(const GeometryObject &object, const ModelTpl< S2, O2, _JointCollectionTpl > &model)
Add a geometry object to a GeometryModel and set its parent joint.
BOOST_AUTO_TEST_CASE(simple_boxes)
std::map< std::pair< std::string, std::string >, fcl::DistanceResult > PairDistanceMap_t
Box(FCL_REAL x, FCL_REAL y, FCL_REAL z)
FrameIndex addBodyFrame(const std::string &body_name, const JointIndex &parentJoint, const SE3 &body_placement=SE3::Identity(), int previousFrame=-1)
Add a body to the frame tree.