Unverified Commit 7e8ebe67 authored by Kelly Guo's avatar Kelly Guo Committed by GitHub

Fixes contact threshold when activating contact sensor (#3498)

# Description

We were incorrectly passing in the activate contact sensor boolean as
the threshold when setting up the contact sensor API, which caused the
sensor threshold to always be 1 when the sensor is activated. The
desired behavior should be defaulting to 0 threshold.


## Type of change

- Bug fix (non-breaking change which fixes an issue)
- Breaking change (existing functionality will not work without user
modification)

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->

---------
Signed-off-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
Signed-off-by: 's avatarKelly Guo <kellyg@nvidia.com>
Co-authored-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
parent 23e935c3
[package] [package]
# Note: Semantic Versioning is used: https://semver.org/ # Note: Semantic Versioning is used: https://semver.org/
version = "0.47.11" version = "0.48.0"
# Description # Description
title = "Isaac Lab framework for Robot Learning" title = "Isaac Lab framework for Robot Learning"
......
Changelog Changelog
--------- ---------
0.48.0 (2025-11-03)
~~~~~~~~~~~~~~~~~~~
Changed
^^^^^^^
* Detected contacts are reported with the threshold of 0.0 (instead of 1.0). This increases the sensitivity of contact
detection.
Fixed
^^^^^
* Removed passing the boolean flag to :meth:`isaaclab.sim.schemas.activate_contact_sensors` when activating contact
sensors. This was incorrectly modifying the threshold attribute to 1.0 when contact sensors were activated.
0.47.11 (2025-11-03) 0.47.11 (2025-11-03)
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
...@@ -95,8 +111,8 @@ Changed ...@@ -95,8 +111,8 @@ Changed
0.47.3 (2025-10-22) 0.47.3 (2025-10-22)
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
Changed Fixed
^^^^^^^ ^^^^^
* Fixed the data type conversion in :class:`~isaaclab.sensors.tiled_camera.TiledCamera` to * Fixed the data type conversion in :class:`~isaaclab.sensors.tiled_camera.TiledCamera` to
support the correct data type when converting from numpy arrays to warp arrays on the CPU. support the correct data type when converting from numpy arrays to warp arrays on the CPU.
......
...@@ -288,7 +288,7 @@ def clone(func: Callable) -> Callable: ...@@ -288,7 +288,7 @@ def clone(func: Callable) -> Callable:
sem.GetSemanticDataAttr().Set(semantic_value) sem.GetSemanticDataAttr().Set(semantic_value)
# activate rigid body contact sensors # activate rigid body contact sensors
if hasattr(cfg, "activate_contact_sensors") and cfg.activate_contact_sensors: if hasattr(cfg, "activate_contact_sensors") and cfg.activate_contact_sensors:
schemas.activate_contact_sensors(prim_paths[0], cfg.activate_contact_sensors) schemas.activate_contact_sensors(prim_paths[0])
# clone asset using cloner API # clone asset using cloner API
if len(prim_paths) > 1: if len(prim_paths) > 1:
cloner = Cloner(stage=stage) cloner = Cloner(stage=stage)
......
...@@ -21,6 +21,7 @@ from enum import Enum ...@@ -21,6 +21,7 @@ from enum import Enum
import carb import carb
import pytest import pytest
from flaky import flaky from flaky import flaky
from pxr import PhysxSchema
import isaaclab.sim as sim_utils import isaaclab.sim as sim_utils
from isaaclab.assets import RigidObject, RigidObjectCfg from isaaclab.assets import RigidObject, RigidObjectCfg
...@@ -395,6 +396,50 @@ def test_sensor_print(setup_simulation): ...@@ -395,6 +396,50 @@ def test_sensor_print(setup_simulation):
print(scene.sensors["contact_sensor"]) print(scene.sensors["contact_sensor"])
@pytest.mark.parametrize("device", ["cuda:0", "cpu"])
def test_contact_sensor_threshold(setup_simulation, device):
"""Test that the contact sensor USD threshold attribute is set to 0.0."""
sim_dt, durations, terrains, devices, carb_settings_iface = setup_simulation
with build_simulation_context(device=device, dt=sim_dt, add_lighting=False) as sim:
sim._app_control_on_stop_handle = None
# Spawn things into stage
scene_cfg = ContactSensorSceneCfg(num_envs=1, env_spacing=1.0, lazy_sensor_update=False)
scene_cfg.terrain = FLAT_TERRAIN_CFG.replace(prim_path="/World/ground")
scene_cfg.shape = CUBE_CFG
scene_cfg.contact_sensor = ContactSensorCfg(
prim_path=scene_cfg.shape.prim_path,
track_pose=True,
debug_vis=False,
update_period=0.0,
track_air_time=True,
history_length=3,
)
scene = InteractiveScene(scene_cfg)
# Play the simulator
sim.reset()
# Get the stage and check the USD threshold attribute on the rigid body prim
from isaacsim.core.utils.stage import get_current_stage
stage = get_current_stage()
prim_path = scene_cfg.shape.prim_path
prim = stage.GetPrimAtPath(prim_path)
# Ensure the contact sensor was created properly
contact_sensor = scene["contact_sensor"]
assert contact_sensor is not None, "Contact sensor was not created"
# Check if the prim has contact report API and verify threshold is close to 0.0
if prim.HasAPI(PhysxSchema.PhysxContactReportAPI):
cr_api = PhysxSchema.PhysxContactReportAPI.Get(stage, prim.GetPrimPath())
threshold_attr = cr_api.GetThresholdAttr()
if threshold_attr.IsValid():
threshold_value = threshold_attr.Get()
assert (
pytest.approx(threshold_value, abs=1e-6) == 0.0
), f"Expected USD threshold to be close to 0.0, but got {threshold_value}"
""" """
Internal helpers. Internal helpers.
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment