diff --git a/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py b/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py index a8f7d1ba786c..616fd215969a 100644 --- a/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py +++ b/source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py @@ -288,7 +288,21 @@ def start_simulation(cls) -> None: device = PhysicsManager._device logger.info(f"Finalizing model on device: {device}") cls._builder.up_axis = Axis.from_string(cls._up_axis) - # Set smaller contact margin for manipulation examples (default 10cm is too large) + + # WAR: USD import produces shapes with zero contact margin. Zero margin causes + # CCD to use the is_discrete path (epsilon=0), where GJK fails to converge on + # mesh terrain, producing NaN in body_q/joint_q. + # TODO: file upstream Newton issue for USD importer zero-margin default. + contact_margin = 0.01 + n_margin_fixed = 0 + for i in range(len(cls._builder.shape_margin)): + if cls._builder.shape_margin[i] == 0.0: + cls._builder.shape_margin[i] = contact_margin + n_margin_fixed += 1 + if n_margin_fixed > 0: + n_total = len(cls._builder.shape_margin) + logger.info(f"Set contact margin={contact_margin} on {n_margin_fixed}/{n_total} shapes with zero margin") + with Timer(name="newton_finalize_builder", msg="Finalize builder took:"): cls._model = cls._builder.finalize(device=device) cls._model.set_gravity(cls._gravity_vector) @@ -398,7 +412,12 @@ def _initialize_contacts(cls) -> None: if cls._needs_collision_pipeline: # Newton collision pipeline: create pipeline and generate contacts if cls._collision_pipeline is None: - cls._collision_pipeline = CollisionPipeline(cls._model, broad_phase="explicit") + # WAR: default max_triangle_pairs (1M) overflows with mesh terrain at + # 4096+ envs (~2M triangle pairs). Overflow silently drops contacts. + # No upstream issue tracking auto-sizing yet. + cls._collision_pipeline = CollisionPipeline( + cls._model, broad_phase="explicit", max_triangle_pairs=2_000_000 + ) if cls._contacts is None: cls._contacts = cls._collision_pipeline.contacts() diff --git a/source/isaaclab_newton/setup.py b/source/isaaclab_newton/setup.py index a2d0305ba84a..b6a1bf328e26 100644 --- a/source/isaaclab_newton/setup.py +++ b/source/isaaclab_newton/setup.py @@ -42,10 +42,10 @@ def run(self): EXTRAS_REQUIRE = { "all": [ "prettytable==3.3.0", - "mujoco==3.5.0", - "mujoco-warp==3.5.0.2", + "mujoco==3.6.0", + "mujoco-warp==3.6.0", "PyOpenGL-accelerate==3.1.10", - "newton==1.0.0", + "newton @ git+https://github.com/newton-physics/newton.git@141baffff9", ], } diff --git a/source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/config/anymal_d/rough_env_cfg.py b/source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/config/anymal_d/rough_env_cfg.py index 38d6b9d0546e..62b49729e647 100644 --- a/source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/config/anymal_d/rough_env_cfg.py +++ b/source/isaaclab_tasks/isaaclab_tasks/manager_based/locomotion/velocity/config/anymal_d/rough_env_cfg.py @@ -3,6 +3,10 @@ # # SPDX-License-Identifier: BSD-3-Clause +from isaaclab_newton.physics import MJWarpSolverCfg, NewtonCfg +from isaaclab_physx.physics import PhysxCfg + +from isaaclab.sim import SimulationCfg from isaaclab.utils import configclass from isaaclab_tasks.manager_based.locomotion.velocity.velocity_env_cfg import ( @@ -10,7 +14,7 @@ LocomotionVelocityRoughEnvCfg, StartupEventsCfg, ) -from isaaclab_tasks.utils import PresetCfg +from isaaclab_tasks.utils import PresetCfg, preset ## # Pre-defined configs @@ -18,6 +22,30 @@ from isaaclab_assets.robots.anymal import ANYMAL_D_CFG # isort: skip +@configclass +class RoughPhysicsCfg(PresetCfg): + default = PhysxCfg(gpu_max_rigid_patch_count=10 * 2**15) + # WAR: Rough terrain requires pyramidal cone — elliptic cone + high impratio diverges + # in float32 with many mesh contacts due to MuJoCo Warp single-precision limitations. + # Upstream (open): https://github.com/google-deepmind/mujoco_warp/issues/1000 + # Also uses Newton collision pipeline (use_mujoco_contacts=False) since MuJoCo's + # built-in collision does not support mesh terrain geometry. + newton = NewtonCfg( + solver_cfg=MJWarpSolverCfg( + njmax=200, + nconmax=100, + cone="pyramidal", + impratio=1.0, + integrator="implicitfast", + use_mujoco_contacts=False, + ccd_iterations=100, + ), + num_substeps=1, + debug_mode=False, + ) + physx = default + + @configclass class AnymalDPhysxEventsCfg(EventsCfg, StartupEventsCfg): pass @@ -32,6 +60,7 @@ class AnymalDEventsCfg(PresetCfg): @configclass class AnymalDRoughEnvCfg(LocomotionVelocityRoughEnvCfg): + sim: SimulationCfg = SimulationCfg(physics=RoughPhysicsCfg()) events: AnymalDEventsCfg = AnymalDEventsCfg() def __post_init__(self): @@ -39,6 +68,9 @@ def __post_init__(self): super().__post_init__() # switch robot to anymal-d self.scene.robot = ANYMAL_D_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot") + # RayCaster height scanner requires Kit (omni.physics) — disable for Newton. + self.scene.height_scanner = preset(default=self.scene.height_scanner, newton=None) + self.observations.policy.height_scan = preset(default=self.observations.policy.height_scan, newton=None) @configclass