|
| 1 | +# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +"""Newton rigid--deformable physics for the shared Franka rope task.""" |
| 5 | + |
| 6 | +from __future__ import annotations |
| 7 | + |
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +from isaaclab.sim.spawners.from_files import UsdFileCfg, spawn_from_usd |
| 11 | +from isaaclab.sim.utils import clone |
| 12 | +from isaaclab_contrib.coupling import CouplerEntryCfg, CouplerProxyCfg, CouplerProxyMappingCfg |
| 13 | +from isaaclab_newton.physics import ( |
| 14 | + MJWarpSolverCfg, |
| 15 | + NewtonCfg, |
| 16 | + NewtonCollisionPipelineCfg, |
| 17 | + NewtonSoftContactCfg, |
| 18 | + VBDSolverCfg, |
| 19 | +) |
| 20 | + |
| 21 | +if TYPE_CHECKING: |
| 22 | + from pxr import Usd |
| 23 | + |
| 24 | + |
| 25 | +@clone |
| 26 | +def spawn_rope_franka_newton( |
| 27 | + prim_path: str, |
| 28 | + cfg: UsdFileCfg, |
| 29 | + translation: tuple[float, float, float] | None = None, |
| 30 | + orientation: tuple[float, float, float, float] | None = None, |
| 31 | + **kwargs, |
| 32 | +) -> Usd.Prim: |
| 33 | + """Use analytic finger colliders for stable volumetric rope contacts. |
| 34 | +
|
| 35 | + The boxes occupy the original collision meshes' bounds. Visual meshes and |
| 36 | + articulation joints remain those of the shared Franka. |
| 37 | +
|
| 38 | + Args: |
| 39 | + prim_path: Prim path or pattern at which to spawn the robot. |
| 40 | + cfg: Robot USD spawner configuration. |
| 41 | + translation: Translation relative to the parent [m]. |
| 42 | + orientation: Rotation quaternion in XYZW order. |
| 43 | + **kwargs: Additional arguments forwarded to the USD spawner. |
| 44 | +
|
| 45 | + Returns: |
| 46 | + The spawned robot prim. |
| 47 | + """ |
| 48 | + from pxr import Gf, UsdGeom |
| 49 | + |
| 50 | + prim = spawn_from_usd(prim_path, cfg, translation, orientation, **kwargs) |
| 51 | + for finger in ("panda_leftfinger", "panda_rightfinger"): |
| 52 | + collider = prim.GetStage().GetPrimAtPath(f"{prim.GetPath()}/{finger}/collisions/collisions") |
| 53 | + assert collider.IsValid() and collider.GetTypeName() == "Mesh", "Expected the legacy Franka finger collider" |
| 54 | + points = UsdGeom.Mesh(collider).GetPointsAttr().Get() |
| 55 | + lower = Gf.Vec3d(*(min(point[axis] for point in points) for axis in range(3))) |
| 56 | + upper = Gf.Vec3d(*(max(point[axis] for point in points) for axis in range(3))) |
| 57 | + collider.SetTypeName("Cube") |
| 58 | + cube = UsdGeom.Cube(collider) |
| 59 | + cube.CreateSizeAttr(1.0) |
| 60 | + cube.AddTranslateOp(opSuffix="rope_contact_center").Set((lower + upper) * 0.5) |
| 61 | + cube.AddScaleOp(opSuffix="rope_contact_size").Set(upper - lower) |
| 62 | + return prim |
| 63 | + |
| 64 | + |
| 65 | +@clone |
| 66 | +def spawn_rope_table_newton( |
| 67 | + prim_path: str, |
| 68 | + cfg: UsdFileCfg, |
| 69 | + translation: tuple[float, float, float] | None = None, |
| 70 | + orientation: tuple[float, float, float, float] | None = None, |
| 71 | + **kwargs, |
| 72 | +) -> Usd.Prim: |
| 73 | + """Use an analytic box for the Seattle table's existing unit-cube collider. |
| 74 | +
|
| 75 | + Args: |
| 76 | + prim_path: Prim path or pattern at which to spawn the table. |
| 77 | + cfg: Table USD spawner configuration. |
| 78 | + translation: Translation relative to the parent [m]. |
| 79 | + orientation: Rotation quaternion in XYZW order. |
| 80 | + **kwargs: Additional arguments forwarded to the USD spawner. |
| 81 | +
|
| 82 | + Returns: |
| 83 | + The spawned table prim. |
| 84 | + """ |
| 85 | + from pxr import UsdGeom |
| 86 | + |
| 87 | + prim = spawn_from_usd(prim_path, cfg, translation, orientation, **kwargs) |
| 88 | + collider = prim.GetStage().GetPrimAtPath(f"{prim.GetPath()}/Collisions/Cube") |
| 89 | + assert collider.IsValid() and collider.GetTypeName() == "Mesh", "Expected the Seattle table's cube mesh collider" |
| 90 | + collider.SetTypeName("Cube") |
| 91 | + UsdGeom.Cube(collider).CreateSizeAttr(1.0) |
| 92 | + return prim |
| 93 | + |
| 94 | + |
| 95 | +def rope_newton_physics_cfg() -> NewtonCfg: |
| 96 | + """Couple the Franka's rigid dynamics to the rope's volumetric VBD solve.""" |
| 97 | + return NewtonCfg( |
| 98 | + solver_cfg=CouplerProxyCfg( |
| 99 | + class_type="autodata_examples.envs.isaac_lab_arena.franka_rope.newton_visuals:NewtonRopeManager", |
| 100 | + entries=[ |
| 101 | + CouplerEntryCfg( |
| 102 | + name="rigid", |
| 103 | + solver_cfg=MJWarpSolverCfg(cone="elliptic", ls_iterations=20, integrator="implicitfast"), |
| 104 | + bodies=[r"/World/envs/env_[^/]+/Robot"], |
| 105 | + include_static_shapes=True, |
| 106 | + ), |
| 107 | + CouplerEntryCfg( |
| 108 | + name="soft", |
| 109 | + solver_cfg=VBDSolverCfg( |
| 110 | + iterations=10, |
| 111 | + rigid_body_particle_contact_buffer_size=4096, |
| 112 | + particle_enable_self_contact=True, |
| 113 | + particle_self_contact_radius=0.002, |
| 114 | + particle_self_contact_margin=0.003, |
| 115 | + ), |
| 116 | + all_particles=True, |
| 117 | + ), |
| 118 | + ], |
| 119 | + proxies=[ |
| 120 | + CouplerProxyMappingCfg( |
| 121 | + source="rigid", |
| 122 | + destination="soft", |
| 123 | + bodies=[ |
| 124 | + r"/World/envs/env_[^/]+/Robot/.*panda_hand", |
| 125 | + r"/World/envs/env_[^/]+/Robot/.*panda_(left|right)finger", |
| 126 | + ], |
| 127 | + mode="lagged", |
| 128 | + collide_interval=1, |
| 129 | + collision_pipeline=NewtonCollisionPipelineCfg(enable_rigid_soft_full_surface_contact=True), |
| 130 | + ), |
| 131 | + ], |
| 132 | + iterations=1, |
| 133 | + ), |
| 134 | + soft_contact_cfg=NewtonSoftContactCfg( |
| 135 | + # Resolve contacts around the narrow rope, with enough friction to carry it. |
| 136 | + soft_contact_ke=1.0e5, |
| 137 | + soft_contact_kd=10.0, |
| 138 | + soft_contact_mu=10.0, |
| 139 | + ), |
| 140 | + num_substeps=10, |
| 141 | + ) |
0 commit comments