Collision Detection Method for Multiple Bodies

92 views
Skip to first unread message

Andy Hansen

unread,
Oct 4, 2023, 5:12:53 PM10/4/23
to ProjectChrono
Hello,

I am trying to model an environment with a vehicle and many obstacles, which all have collisions enabled. I am trying to write a system to identify which bodies are colliding with one another at any given time, i.e. "Right now, the front left wheel is in contact with obstacle #47". 

I imagine it would be possible to estimate this using the bounding boxes for the bodies, but those are not always very precise for rounded shapes like wheels.

Is there any way to determine whether two bodies are currently colliding?

Thank you,

Andy 

Radu Serban

unread,
Oct 5, 2023, 1:55:03 AM10/5/23
to ProjectChrono

Hi Andy,

 

Many of the phases for collision detection and contact generation in Chrono provide callback mechanisms that allow the user to intervene in (or simply monitor) the process.

For example, during collision detection, you can provide callback classes of the following types:

 

Similarly, for contacts you can provide any of the following user-specified callbacks:

 

For the problem you describe, you can use any of ChCollisionSystem::NarrowphaseCallback, ChContactContainer::AddContactCallback, or ChContactContainer::ReportContactCallback as they will all allow you to monitor that two particular shapes will be involved in a contact.  The most natural one to use in your case is probably ChContactContainer::ReportContactCallback.  Look at the documentation, the implementation, or demos to figure out how exactly you can extract the information of the bodies containing the collision shapes from the arguments provided in the corresponding virtual functions that you would have to override in each case.  For an example of using ReportContactCallback, see demo_MBS_callbackNSC or demo_MBS_callbackSMC among others. These two demos also showcase the use of AddContactCallback.

 

If you want to be notified of a collision but not generate a contact for it (so piggybacking on the collision detection system to use it as a monitoring system for shape intersections), you can rely on the ChCollisionSystem::NarrowphaseCallback.  For an example of such use, see test_CTC_sentinel (this is in my own fork of the Chrono repository).  There, a collision is intercepted when it is discovered, but the custom callback function then flags not to generate a contact for it.  For a vehicle simulation, you could use this to monitor when the vehicle enters a particular region (of course, there are simpler ways of doing this outside the collision detection system, but if you have a complicated shape for the region this is an option).

 

--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/e7fe27a8-f0ba-4428-ae11-e49a99158cefn%40googlegroups.com.

Andy Hansen

unread,
Oct 5, 2023, 1:34:43 PM10/5/23
to ProjectChrono
Thank you for the assistance! I will investigate those methods.

Andy

Reply all
Reply to author
Forward
0 new messages