flexible-collision-library / fcl

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

Collision tolerance #527

Open dBierni opened 3 years ago

dBierni commented 3 years ago

Hi,

Is there any way to add tolerance to the fc::collide function? I mean, if the distance between two objects is smaller than "safety distance", then they are in a collision.

I just wonder if there is possible with fcl::collide? just not use the fcl::distance a then compare to the "safety distance

SeanCurtis-TRI commented 3 years ago

There isn't currently. You're not the first to request it. Currently, collide strictly looks for penetrating geometries. The algorithms are tuned so if cheap culling tests can prove no contact, the algorithm stops computing. Creating such a threshold would require redesigning all of the algorithms.

You're best off using the signed distance and set DistanceRequest::enable_signed_distance to true and set the distance value in the callback so that BVH culling can utilize that to ignore results that are obviously more separated than you care for.

dBierni commented 3 years ago

Ok, Thank you!

Should setting DistanceRequest::distance_tolerance makes calculation faster? - I am not sure if I understand what does it mean in practice "the threshold used in GJK algorithm to stop distance iteration ". Is it according to the GJK algorithm - the distance between simplex and origin?

florent-lamiraux commented 3 years ago

You can find an implementation of tolerance in this forked project: https://github.com/humanoid-path-planner/hpp-fcl. You can set the security margin here: https://github.com/humanoid-path-planner/hpp-fcl/blob/44c98b5258b3a2aa5518366b6331f86c104e19b5/include/hpp/fcl/collision_data.h#L210. This comes at negligible additional cost.

dBierni commented 3 years ago

@florent-lamiraux Thank you! Do you have any benchmarks? I mean, the difference between hpp::fcl::collide with security_margin and fcl::distance? For the easy example with 2 hpp::fcl::Box the fcl::distance performs better.

I need to check how it performs with meshes, as I see there is no support for BroadPhaseManager.

florent-lamiraux commented 3 years ago

No, we have no specific benchmark for that.

For simple geometries like boxes, distance and collision computations take almost the same time. The difference is visible with meshes. The collision test between bounding boxes returns a lower bound of the distance between the boxes with no additional computation. If this lower bound is greater than the security margin, we break the boxes.

Concerning broad phase, we only support collisions between pairs of objects in hpp-fcl. For multiple objects, kinematics chains and continuous collision checking, computations are done in hpp-core.

For more information, you can post an issue there describing precisely your needs.

jmirabel commented 3 years ago

To complete @florent-lamiraux's answer:

We didn't re-implement the collision functions for pairs of primitives shapes. Instead, we call the distance function. The difference you see between both is probably the overhead of converting the distance result into a collision result. For some of them, like box-box, it would indeed be beneficial to re-implement them, but for others it makes almost no difference (and twice less code).

If you want to re-implement the box-box collision function with a tolerance, we can provide guidelines. It is not a hard task.

dBierni commented 3 years ago

The test with boxes was just for fast check the hpp::fcl::collide. Normally I do collision checks with the meshes.

Test with meshes shows that hpp::fcl performs better than my current library, I will open an issue as I have few questions.