flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.43k stars 417 forks source link

Help wanted: Constructing a CollisionObject from multiple primitives #511

Open tfachmann opened 3 years ago

tfachmann commented 3 years ago

I am using the fcl library as transition to have a better representation of collision objects. As I don't have a mesh for all of my objects (yet) I have used a collection of spheres with a given radius to approximate the collisions.

While switching to fcl, I now want to be able to represent both: a complete mesh and my previous (naive) method as FCL Objects. Is there a functionality to construct an CollisionObject which is the union of Spheres?

I have found fcl::generateBVHModel which appears to provide the functionality I need, but it didn't work as expected (maybe I just didn't understand it). I have used it as such:

typedef fcl::BVHModel<fcl::OBBRSSf> MeshModel;
// t_transformations describes a relative transformation to the center of the sphere,
// where all have the same radius t_radius
fcl::CollisionObjectf toFCL(const double t_radius, const std::vector<Eigen::Matrix4f>& t_transformations)
{
  std::shared_ptr<MeshModel> geom = std::make_shared<MeshModel>();
  for(size_t i = 0; i < t_transformations.size() - 1; ++i) {
    auto sphere = fcl::Spheref(t_radius);
    fcl::Transform3f trafo(t_transformations[i]);
    fcl::generateBVHModel(*geom, sphere, trafo, 32, fcl::FinalizeModel::DONT);
  }
  auto sphere = fcl::Spheref(t_radius);
  fcl::Transform3f trafo(t_transformations[i]);
  fcl::generateBVHModel(*geom, sphere, trafo, 32, fcl::FinalizeModel::DO);
  geom->computeVolume()   // == 0   (?)
  return fcl::CollisionObjectf(geom, fcl::Transform3f::Identity());
}

Am I using the interface correctly? If not, is it even possible to construct an CollisionObject from multiple primitives? If I'm using it correctly, I can elaborate further on what goes wrong / is unexpected.

ddengster commented 3 years ago

hi, i'm also trying to get things to work with multigeometry swept collision. How you're constructing the models seems to be correct (though you might want to know that the fcl::generateBVHModel function converts the circles to triangles and can be inefficient).

Now, on my setup with even just 1 box being added to the fcl::BVHModel<fcl::OBBRSSf> , then combined with a fcl::SplineMotion and tested for swept collision, i get an infinite loop with the distanceRecurse function here: https://github.com/flexible-collision-library/fcl/blob/master/include/fcl/narrowphase/detail/conservative_advancement_func_matrix-inl.h#L496 and it eventually results in a stack overflow exception. Are you doing something similar to this and getting the same results I have?

If someone could help in this area it would be great!

tfachmann commented 3 years ago

Hi, thanks for your feedback regarding the construction of the BVHModel geometry. For my use-case, I assume it would be best to not triangulate the spheres by constructing a mesh, but better hold a vector of fcl:Spheres instead to then check the collision against each sphere.

I was only using the fcl::collide() and fcl::distance() interface, where I have not encountered a stack overflow exception. My error was more on a semantic layer which I had blamed to the construction of the mesh. Thus, your error is probably something else.