|
21 | 21 | import carb |
22 | 22 | import pytest |
23 | 23 | from flaky import flaky |
| 24 | +from pxr import PhysxSchema |
24 | 25 |
|
25 | 26 | import isaaclab.sim as sim_utils |
26 | 27 | from isaaclab.assets import RigidObject, RigidObjectCfg |
@@ -395,6 +396,50 @@ def test_sensor_print(setup_simulation): |
395 | 396 | print(scene.sensors["contact_sensor"]) |
396 | 397 |
|
397 | 398 |
|
| 399 | +@pytest.mark.parametrize("device", ["cuda:0", "cpu"]) |
| 400 | +def test_contact_sensor_threshold(setup_simulation, device): |
| 401 | + """Test that the contact sensor USD threshold attribute is set to 0.0.""" |
| 402 | + sim_dt, durations, terrains, devices, carb_settings_iface = setup_simulation |
| 403 | + with build_simulation_context(device=device, dt=sim_dt, add_lighting=False) as sim: |
| 404 | + sim._app_control_on_stop_handle = None |
| 405 | + # Spawn things into stage |
| 406 | + scene_cfg = ContactSensorSceneCfg(num_envs=1, env_spacing=1.0, lazy_sensor_update=False) |
| 407 | + scene_cfg.terrain = FLAT_TERRAIN_CFG.replace(prim_path="/World/ground") |
| 408 | + scene_cfg.shape = CUBE_CFG |
| 409 | + scene_cfg.contact_sensor = ContactSensorCfg( |
| 410 | + prim_path=scene_cfg.shape.prim_path, |
| 411 | + track_pose=True, |
| 412 | + debug_vis=False, |
| 413 | + update_period=0.0, |
| 414 | + track_air_time=True, |
| 415 | + history_length=3, |
| 416 | + ) |
| 417 | + scene = InteractiveScene(scene_cfg) |
| 418 | + # Play the simulator |
| 419 | + sim.reset() |
| 420 | + |
| 421 | + # Get the stage and check the USD threshold attribute on the rigid body prim |
| 422 | + from isaacsim.core.utils.stage import get_current_stage |
| 423 | + |
| 424 | + stage = get_current_stage() |
| 425 | + prim_path = scene_cfg.shape.prim_path |
| 426 | + prim = stage.GetPrimAtPath(prim_path) |
| 427 | + |
| 428 | + # Ensure the contact sensor was created properly |
| 429 | + contact_sensor = scene["contact_sensor"] |
| 430 | + assert contact_sensor is not None, "Contact sensor was not created" |
| 431 | + |
| 432 | + # Check if the prim has contact report API and verify threshold is close to 0.0 |
| 433 | + if prim.HasAPI(PhysxSchema.PhysxContactReportAPI): |
| 434 | + cr_api = PhysxSchema.PhysxContactReportAPI.Get(stage, prim.GetPrimPath()) |
| 435 | + threshold_attr = cr_api.GetThresholdAttr() |
| 436 | + if threshold_attr.IsValid(): |
| 437 | + threshold_value = threshold_attr.Get() |
| 438 | + assert ( |
| 439 | + pytest.approx(threshold_value, abs=1e-6) == 0.0 |
| 440 | + ), f"Expected USD threshold to be close to 0.0, but got {threshold_value}" |
| 441 | + |
| 442 | + |
398 | 443 | """ |
399 | 444 | Internal helpers. |
400 | 445 | """ |
|
0 commit comments