Keys for contact bodies never set using ContactSensor and number of contacts never greater than 1

Isaac Sim Version

4.5.0
4.2.0
4.1.0
4.0.0
4.5.0
2023.1.1
2023.1.0-hotfix.1
Other (please specify):

Operating System

Ubuntu 22.04
Ubuntu 20.04
Windows 11
Windows 10
Other (please specify): Ubuntu 24.04

GPU Information

  • Model: NVIDIA GeForce RTX™ 4090 Laptop GPU
  • Driver Version: 550.144.03

Topic Description

Detailed Description

While trying to figure out how I can do simple collision checking in Isaac Sim or building upon Isaac Lab, I was exploring the ContactSensor class and followed the guide in the documentation. There, it is mentioned that the get_current_frame()method should return a dictionary with various entries. Among them: body0 and body1. However, in my test runs, these entries appear to be never created. I stepped with the debugger through the ContactSensor class and noticed that self._current_frame does not have contacts and thus, the body entries are never created. See lines 109 and following in contact_sensor.py:

if "contacts" in self._current_frame:
    self._current_frame["contacts"] = []
    for i in range(len(cs_raw_data)):
        contact_frame = dict()
        contact_frame["body0"] = self._contact_sensor_interface.decode_body_name(
            int(cs_raw_data["body0"][i])
        )
        contact_frame["body1"] = self._contact_sensor_interface.decode_body_name(
            int(cs_raw_data["body1"][i])
        )
        contact_frame["position"] = self._backend_utils.create_tensor_from_list(
            [
                cs_raw_data["position"][i][0],
                cs_raw_data["position"][i][1],
                cs_raw_data["position"][i][2],
            ],
            dtype="float32",
            device=self._device,
        )
        contact_frame["normal"] = self._backend_utils.create_tensor_from_list(
            [cs_raw_data["normal"][i][0], cs_raw_data["normal"][i][1], cs_raw_data["normal"][i][2]],
            dtype="float32",
            device=self._device,
        )
        contact_frame["impulse"] = self._backend_utils.create_tensor_from_list(
            [
                cs_raw_data["impulse"][i][0],
                cs_raw_data["impulse"][i][1],
                cs_raw_data["impulse"][i][2],
            ],
            dtype="float32",
            device=self._device,
        )
        self._current_frame["contacts"].append(contact_frame)

The remaining keys in that branch are never set as well (e.g., position or normal).

I’ve tested this with a single and two cubes. Furthermore, I observed that the number_of_contacts value never exceeds 1 even though I would expect 2 for a cube that is between the ground plane and has another cube lying on top. From one of the screenshots attached you can see which values are actually set.

Am I missing something or is this a bug?

Steps to Reproduce

This is the standalone script I’ve tested this with, note that I spawned a dome light using the Isaac Lab API, so you might need to change that.

from isaacsim import SimulationApp

simulation_app = SimulationApp({"headless": False})

import numpy as np
from isaacsim.core.api.objects import DynamicCuboid
from isaacsim.core.api.objects.ground_plane import GroundPlane
from isaacsim.core.api.physics_context import PhysicsContext

PhysicsContext()
GroundPlane(prim_path="/World/groundPlane", size=10, color=np.array([0.5, 0.5, 0.5]))
cube = DynamicCuboid(prim_path="/World/Cube",
    position=np.array([-.5, -.2, 1.0]),
    scale=np.array([.5, .5, .5]),
    color=np.array([.2,.3,0.]))

DynamicCuboid(prim_path="/World/Cube2",
    position=np.array([-.5, -.2, 2.0]),
    scale=np.array([.5, .5, .5]),
    color=np.array([.0,.2,0.3]))

from isaacsim.sensors.physics import ContactSensor
import numpy as np

sensor = ContactSensor(
    prim_path="/World/Cube/Contact_Sensor",
    name="Contact_Sensor",
    frequency=60,
    translation=np.array([0, 0, 0]),
    min_threshold=0,
    max_threshold=10000000,
    radius=-1
)

sensor2 = ContactSensor(
    prim_path="/World/Cube2/Contact_Sensor",
    name="Contact_Sensor",
    frequency=60,
    translation=np.array([0, 0, 0]),
    min_threshold=0,
    max_threshold=10000000,
    radius=-1
)

# Add dome light (from Isaac Lab API, replace if necessary)
import isaaclab.sim as sim_utils
light_cfg = sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75))
light_cfg.func("/World/Light", light_cfg)

# Run simulation
while simulation_app.is_running():
    sensor_data = sensor.get_current_frame()
    sensor_data2 = sensor2.get_current_frame()
    if 'number_of_contacts' in sensor_data and sensor_data['number_of_contacts'] > 0:
        print("Contact sensor data: ", sensor_data)
    if 'number_of_contacts' in sensor_data2 and sensor_data2['number_of_contacts'] > 0:
        print("Contact sensor data 2: ", sensor_data2)
    simulation_app.update()

Screenshots or Videos


Hi @Zacryon thanks for bringing up this issue! I am able to replicate the issue. Let me reach out to the internal team.

1 Like

Sorry for the delay but this should be fixed in Isaac sim 5.1.0

1 Like