Contact Reporting does not report

Hi,

I used the following code, as per the CodeReportingDemo to do contact reporting:

class ContactManager():
    def __init__(self):
        _contact_report_sub = get_physx_simulation_interface()\
                                .subscribe_contact_report_events(self._on_contact_report_event)
        self.state = None

    def _on_contact_report_event(contact_headers, contact_data):
        data = []
        for contact_header in contact_headers:
            print("Contact between two objects!", ch)
            # some code to add it to last state

And it was working fine on Friday. However, the same code doesn’t report anything today - and I have no idea what could have changed. So I added the following to the script editor to debug.

from pxr import Usd, UsdLux, UsdGeom, UsdShade, Sdf, Gf, Tf, Vt, UsdPhysics, PhysxSchema
from omni.physx.scripts.physicsUtils import *
from omni.physx import get_physx_interface, get_physx_simulation_interface
from omni.physx.bindings._physx import SimulationEvent
import omni.physxdemos as demo

def contact_report_event(ch,cd):
	ValueError("AHA!!!")
_contact_report_sub = get_physx_simulation_interface().subscribe_contact_report_events(contact_report_event)

And it doesn’t report (I ran it alongside the Leonardo demo with cube stacking, in which I expect panda-cube collisions and cube-table collisions)

Is it possible I somehow disabled the event subscription or some extension needs to be on?

I found a work-around by using get_physx_simulation_interface().get_contact_report() instead. It gives me the current state. It was not mentioned anywhere in the documentation though, I discovered it in ContactReportImmediateAPIDemo within kit>extPhysics → demos

Surprisingly, this work-around does not report all collisions either -
image

I simulated robot pick of brush (which is reported), collision of brush with shoe (not reported). The only difference between the shoe and the brush in terms of spawning is that the shoe is spawned via URDF while the Brush is a USD file.

Either via:


        result, prim_path = omni.kit.commands.execute( 
                "URDFParseAndImportFile", urdf_path=urdf_path,
                import_config=AssetManager.import_config,dest_path = dest_path)

        if "prim_path" in list(kwargs.keys()):
            prim_path = kwargs["prim_path"]
        else:
            prim_path = omni.usd.get_stage_next_free_path(
                omni.usd.get_context().get_stage(), 
                f'/World/{prim_name}', False
            )
        prim = add_asset_to_stage(dest_path, prim_name, prim_path, scene,
                            position =kwargs["position"]/get_stage_units(),
                            orientation = euler_angles_to_quat(orientation*np.pi/180),
                            orientation_euler = orientation,
                            scale = scale)

or via

        result, prim_path = omni.kit.commands.execute( 
                "URDFParseAndImportFile", urdf_path=urdf_path,
                import_config=AssetManager.import_config,dest_path = dest_path)

        if "prim_path" in list(kwargs.keys()):
            prim_path = kwargs["prim_path"]
        else:
            prim_path = omni.usd.get_stage_next_free_path(
                omni.usd.get_context().get_stage(), 
                f'/World/{prim_name}', False
            )
        prim = omni.usd.get_context().get_stage().OverridePrim(prim_path)
        prim.GetReferences().AddReference(dest_path)
        transform(prim_path, position, orientation, scale)

Both with same result.

The contact report only reports contact between /World/brush - /World/RPL_Franka/panda_rightfinger and
/World/brush - /World/RPL_Franka/panda_leftfinger, not with /World/demo_shoe. At some point in the pickup, also reported /World/RPL_Franka/panda_leftfinger - /World/defaultGroundPlane/GroundPlane/CollisionPlane

Finally, I figured out that importing from URDF through script does not add Contact Reporter API, while importing URDF via GUI does…>.< . FIXED in code (Note: using prim.prim because I have a custom prim type that encompasses RigidPrim)


        omni.kit.commands.execute('AddPhysicsComponent',
            usd_prim=prim.prim,
            component='ContactReportAPI')
        # omni.kit.commands.execute('ApplyAPISchema',
        #     api=<class 'pxr.PhysxSchema.PhysxContactReportAPI'>,
        #     prim=Usd.Prim(</World/Womens_Bluefish_2Eye_Boat_Shoe_in_White_Tumbled_YG44xIePRHw>))
        omni.kit.commands.execute('ChangeProperty',
            prop_path=Sdf.Path(f'{prim_path}.physxContactReport:threshold'),
            value=0.0,
            prev=1.0)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.