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:
* ChCollisionSystem::BroadphaseCallback<https://api.projectchrono.org/classchrono_1_1collision_1_1_ch_collision_system_1_1_broadphase_callback.html>, to be notified of “near enough” pairs of collision models found by the broadphase algorithm that are about to be included in the list of potential collisions. * ChCollisionSystem::NarrowphaseCallback<https://api.projectchrono.org/classchrono_1_1collision_1_1_ch_collision_system_1_1_narrowphase_callback.html>, to be notified of actual collisions happening and allow the user to perform various actions (including overriding geometric information for a collision, but also using the collision detection as a monitoring system). * ChCollisionSystem::VisualizationCallback<https://api.projectchrono.org/classchrono_1_1collision_1_1_ch_collision_system_1_1_visualization_callback.html>, to allow user-provided visualization of a contact. Similarly, for contacts you can provide any of the following user-specified callbacks: * ChContactContainer::AddContactCallback<https://api.projectchrono.org/classchrono_1_1_ch_contact_container_1_1_add_contact_callback.html>, to be notified whenever a new contact is being added to the system (and, optionally, change the contact material properties). * ChContactContainer::ReportContactCallback<https://api.projectchrono.org/classchrono_1_1_ch_contact_container_1_1_report_contact_callback.html>, to be notified of all contacts that were added to the system (as the name suggests, for reporting purposes as no other action is possible at that time). 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<https://github.com/projectchrono/chrono/blob/main/src/demos/mbs/demo_MBS_callbackNSC.cpp> or demo_MBS_callbackSMC<https://github.com/projectchrono/chrono/blob/main/src/demos/mbs/demo_MBS_callbackSMC.cpp> 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<https://github.com/rserban/chrono/blob/main/src/projects/contact/sequential/test_CTC_sentinel.cpp> (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 From: [email protected] <[email protected]> On Behalf Of Andy Hansen Sent: Wednesday, October 4, 2023 11:13 PM To: ProjectChrono <[email protected]> Subject: [chrono] Collision Detection Method for Multiple Bodies 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 -- 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 [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/e7fe27a8-f0ba-4428-ae11-e49a99158cefn%40googlegroups.com<https://groups.google.com/d/msgid/projectchrono/e7fe27a8-f0ba-4428-ae11-e49a99158cefn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/PH0PR06MB8237ED7E16D9DBF317D28393A7CAA%40PH0PR06MB8237.namprd06.prod.outlook.com.
