Skip to content

Commit f9faae3

Browse files
committed
Compose joint armature explicitly in inertia-based control
1 parent 07daf44 commit f9faae3

11 files changed

Lines changed: 34 additions & 10 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Added joint armature explicitly to the mass matrix used by operational space control while keeping the articulation mass matrix as rigid-body inertia.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,15 +946,15 @@ def body_com_jacobian_w(self) -> ProxyArray:
946946

947947
@property
948948
def mass_matrix(self) -> ProxyArray:
949-
"""Per-env generalized mass matrix ``M(q)`` in joint space.
949+
"""Per-env rigid-body mass matrix ``M_body(q)`` in joint space.
950950
951951
Shape: ``(num_instances, num_joints + num_base_dofs, num_joints + num_base_dofs)``,
952952
dtype ``wp.float32`` [kg·m² or kg, per DoF type]. DoF-axis convention matches
953953
:attr:`body_link_jacobian_w`.
954954
955-
``M(q)`` is symmetric positive-definite. ``M[i, j]`` is the coefficient
956-
relating DoF ``j``'s acceleration to the inertial torque on DoF ``i`` in
957-
``M(q) q_ddot + C(q, q_dot) q_dot + g(q) = tau``.
955+
``M_body(q)`` is symmetric positive-definite and excludes :attr:`joint_armature`.
956+
Controllers that model joint armature as additional inertia can add it to the
957+
joint diagonal explicitly. Other solver-specific inertial terms may also be absent.
958958
"""
959959
raise NotImplementedError(f"{type(self).__name__} does not implement mass_matrix.")
960960

‎source/isaaclab/isaaclab/envs/mdp/actions/task_space_actions.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ def _compute_dynamic_quantities(self):
658658
self._mass_matrix[:] = self._asset.data.mass_matrix.torch[:, self._jacobi_joint_idx, :][
659659
:, :, self._jacobi_joint_idx
660660
]
661+
self._mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._asset.data.joint_armature.torch[:, self._joint_ids])
661662
if self._needs_gravity:
662663
self._gravity[:] = self._asset.data.gravity_compensation_forces.torch[:, self._jacobi_joint_idx]
663664

‎source/isaaclab/test/controllers/test_operational_space.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ def test_floating_base_osc_action_term_indexing():
796796
num_arm_joints = action_term._num_DoF
797797

798798
# --- 3. Step the env to populate physics buffers ---
799+
arm_joint_ids, _ = robot.find_joints(_G1_ARM_JOINT_NAMES)
800+
robot.write_joint_armature_to_sim_index(armature=0.5, joint_ids=arm_joint_ids)
801+
assert torch.all(robot.data.joint_armature.torch[:, arm_joint_ids] == 0.5)
799802
zero_actions = torch.zeros(num_envs, action_term.action_dim, device=env.device)
800803
action_term.process_actions(zero_actions)
801804
action_term.apply_actions()
@@ -809,7 +812,8 @@ def test_floating_base_osc_action_term_indexing():
809812
full_mass_matrix = robot.data.mass_matrix.torch
810813
full_gravity = robot.data.gravity_compensation_forces.torch
811814

812-
manual_mass = full_mass_matrix[:, jacobi_joint_idx, :][:, :, jacobi_joint_idx]
815+
manual_mass = full_mass_matrix[:, jacobi_joint_idx, :][:, :, jacobi_joint_idx].clone()
816+
manual_mass.diagonal(dim1=-2, dim2=-1).add_(robot.data.joint_armature.torch[:, arm_joint_ids])
813817
manual_gravity = full_gravity[:, jacobi_joint_idx]
814818

815819
# --- 6. KEY ASSERTION: action term output must match manual extraction with correct indices ---
@@ -825,7 +829,8 @@ def test_floating_base_osc_action_term_indexing():
825829
# --- 8. Verify correct indices differ from raw joint_ids (the old bug) ---
826830
# Reconstruct the original joint_ids before any slice(None) optimization
827831
original_joint_ids, _ = robot.find_joints(_G1_ARM_JOINT_NAMES)
828-
buggy_mass = full_mass_matrix[:, original_joint_ids, :][:, :, original_joint_ids]
832+
buggy_mass = full_mass_matrix[:, original_joint_ids, :][:, :, original_joint_ids].clone()
833+
buggy_mass.diagonal(dim1=-2, dim2=-1).add_(robot.data.joint_armature.torch[:, original_joint_ids])
829834
assert not torch.allclose(term_mass, buggy_mass, atol=1e-6), (
830835
"Action term mass matrix should NOT match extraction with raw joint_ids (no num_base_dofs offset)"
831836
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Included joint armature in Newton operational space control without changing the raw articulation mass matrix.

‎source/isaaclab_newton/isaaclab_newton/envs/mdp/actions/newton_task_space_actions.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,16 @@ def apply_actions(self):
316316
self._ee_wrench_b[:, 3:] = ee_wrench_des[:, 3:]
317317
ee_wrench = self._ee_wrench_b
318318
joint_ids = self._jacobi_joint_ids
319+
mass_matrix = None
320+
if cfg.use_inertia_decoupling:
321+
mass_matrix = data.mass_matrix.torch[:, joint_ids][:, :, joint_ids]
322+
mass_matrix.diagonal(dim1=-2, dim2=-1).add_(data.joint_armature.torch[:, self._joint_ids])
319323
efforts = self._controller.compute(
320324
self._compute_ee_jacobian(),
321325
ee_pose,
322326
self._compute_ee_velocity(),
323327
self._ee_pose_des,
324-
mass_matrix=data.mass_matrix.torch[:, joint_ids][:, :, joint_ids] if cfg.use_inertia_decoupling else None,
328+
mass_matrix=mass_matrix,
325329
gravity=data.gravity_compensation_forces.torch[:, joint_ids] if cfg.use_gravity_compensation else None,
326330
ee_wrench_des=ee_wrench_des,
327331
ee_wrench=ee_wrench,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,14 @@ def test_get_gravity_compensation_forces_matches_jacobian_gravity(scene: _Scene,
17181718
M_0 = articulation.data.mass_matrix.torch.clone()
17191719
g_0 = articulation.data.gravity_compensation_forces.torch.clone()
17201720

1721+
if island == "ordered":
1722+
# Armature changes the simulated joint inertia, but the exposed matrix is rigid-body inertia.
1723+
armature_0 = articulation.data.joint_armature.torch.clone()
1724+
articulation.write_joint_armature_to_sim_index(armature=armature_0[1:2] + 0.25, env_ids=[1])
1725+
torch.testing.assert_close(articulation.data.joint_armature.torch[1:2], armature_0[1:2] + 0.25)
1726+
torch.testing.assert_close(articulation.data.mass_matrix.torch, M_0)
1727+
articulation.write_joint_armature_to_sim_index(armature=armature_0[1:2], env_ids=[1])
1728+
17211729
# Non-trivial configuration via manual writes (no sim step, so the assert
17221730
# compares both quantities at exactly this state): random joint offsets,
17231731
# and for floating-base a non-identity root pose.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Included joint armature in the Factory and Automate control mass matrices.

‎source/isaaclab_tasks/isaaclab_tasks/contrib/automate/assembly_env.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ def _compute_intermediate_values(self, dt):
269269
self.left_finger_jacobian = jacobians[:, self.left_finger_body_idx - 1, 0:6, 0:7]
270270
self.right_finger_jacobian = jacobians[:, self.right_finger_body_idx - 1, 0:6, 0:7]
271271
self.fingertip_midpoint_jacobian = (self.left_finger_jacobian + self.right_finger_jacobian) * 0.5
272-
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7]
272+
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7].clone()
273+
self.arm_mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._robot.data.joint_armature.torch[:, 0:7])
273274
self.joint_pos = self._robot.data.joint_pos.torch.clone()
274275
self.joint_vel = self._robot.data.joint_vel.torch.clone()
275276

‎source/isaaclab_tasks/isaaclab_tasks/contrib/automate/disassembly_env.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ def _compute_intermediate_values(self, dt):
192192
self.left_finger_jacobian = jacobians[:, self.left_finger_body_idx - 1, 0:6, 0:7]
193193
self.right_finger_jacobian = jacobians[:, self.right_finger_body_idx - 1, 0:6, 0:7]
194194
self.fingertip_midpoint_jacobian = (self.left_finger_jacobian + self.right_finger_jacobian) * 0.5
195-
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7]
195+
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7].clone()
196+
self.arm_mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._robot.data.joint_armature.torch[:, 0:7])
196197
self.joint_pos = self._robot.data.joint_pos.torch.clone()
197198
self.joint_vel = self._robot.data.joint_vel.torch.clone()
198199

0 commit comments

Comments
 (0)