Dectecting and saving contact points in collision Pychrono

215 views
Skip to first unread message

Declan Mulroy

unread,
Nov 14, 2019, 6:46:53 PM11/14/19
to ProjectChrono

Hello, 

Ive managed to collect and save Forces generated by collision however Im also trying to save the locations of those points of contact in the global frame using pychrono. I found this function in the core.py code but am not sure what it wants. Does it want the coordinate frame of the local object and global object or is this not even the correct function to use. I am also using EasyBodycylinders as well. 


   def GetContactPoint(self, loc_point, state_x):
        r"""GetContactPoint(ChBody self, ChVectorD loc_point, ChState state_x) -> ChVectorD"""
        return _core.ChBody_GetContactPoint(self, loc_point, state_x)

Thank you in advanced, 


Declan Mulroy

Radu Serban

unread,
Nov 15, 2019, 2:40:21 AM11/15/19
to projec...@googlegroups.com

Hi Declan,

That function (and several more) should not be in the public API -- they implement the interface to so-called ChContactable objects (objects that can generate contacts).  I will clean this up when I get a chance.

To report contact point locations use the contact reporting callback mechanism, by deriving your own reporter from ChContactContainer::ReportContactCallback.
See demo_python_2.py for an example and the documentation at (http://api.projectchrono.org/development/classchrono_1_1_ch_contact_container_1_1_report_contact_callback.html)

--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/d7d9b8c7-b4b8-47ab-a1b2-32a102c2beae%40googlegroups.com.

Declan Mulroy

unread,
Nov 17, 2019, 8:32:32 PM11/17/19
to ProjectChrono
I see. Thank Radu!

On Friday, November 15, 2019 at 1:40:21 AM UTC-6, Radu Serban wrote:

Hi Declan,

That function (and several more) should not be in the public API -- they implement the interface to so-called ChContactable objects (objects that can generate contacts).  I will clean this up when I get a chance.

To report contact point locations use the contact reporting callback mechanism, by deriving your own reporter from ChContactContainer::ReportContactCallback.
See demo_python_2.py for an example and the documentation at (http://api.projectchrono.org/development/classchrono_1_1_ch_contact_container_1_1_report_contact_callback.html)

--Radu


On 11/15/2019 12:46 AM, Declan Mulroy wrote:

Hello, 

Ive managed to collect and save Forces generated by collision however Im also trying to save the locations of those points of contact in the global frame using pychrono. I found this function in the core.py code but am not sure what it wants. Does it want the coordinate frame of the local object and global object or is this not even the correct function to use. I am also using EasyBodycylinders as well. 


   def GetContactPoint(self, loc_point, state_x):
        r"""GetContactPoint(ChBody self, ChVectorD loc_point, ChState state_x) -> ChVectorD"""
        return _core.ChBody_GetContactPoint(self, loc_point, state_x)

Thank you in advanced, 


Declan Mulroy
--
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 projec...@googlegroups.com.

Declan Mulroy

unread,
Dec 11, 2019, 3:28:12 PM12/11/19
to ProjectChrono
Hello Again, 

I went though the python_2.py demo and have been working off of that however im trying to be able to call on the point vA but it will not allow me to. I tried inserting an empty array but it was not working as well as have it return the variable vA which is the contact point location. 
How would I extract the contact point locations from the class or from the function getcontactcontainer in general. Below is the modified code I am working with which is essentialy python_2.py tutorial. 

Thank you in advanced,

Declan. 


class MyReportContactCallback(chrono.ReportContactCallback):
    def __init__(self):
         chrono.ReportContactCallback.__init__(self)
         
#    def OnReportContact(self,vA,vB,cA,dist,rad,force,torque,modA,modB):
#        
##        bodyUpA = chrono.CastContactableToChBody(modA)
##         nameA = bodyUpA.GetName()
##         bodyUpB = chrono.CastContactableToChBody(modB)
##         nameB = bodyUpB.GetName()
##         print ('  contact: point A=' , vA,  '  dist=',dist, 'Body A:', nameA, 'Body B:', nameB)
#        return True        # return False to stop reporting contacts


    def OnReportContact(self,vA,vB,cA,dist,rad,force,torque,modA,modB):
        
#        bodyUpA = chrono.CastContactableToChBody(modA)
#         nameA = bodyUpA.GetName()
#         bodyUpB = chrono.CastContactableToChBody(modB)
#         nameB = bodyUpB.GetName()
#         print ('  contact: point A=' , vA,  '  dist=',dist, 'Body A:', nameA, 'Body B:', nameB)
          return vA        # return False to stop reporting contacts

#

my_rep = MyReportContactCallback()




# Simulation loop
my_system.SetChTime(0)
while (my_system.GetChTime() < 1.2) :

    my_system.DoStepDynamics(0.01)

 #   print ('time=', my_system.GetChTime(), ' bodyB y=', my_shbodyB.GetPos().y)

    my_system.GetContactContainer().ReportAllContacts(my_rep)

On Friday, November 15, 2019 at 1:40:21 AM UTC-6, Radu Serban wrote:

Hi Declan,

That function (and several more) should not be in the public API -- they implement the interface to so-called ChContactable objects (objects that can generate contacts).  I will clean this up when I get a chance.

To report contact point locations use the contact reporting callback mechanism, by deriving your own reporter from ChContactContainer::ReportContactCallback.
See demo_python_2.py for an example and the documentation at (http://api.projectchrono.org/development/classchrono_1_1_ch_contact_container_1_1_report_contact_callback.html)

--Radu


On 11/15/2019 12:46 AM, Declan Mulroy wrote:

Hello, 

Ive managed to collect and save Forces generated by collision however Im also trying to save the locations of those points of contact in the global frame using pychrono. I found this function in the core.py code but am not sure what it wants. Does it want the coordinate frame of the local object and global object or is this not even the correct function to use. I am also using EasyBodycylinders as well. 


   def GetContactPoint(self, loc_point, state_x):
        r"""GetContactPoint(ChBody self, ChVectorD loc_point, ChState state_x) -> ChVectorD"""
        return _core.ChBody_GetContactPoint(self, loc_point, state_x)

Thank you in advanced, 


Declan Mulroy
--
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 projec...@googlegroups.com.

Radu Serban

unread,
Dec 15, 2019, 6:06:43 AM12/15/19
to ProjectChrono

 

Hi Declan,

 

I am not perfectly clear on what you mean by being “able to call on the point vA”, but you cannot have OnReportContact return it.  That method is called internally by ReportAllContacts and must return ‘true’ or ‘false’, informing the caller (ReportAllContacts) to continue processing the next contact or stop processing, respectively.

 

If you want to extract all vA points in a list, you can do something like:

 

class MyReportContactCallback(chrono.ReportContactCallback):

    def __init__(self):

        chrono.ReportContactCallback.__init__(self)

        self.points = []

    def OnReportContact(self,vA,vB,cA,dist,rad,force,torque,modA,modB):

        self.points.append(vA)

        return True        # return False to stop reporting contacts

    def ResetList(self):

        self.points = []

    def GetList(self):

        return self.points

 

my_rep = MyReportContactCallback()

 

while (my_system.GetChTime() < 1.2) :

    my_system.DoStepDynamics(0.01)

 

    my_rep.ResetList()

    my_system.GetContactContainer().ReportAllContacts(my_rep)

    crt_list = my_rep.GetList()

    print('time=', my_system.GetChTime(), ' num. contacts=', my_system.GetContactContainer().GetNcontacts())

    print(*crt_list, sep='\n')

 

Is this what you need?

--Radu

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/dd9ef760-c56d-4ae0-8ced-89e1f15b0e17%40googlegroups.com.

 

Declan Mulroy

unread,
Dec 15, 2019, 4:01:19 PM12/15/19
to Radu Serban, ProjectChrono
Yes That's exactly what I am looking for. To extract the points of contact and which bodies made contact. Thank you Radu!





--
--
Declan Mulroy
Direct: (847)-767-3222
Mechanical Engineering | Armour College of Engineering
Illinois Institute of Technology

Qihan Xuan

unread,
Jun 10, 2020, 1:08:20 PM6/10/20
to ProjectChrono
Hi,

Is it doable to write this code as C++?

Thanks,
Qihan

Radu Serban

unread,
Jun 10, 2020, 2:08:08 PM6/10/20
to projec...@googlegroups.com

Qihan,

Look at demo_IRR_callbackNSC (https://github.com/projectchrono/chrono/blob/develop/src/demos/irrlicht/demo_IRR_callbackNSC.cpp) and demo_IRR_callbackSMC (https://github.com/projectchrono/chrono/blob/develop/src/demos/irrlicht/demo_IRR_callbackSMC.cpp) for C++ examples of using contact reporting callbacks.

--Radu

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/809071a6-4065-4dda-a6e9-d40d543301fbo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages