How to add a Contact Sensor to a Pegasus Sim drone?

How do I add a Contact Sensor to a drone that meets the requirements of Pegasus Sim? This might seem like a silly or obvious question to ask, but what it boils down to is that the requirements of Pegasus Sim and Contact Sensors appear to be incompatible, or at least I can’t figure out the exact configuration that will allow them to work together.

I’ve tried to thoroughly document the problem, and what solutions I’ve already tried that haven’t worked. Apologies in advance for over-explaining everything, but this is a problem where the context and details are key.

I’m using:

  • Pegasus Sim 5.1.0
  • Isaac Sim 5.1.0
  • Ubuntu 24.04

Background

To fully understand the problem, I have to explain the requirements of Pegasus Sim and Contact Sensors/Isaac Sim

Note: Where I list the APIs connected to prims, I’ve shown only the obvious/relevant ones. For example, when you add a RigidBody property to a prim, you actually get both PhysicsRigidBodyAPI and PhysxRigidBodyAPI, so I’m only going to show the first of these rather than both all the time.

Pegasus Sim Requirements

Pegasus Sim is hard-coded to require a prim hierarchy that looks like this (using the default Iris drone as an example):

vehicle (defaultPrim)          | Xform
    body                       | Xform w/ RigidBodyAPI, MassAPI
        body                   | Mesh w/ ColliderAPI
    rotor1                     | Xform
        iris_prop_ccw          | Mesh w ColliderAPI
        joint0                 | PhysicsRevoluteJoint
    ...
    rotor3                     | Xform
        iris_prop_cw           | Mesh w ColliderAPI
        joint3                 | PhysicsRevoluteJoint

With the following requirements:

  1. body MUST be directly below vehicle. Isaac Sim will otherwise think the body Xform is invalid
  2. body MUST be an Xform, you can’t replace it with a mesh that has the rigid body, mass and collider APIs

Contact Sensor / Isaac Sim Requirements

Reading through the documentation around Contact Sensors in Isaac Sim 5.1.0 and the various related forum posts, I have determined that Contact Sensors require the following prim hierarchy:

collision_mesh                 | Mesh w/ RigidBodyAPI, ColliderAPI, ContactReporterAPI
    Contact Sensor             | Contact Sensor

With the following requirements:

  1. A Contact Sensor can only be added to a prim that has a RigidBody AND Collider API
  2. The Contact Sensor also requires that the parent prim has a ContactReporterAPI, but the option for adding it doesn’t even appear unless the mesh already has the RigidBody and Mass APIs
  3. A parent and child prim cannot both have RigidBodyAPIs, so you cannot place this collision mesh anywhere under body. Isaac Sim will throw all sorts of physics related warnings and errors.

Problem

Because of the requirements stated above, you can’t nest the collision mesh and it’s Contact Sensor anywhere below the body Xform, and you can’t modify the placement or configuration of the body Xform either. This limits you to putting it alongside body somehow.

If you start by just putting it at the same nested level, you get a hierarchy that looks like:

vehicle (defaultPrim)          | Xform
    body                       | Xform w/ RigidBodyAPI, MassAPI
        body                   | Mesh ColliderAPI
    collision_mesh             | Mesh w/ RigidBodyAPI, ColliderAPI, ContactReporterAPI
        Contact Sensor         | Contact Sensor

    ...rotors etc ....

However now you quickly start running into problems…

If you DON’T remove the ColliderAPI from the body mesh, then your drone and the collision_mesh will fly apart as soon as the simulation starts:

If you DO remove the ColliderAPI from body, the collision_mesh still doesn’t stay part of the drone, even though its nested under the same root prim:

If you instead use a FixedJoint to connect the collision_mesh prim to the body Xform or mesh, the whole drone now becomes immobile, won’t take off, and Ardupilot will throw a “loss of thrust” error. This problem has already been documented on the forum (Robot sliding: wheel has been spinning, but the robot not move…)

Any minor variation of what I’ve described above leads to the same outcomes - either the drone is immobilized or the two meshes aren’t connected.

So, with all of that said and done, what is the solution to this problem? How can I attach a Contact Sensor to this drone in a way that doesn’t break it?

Hello @matt.young,

Welcome to the Isaac ROS forum and thanks for the post!

The collider mesh does not need its own rigid body.

vehicle
└── body Xform: RigidBodyAPI, PhysxRigidBodyAPI, MassAPI, PhysxContactReportAPI
└── body Mesh: CollisionAPI
└── Contact_Sensor

You could keep the existing collider mesh and its parent rigid body.
Then add PhysxContactReportAPI to the outer body Xform. Select the inner body mesh and create the Contact Sensor. The sensor searches its ancestors for an enabled rigid body, so it can use the outer body Xform. Enable PhysxContactReportAPI on that Xform, keeping the mesh as its child collider. No additional rigid body or fixed joint is needed as designed in 5.1 source, where ContactSensor::findValidParent() searches ancestor prims for an enabled rigid body.

For initial testing, you might need to use radius=-1 and set the body’s physxRigidBody:sleepThreshold to 0 to keep it awake.

That works! Thanks a lot @vchuang!

To clarify for future readers, the mesh and contact sensor do need to be nested underneath each other, so the final hierarchy is:

vehicle (defaultPrim)          | Xform
    body                       | Xform w/ RigidBodyAPI, PhysxRigidBodyAPI, MassAPI, ContactReporterAPI
        body                   | Mesh w/  ColliderAPI
            Contact Sensor     | Contact Sensor

And then the documentation for Contact Sensor had the python code I needed to read the sensor during simulation.