Skip to content

Commit 5b3f070

Browse files
NeoZngooctipusAntoineRichard
authored
Include joint armature in PhysX and OvPhysX mass matrices (#8424)
# Description PhysX and OvPhysX simulate joint armature but omit it from their native mass-matrix queries. Include it once in each backend's cached articulation mass matrix, using public joint order and leaving floating-base rows untouched. PhysX copies the native result into its own output buffer before adding armature. The change is limited to `isaaclab_physx` and `isaaclab_ov`. Existing controllers and tasks consume the corrected matrix. Newton already includes armature upstream and needs no additional correction. Related: #8423 and [PhysX #575](NVIDIA-Omniverse/PhysX#575). ## Type of change - Bug fix ## Validation - Both new backend regressions failed before the fix and passed afterward. They cover reordered joints, floating-base offsets, repeated cached/refreshed reads, and preservation of PhysX's native query storage. - Focused OvPhysX dynamics checks: **5 passed**. - Focused PhysX checks: **1 passed, 1 existing xfail** (GPU mass/inertia writes take effect on the next step). - Repository formatting/lint hooks, changelog gate, and `git diff --check` passed. Independent review found no actionable issues. GPU validation used a reused uv environment with this worktree's source imports verified: Isaac Sim 6.2.0, OvPhysX 0.7.0.74035321, Warp 1.17.0, Torch 2.11.0+cu130, RTX 5090. Existing dependency/native warnings were observed. A separate native SDK check also confirmed that OvPhysX 0.7 still omits armature before this correction. ## Checklist - [x] I have read and understood the contribution guidelines. - [x] I have run the repository formatting and lint checks. - [x] I have validated the changed behavior with focused coverage and applied the test-audit criteria. - [x] I have added a changelog fragment for each touched package. - [x] My name already exists in `CONTRIBUTORS.md`. - [ ] My changes generate no new warnings (existing dependency/native warnings were observed). --------- Signed-off-by: Zeng Qingcheng <60593302+NeoZng@users.noreply.github.com> Co-authored-by: Octi Zhang <zhengyuz@nvidia.com> Co-authored-by: AntoineRichard <antoiner@nvidia.com>
1 parent 014b887 commit 5b3f070

9 files changed

Lines changed: 80 additions & 10 deletions

File tree

‎source/isaaclab/changelog.d/mass-matrix-armature.skip‎

Whitespace-only changes.

‎source/isaaclab/isaaclab/assets/articulation/base_articulation_data.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,10 @@ def mass_matrix(self) -> ProxyArray:
963963
``M(q)`` is symmetric positive-definite. ``M[i, j]`` is the coefficient
964964
relating DoF ``j``'s acceleration to the inertial torque on DoF ``i`` in
965965
``M(q) q_ddot + C(q, q_dot) q_dot + g(q) = tau``.
966+
967+
The joint armature (:attr:`joint_armature`) is included on the diagonal of the
968+
joint DoFs, so ``M(q)`` is the joint-space inertia the solver integrates. The
969+
floating-base DoFs carry no armature.
966970
"""
967971
raise NotImplementedError(f"{type(self).__name__} does not implement mass_matrix.")
968972

‎source/isaaclab/test/assets/contract/test_articulation_contract.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,11 @@ def test_ordering_reorders_public_dynamics_quantities(monkeypatch, backend, is_f
11981198
jacobian = jacobian.reshape(num_instances, num_jacobi_bodies, 6, num_dofs)
11991199
mass_matrix = np.arange(num_instances * num_dofs**2, dtype=np.float32).reshape(num_instances, num_dofs, num_dofs)
12001200
gravity = np.arange(num_instances * num_dofs, dtype=np.float32).reshape(num_instances, num_dofs)
1201+
# The PhysX backend adds joint armature to the mass-matrix diagonal; the mocks draw it at random, so share one.
1202+
armature = torch.arange(1, num_instances * num_joints + 1, dtype=torch.float32).reshape(num_instances, num_joints)
12011203
for art, raw_backend in ((identity_art, identity_raw), (ordered_art, ordered_raw)):
12021204
_set_body_state(backend, art, raw_backend, _make_body_state(num_instances, num_bodies))
1205+
art.write_joint_armature_to_sim_index(armature=armature)
12031206
if backend == "physx":
12041207
raw_backend.set_mock_jacobians(wp.array(jacobian, dtype=wp.float32, device="cpu"))
12051208
raw_backend.set_mock_generalized_mass_matrices(wp.array(mass_matrix, dtype=wp.float32, device="cpu"))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Included joint armature in OvPhysX articulation mass matrices used by inertia-based controllers.

‎source/isaaclab_ov/isaaclab_ov/assets/articulation/articulation_data.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,11 @@ def mass_matrix(self) -> ProxyArray:
11451145
)
11461146
else:
11471147
self._binding_read(TT.MASS_MATRIX, self._mass_matrix.data.warp)
1148+
# PhysX mass-matrix queries omit the joint armature used by the solver (PhysX#575).
1149+
# TODO: Remove once PhysX#575 is fixed upstream, or armature will be counted twice.
1150+
self._mass_matrix.data.torch.diagonal(dim1=-2, dim2=-1)[:, self._num_base_dofs :].add_(
1151+
self.joint_armature.torch
1152+
)
11481153
self._mass_matrix.timestamp = self._sim_timestamp
11491154
return self._mass_matrix.data
11501155

‎source/isaaclab_ov/test/assets/test_articulation.py‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,18 +1345,38 @@ def assert_dynamics_match(jacobian: bool = True, gravity: bool = True) -> None:
13451345
assert data._gravity_compensation_forces.timestamp < data._sim_timestamp
13461346
assert_dynamics_match(jacobian=False)
13471347

1348-
# Inertia and armature each affect only the generalized mass matrix.
1348+
# Inertia affects only the generalized mass matrix.
13491349
inertias = data.body_inertia.torch.clone()
13501350
inertias[:, -1, [0, 4, 8]] *= 1.1
13511351
articulation.set_inertias_index(inertias=inertias)
13521352
assert data._mass_matrix.timestamp < data._sim_timestamp
13531353
assert_dynamics_match(jacobian=False, gravity=False)
13541354

1355-
armature = data.joint_armature.torch.clone()
1356-
armature[:, -1] += 0.01
1357-
articulation.write_joint_armature_to_sim_index(armature=armature)
1358-
assert data._mass_matrix.timestamp < data._sim_timestamp
1359-
assert_dynamics_match(jacobian=False, gravity=False)
1355+
1356+
@pytest.mark.parametrize("scene", _CUDA_SCENES, indirect=True)
1357+
def test_joint_armature_updates_mass_matrix_without_accumulating(scene: _ArticulationScene) -> None:
1358+
"""Armature adds joint inertia in public order without changing the leading floating-base inertia."""
1359+
for articulation in (scene.islands["dynamics"], scene.islands["floating"]):
1360+
data = articulation.data
1361+
original_armature = data.joint_armature.torch.clone()
1362+
before = data.mass_matrix.torch.clone()
1363+
increment = 0.125 * torch.arange(
1364+
1, original_armature.numel() + 1, device=scene.device, dtype=original_armature.dtype
1365+
).reshape_as(original_armature)
1366+
expected_change = torch.zeros_like(before)
1367+
joint_dofs = articulation.num_base_dofs + torch.arange(articulation.num_joints, device=scene.device)
1368+
expected_change[:, joint_dofs, joint_dofs] = increment
1369+
try:
1370+
articulation.write_joint_armature_to_sim_index(armature=original_armature + increment)
1371+
after = data.mass_matrix.torch.clone()
1372+
torch.testing.assert_close(after - before, expected_change, atol=1e-5, rtol=1e-5)
1373+
torch.testing.assert_close(data.mass_matrix.torch, after)
1374+
1375+
# Advancing the cache timestamp without stepping preserves the pose and must not add armature again.
1376+
articulation.update(scene.sim.cfg.dt)
1377+
torch.testing.assert_close(data.mass_matrix.torch, after)
1378+
finally:
1379+
articulation.write_joint_armature_to_sim_index(armature=original_armature)
13601380

13611381

13621382
@pytest.mark.parametrize("scene", _CUDA_SCENES, indirect=True)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Included joint armature in PhysX articulation mass matrices used by inertia-based controllers.

‎source/isaaclab_physx/isaaclab_physx/assets/articulation/articulation_data.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,9 @@ def mass_matrix(self) -> ProxyArray:
10611061
"""See :attr:`isaaclab.assets.BaseArticulationData.mass_matrix`."""
10621062
if self._mass_matrix.timestamp < self._sim_timestamp:
10631063
source = self._root_view.get_generalized_mass_matrices()
1064+
if self._mass_matrix.data is None:
1065+
self._mass_matrix.data = ProxyArray(wp.empty_like(source))
10641066
if self.has_joint_ordering or self._has_reversed_joints:
1065-
if self._mass_matrix.data is None:
1066-
self._mass_matrix.data = ProxyArray(wp.empty_like(source))
10671067
self._read_launch_cache.launch(
10681068
"mass_matrix",
10691069
wp.launch,
@@ -1078,8 +1078,13 @@ def mass_matrix(self) -> ProxyArray:
10781078
],
10791079
outputs=[self._mass_matrix.data],
10801080
)
1081-
elif self._mass_matrix.data is None:
1082-
self._mass_matrix.data = ProxyArray(source)
1081+
else:
1082+
wp.copy(self._mass_matrix.data.warp, source)
1083+
# PhysX mass-matrix queries omit the joint armature used by the solver (PhysX#575).
1084+
# TODO: Remove once PhysX#575 is fixed upstream, or armature will be counted twice.
1085+
self._mass_matrix.data.torch.diagonal(dim1=-2, dim2=-1)[:, self._num_base_dofs :].add_(
1086+
self.joint_armature.torch
1087+
)
10831088
self._mass_matrix.timestamp = self._sim_timestamp
10841089
return self._mass_matrix.data
10851090

‎source/isaaclab_physx/test/assets/test_articulation.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,37 @@ def test_fixed_tendon_position_target_writes_offset(articulation_scene: _Articul
12271227
torch.testing.assert_close(wp.to_torch(articulation.root_view.get_fixed_tendon_offsets()).to(device), offset)
12281228

12291229

1230+
@pytest.mark.isaacsim_ci
1231+
def test_joint_armature_updates_mass_matrix_without_accumulating(articulation_scene: _ArticulationScene) -> None:
1232+
"""Armature adds joint inertia in public order without changing base inertia or native query storage."""
1233+
scene = articulation_scene
1234+
for articulation in (scene.ordered, scene.floating):
1235+
data = articulation.data
1236+
original_armature = data.joint_armature.torch.clone()
1237+
before = data.mass_matrix.torch.clone()
1238+
increment = 0.125 * torch.arange(
1239+
1, original_armature.numel() + 1, device=scene.device, dtype=original_armature.dtype
1240+
).reshape_as(original_armature)
1241+
expected_change = torch.zeros_like(before)
1242+
joint_dofs = articulation.num_base_dofs + torch.arange(articulation.num_joints, device=scene.device)
1243+
expected_change[:, joint_dofs, joint_dofs] = increment
1244+
try:
1245+
articulation.write_joint_armature_to_sim_index(armature=original_armature + increment)
1246+
native = wp.to_torch(articulation.root_view.get_generalized_mass_matrices())
1247+
native_before = native.clone()
1248+
after = data.mass_matrix.torch.clone()
1249+
torch.testing.assert_close(after - before, expected_change, atol=1e-5, rtol=1e-5)
1250+
torch.testing.assert_close(data.mass_matrix.torch, after)
1251+
torch.testing.assert_close(native, native_before, atol=0.0, rtol=0.0)
1252+
1253+
# Advancing the cache timestamp without stepping preserves the pose and must not add armature again.
1254+
articulation.update(scene.sim.cfg.dt)
1255+
torch.testing.assert_close(data.mass_matrix.torch, after)
1256+
torch.testing.assert_close(native, native_before, atol=0.0, rtol=0.0)
1257+
finally:
1258+
articulation.write_joint_armature_to_sim_index(armature=original_armature)
1259+
1260+
12301261
@pytest.mark.xfail(strict=True, reason="GPU PhysX applies mass and inertia writes on the next step")
12311262
def test_inertial_writes_refresh_the_mass_matrix(articulation_scene: _ArticulationScene) -> None:
12321263
"""Mass and inertia writes refresh a mass matrix that was already read in the same step."""

0 commit comments

Comments
 (0)