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 boost::shared_ptr<fcl::Box> sample(
new fcl::Box(1, 1, 1));
54 model.
getBodyId(
"planar1_body"),joint_parent_1,
60 boost::shared_ptr<fcl::Box> sample2(
new fcl::Box(1, 1, 1));
64 model.
getBodyId(
"planar2_body"),joint_parent_2,
69 boost::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);
128 std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
129 std::vector < std::string > packageDirs;
131 packageDirs.push_back(meshDir);
135 GeometryModel geomModel;
140 BOOST_CHECK(geomModelOther == geomModel);
143 GeometryData geomData(geomModel);
144 fcl::CollisionResult result;
147 q << 0, 0, 0.840252, 0, 0, 0, 1, 0, 0, -0.3490658, 0.6981317, -0.3490658, 0, 0, 0, -0.3490658,
148 0.6981317, -0.3490658, 0, 0, 1.5, 0.6, -0.5, -1.05, -0.4, -0.3, -0.2, 0, 0, 0, 0,
149 1.5, -0.6, 0.5, 1.05, -0.4, -0.3, -0.2 ;
153 BOOST_CHECK(computeCollision(geomModel,geomData,idx) ==
false);
155 fcl::DistanceResult distance_res = computeDistance(geomModel,geomData,idx);
156 BOOST_CHECK(distance_res.min_distance > 0.);
165 std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
166 std::vector < std::string > package_dirs;
168 package_dirs.push_back(mesh_dir);
181 collision_map((Eigen::DenseIndex)cp.first,(Eigen::DenseIndex)cp.second) =
true;
185 GeometryModel geom_model_copy, geom_model_copy_lower;
221 GeometryData
geom_data(geom_model), geom_data_copy(geom_model), geom_data_copy_lower(geom_model);
222 geom_data_copy.deactivateAllCollisionPairs();
226 for(
size_t k = 0; k <
geom_data.activeCollisionPairs.size(); ++k)
229 collision_map((Eigen::DenseIndex)cp.first,(Eigen::DenseIndex)cp.second) =
geom_data.activeCollisionPairs[k];
233 geom_data_copy.setActiveCollisionPairs(geom_model, collision_map);
234 BOOST_CHECK(geom_data_copy.activeCollisionPairs ==
geom_data.activeCollisionPairs);
242 GeometryData geom_data_upper(geom_model), geom_data_lower(geom_model);
246 security_margin_map_upper.triangularView<Eigen::Lower>().
fill(0.);
248 geom_data_upper.setSecurityMargins(geom_model, security_margin_map);
249 for(
size_t k = 0; k < geom_data_upper.collisionRequests.size(); ++k)
251 BOOST_CHECK(geom_data_upper.collisionRequests[k].security_margin == 1.);
254 geom_data_lower.setSecurityMargins(geom_model, security_margin_map,
false);
255 for(
size_t k = 0; k < geom_data_lower.collisionRequests.size(); ++k)
257 BOOST_CHECK(geom_data_lower.collisionRequests[k].security_margin == 1.);
270 if(cp.first == 0 || cp.second == 0)
291 if(cp.first == 0 || cp.second == 0)
311 const std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
312 std::vector < std::string > packageDirs;
314 packageDirs.push_back(meshDir);
335 for(
size_t cp_index = 0; cp_index < geom_model.
collisionPairs.size(); ++cp_index)
341 hpp::fcl::CollisionResult other_res;
342 computeCollision(geom_model,geom_data,cp_index);
347 fcl::collide(obj1.geometry.get(), oM1,
348 obj2.geometry.get(), oM2,
349 geom_data.collisionRequests[cp_index],
352 const hpp::fcl::CollisionResult &
res = geom_data.collisionResults[cp_index];
354 BOOST_CHECK(res.isCollision() == other_res.isCollision());
355 BOOST_CHECK(!res.isCollision());
373 const std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
374 std::vector < std::string > packageDirs;
376 packageDirs.push_back(meshDir);
394 BOOST_CHECK(computeDistances(geom_model,geom_data) < geom_model.
collisionPairs.size());
399 BOOST_CHECK(computeDistances(model,data,geom_model,geom_data,q) < geom_model.
collisionPairs.size());
408 const std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
409 std::vector < std::string > packageDirs;
411 packageDirs.push_back(meshDir);
415 GeometryModel geom_model1;
418 GeometryModel geom_model2;
422 BOOST_CHECK(geom_model2.
ngeoms == 2*geom_model1.
ngeoms);
425 GeometryModel geom_model_empty;
427 BOOST_CHECK(geom_model_empty.
ngeoms == 0);
429 BOOST_CHECK(geom_model.
ngeoms== 0);
433 #if defined(PINOCCHIO_WITH_URDFDOM) && defined(PINOCCHIO_WITH_HPP_FCL) 436 std::vector < std::string > packageDirs;
438 std::string filename =
PINOCCHIO_MODEL_DIR + std::string(
"/example-robot-data/robots/romeo_description/urdf/romeo_small.urdf");
440 packageDirs.push_back(meshDir);
450 pinocchio::computeBodyRadius(model, geom, geomData);
451 BOOST_FOREACH(
double radius, geomData.radius) BOOST_CHECK(radius>=0.);
453 #endif // if defined(PINOCCHIO_WITH_URDFDOM) && defined(PINOCCHIO_WITH_HPP_FCL) 455 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.
FrameVector frames
Vector of operational frames registered on the model.
std::vector< bool > activeCollisionPairs
Vector of collision pairs.
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)
PairIndex findCollisionPair(const CollisionPair &pair) const
Return the index of a given collision pair in collisionPairs.
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.
void activateAllCollisionPairs()
Activate all collision pairs.
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
std::map< std::string, pinocchio::SE3 > JointPositionsMap_t
bool existCollisionPair(const CollisionPair &pair) const
Check if a collision pair exists in collisionPairs. See also findCollisitionPair(const CollisionPair ...
pinocchio::JointIndex JointIndex
FrameIndex getBodyId(const std::string &name) const
Return the index of a body given by its name.
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...
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 ...
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.
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
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.
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)