Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ def mass_matrix(self) -> ProxyArray:
``M(q)`` is symmetric positive-definite. ``M[i, j]`` is the coefficient
relating DoF ``j``'s acceleration to the inertial torque on DoF ``i`` in
``M(q) q_ddot + C(q, q_dot) q_dot + g(q) = tau``.

The joint armature (:attr:`joint_armature`) is included on the diagonal of the
joint DoFs, so ``M(q)`` is the joint-space inertia the solver integrates. The
floating-base DoFs carry no armature.
"""
raise NotImplementedError(f"{type(self).__name__} does not implement mass_matrix.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,11 @@ def test_ordering_reorders_public_dynamics_quantities(monkeypatch, backend, is_f
jacobian = jacobian.reshape(num_instances, num_jacobi_bodies, 6, num_dofs)
mass_matrix = np.arange(num_instances * num_dofs**2, dtype=np.float32).reshape(num_instances, num_dofs, num_dofs)
gravity = np.arange(num_instances * num_dofs, dtype=np.float32).reshape(num_instances, num_dofs)
# The PhysX backend adds joint armature to the mass-matrix diagonal; the mocks draw it at random, so share one.
armature = torch.arange(1, num_instances * num_joints + 1, dtype=torch.float32).reshape(num_instances, num_joints)
for art, raw_backend in ((identity_art, identity_raw), (ordered_art, ordered_raw)):
_set_body_state(backend, art, raw_backend, _make_body_state(num_instances, num_bodies))
art.write_joint_armature_to_sim_index(armature=armature)
if backend == "physx":
raw_backend.set_mock_jacobians(wp.array(jacobian, dtype=wp.float32, device="cpu"))
raw_backend.set_mock_generalized_mass_matrices(wp.array(mass_matrix, dtype=wp.float32, device="cpu"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Included joint armature in OvPhysX articulation mass matrices used by inertia-based controllers.
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,11 @@ def mass_matrix(self) -> ProxyArray:
)
else:
self._binding_read(TT.MASS_MATRIX, self._mass_matrix.data.warp)
# PhysX mass-matrix queries omit the joint armature used by the solver (PhysX#575).
# TODO: Remove once PhysX#575 is fixed upstream, or armature will be counted twice.
self._mass_matrix.data.torch.diagonal(dim1=-2, dim2=-1)[:, self._num_base_dofs :].add_(
self.joint_armature.torch
)
self._mass_matrix.timestamp = self._sim_timestamp
return self._mass_matrix.data

Expand Down
32 changes: 26 additions & 6 deletions source/isaaclab_ov/test/assets/test_articulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,18 +1345,38 @@ def assert_dynamics_match(jacobian: bool = True, gravity: bool = True) -> None:
assert data._gravity_compensation_forces.timestamp < data._sim_timestamp
assert_dynamics_match(jacobian=False)

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

armature = data.joint_armature.torch.clone()
armature[:, -1] += 0.01
articulation.write_joint_armature_to_sim_index(armature=armature)
assert data._mass_matrix.timestamp < data._sim_timestamp
assert_dynamics_match(jacobian=False, gravity=False)

@pytest.mark.parametrize("scene", _CUDA_SCENES, indirect=True)
def test_joint_armature_updates_mass_matrix_without_accumulating(scene: _ArticulationScene) -> None:
"""Armature adds joint inertia in public order without changing the leading floating-base inertia."""
for articulation in (scene.islands["dynamics"], scene.islands["floating"]):
data = articulation.data
original_armature = data.joint_armature.torch.clone()
before = data.mass_matrix.torch.clone()
increment = 0.125 * torch.arange(
1, original_armature.numel() + 1, device=scene.device, dtype=original_armature.dtype
).reshape_as(original_armature)
expected_change = torch.zeros_like(before)
joint_dofs = articulation.num_base_dofs + torch.arange(articulation.num_joints, device=scene.device)
expected_change[:, joint_dofs, joint_dofs] = increment
try:
articulation.write_joint_armature_to_sim_index(armature=original_armature + increment)
after = data.mass_matrix.torch.clone()
torch.testing.assert_close(after - before, expected_change, atol=1e-5, rtol=1e-5)
torch.testing.assert_close(data.mass_matrix.torch, after)

# Advancing the cache timestamp without stepping preserves the pose and must not add armature again.
articulation.update(scene.sim.cfg.dt)
torch.testing.assert_close(data.mass_matrix.torch, after)
finally:
articulation.write_joint_armature_to_sim_index(armature=original_armature)


@pytest.mark.parametrize("scene", _CUDA_SCENES, indirect=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Included joint armature in PhysX articulation mass matrices used by inertia-based controllers.
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,9 @@ def mass_matrix(self) -> ProxyArray:
"""See :attr:`isaaclab.assets.BaseArticulationData.mass_matrix`."""
if self._mass_matrix.timestamp < self._sim_timestamp:
source = self._root_view.get_generalized_mass_matrices()
if self._mass_matrix.data is None:
self._mass_matrix.data = ProxyArray(wp.empty_like(source))
if self.has_joint_ordering or self._has_reversed_joints:
if self._mass_matrix.data is None:
self._mass_matrix.data = ProxyArray(wp.empty_like(source))
self._read_launch_cache.launch(
"mass_matrix",
wp.launch,
Expand All @@ -1078,8 +1078,13 @@ def mass_matrix(self) -> ProxyArray:
],
outputs=[self._mass_matrix.data],
)
elif self._mass_matrix.data is None:
self._mass_matrix.data = ProxyArray(source)
else:
wp.copy(self._mass_matrix.data.warp, source)
# PhysX mass-matrix queries omit the joint armature used by the solver (PhysX#575).
# TODO: Remove once PhysX#575 is fixed upstream, or armature will be counted twice.
self._mass_matrix.data.torch.diagonal(dim1=-2, dim2=-1)[:, self._num_base_dofs :].add_(
self.joint_armature.torch
)
self._mass_matrix.timestamp = self._sim_timestamp
return self._mass_matrix.data

Expand Down
31 changes: 31 additions & 0 deletions source/isaaclab_physx/test/assets/test_articulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,37 @@ def test_fixed_tendon_position_target_writes_offset(articulation_scene: _Articul
torch.testing.assert_close(wp.to_torch(articulation.root_view.get_fixed_tendon_offsets()).to(device), offset)


@pytest.mark.isaacsim_ci
def test_joint_armature_updates_mass_matrix_without_accumulating(articulation_scene: _ArticulationScene) -> None:
"""Armature adds joint inertia in public order without changing base inertia or native query storage."""
scene = articulation_scene
for articulation in (scene.ordered, scene.floating):
data = articulation.data
original_armature = data.joint_armature.torch.clone()
before = data.mass_matrix.torch.clone()
increment = 0.125 * torch.arange(
1, original_armature.numel() + 1, device=scene.device, dtype=original_armature.dtype
).reshape_as(original_armature)
expected_change = torch.zeros_like(before)
joint_dofs = articulation.num_base_dofs + torch.arange(articulation.num_joints, device=scene.device)
expected_change[:, joint_dofs, joint_dofs] = increment
try:
articulation.write_joint_armature_to_sim_index(armature=original_armature + increment)
native = wp.to_torch(articulation.root_view.get_generalized_mass_matrices())
native_before = native.clone()
after = data.mass_matrix.torch.clone()
torch.testing.assert_close(after - before, expected_change, atol=1e-5, rtol=1e-5)
torch.testing.assert_close(data.mass_matrix.torch, after)
torch.testing.assert_close(native, native_before, atol=0.0, rtol=0.0)

# Advancing the cache timestamp without stepping preserves the pose and must not add armature again.
articulation.update(scene.sim.cfg.dt)
torch.testing.assert_close(data.mass_matrix.torch, after)
torch.testing.assert_close(native, native_before, atol=0.0, rtol=0.0)
finally:
articulation.write_joint_armature_to_sim_index(armature=original_armature)


@pytest.mark.xfail(strict=True, reason="GPU PhysX applies mass and inertia writes on the next step")
def test_inertial_writes_refresh_the_mass_matrix(articulation_scene: _ArticulationScene) -> None:
"""Mass and inertia writes refresh a mass matrix that was already read in the same step."""
Expand Down
Loading