Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added joint armature explicitly to the mass matrix used by operational space control while keeping the articulation mass matrix as rigid-body inertia.
Original file line number Diff line number Diff line change
Expand Up @@ -946,15 +946,15 @@ def body_com_jacobian_w(self) -> ProxyArray:

@property
def mass_matrix(self) -> ProxyArray:
"""Per-env generalized mass matrix ``M(q)`` in joint space.
"""Per-env rigid-body mass matrix ``M_body(q)`` in joint space.

Shape: ``(num_instances, num_joints + num_base_dofs, num_joints + num_base_dofs)``,
dtype ``wp.float32`` [kg·m² or kg, per DoF type]. DoF-axis convention matches
:attr:`body_link_jacobian_w`.

``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``.
``M_body(q)`` is symmetric positive-definite and excludes :attr:`joint_armature`.
Controllers that model joint armature as additional inertia can add it to the
joint diagonal explicitly. Other solver-specific inertial terms may also be absent.
"""
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 @@ -658,6 +658,7 @@ def _compute_dynamic_quantities(self):
self._mass_matrix[:] = self._asset.data.mass_matrix.torch[:, self._jacobi_joint_idx, :][
:, :, self._jacobi_joint_idx
]
self._mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._asset.data.joint_armature.torch[:, self._joint_ids])
if self._needs_gravity:
self._gravity[:] = self._asset.data.gravity_compensation_forces.torch[:, self._jacobi_joint_idx]

Expand Down
9 changes: 7 additions & 2 deletions source/isaaclab/test/controllers/test_operational_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ def test_floating_base_osc_action_term_indexing():
num_arm_joints = action_term._num_DoF

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

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

# --- 6. KEY ASSERTION: action term output must match manual extraction with correct indices ---
Expand All @@ -825,7 +829,8 @@ def test_floating_base_osc_action_term_indexing():
# --- 8. Verify correct indices differ from raw joint_ids (the old bug) ---
# Reconstruct the original joint_ids before any slice(None) optimization
original_joint_ids, _ = robot.find_joints(_G1_ARM_JOINT_NAMES)
buggy_mass = full_mass_matrix[:, original_joint_ids, :][:, :, original_joint_ids]
buggy_mass = full_mass_matrix[:, original_joint_ids, :][:, :, original_joint_ids].clone()
buggy_mass.diagonal(dim1=-2, dim2=-1).add_(robot.data.joint_armature.torch[:, original_joint_ids])
assert not torch.allclose(term_mass, buggy_mass, atol=1e-6), (
"Action term mass matrix should NOT match extraction with raw joint_ids (no num_base_dofs offset)"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Included joint armature in Newton operational space control without changing the raw articulation mass matrix.
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,16 @@ def apply_actions(self):
self._ee_wrench_b[:, 3:] = ee_wrench_des[:, 3:]
ee_wrench = self._ee_wrench_b
joint_ids = self._jacobi_joint_ids
mass_matrix = None
if cfg.use_inertia_decoupling:
mass_matrix = data.mass_matrix.torch[:, joint_ids][:, :, joint_ids]
mass_matrix.diagonal(dim1=-2, dim2=-1).add_(data.joint_armature.torch[:, self._joint_ids])
efforts = self._controller.compute(
self._compute_ee_jacobian(),
ee_pose,
self._compute_ee_velocity(),
self._ee_pose_des,
mass_matrix=data.mass_matrix.torch[:, joint_ids][:, :, joint_ids] if cfg.use_inertia_decoupling else None,
mass_matrix=mass_matrix,
gravity=data.gravity_compensation_forces.torch[:, joint_ids] if cfg.use_gravity_compensation else None,
ee_wrench_des=ee_wrench_des,
ee_wrench=ee_wrench,
Expand Down
8 changes: 8 additions & 0 deletions source/isaaclab_newton/test/assets/test_articulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,14 @@ def test_get_gravity_compensation_forces_matches_jacobian_gravity(scene: _Scene,
M_0 = articulation.data.mass_matrix.torch.clone()
g_0 = articulation.data.gravity_compensation_forces.torch.clone()

if island == "ordered":
# Armature changes the simulated joint inertia, but the exposed matrix is rigid-body inertia.
armature_0 = articulation.data.joint_armature.torch.clone()
articulation.write_joint_armature_to_sim_index(armature=armature_0[1:2] + 0.25, env_ids=[1])
torch.testing.assert_close(articulation.data.joint_armature.torch[1:2], armature_0[1:2] + 0.25)
torch.testing.assert_close(articulation.data.mass_matrix.torch, M_0)
articulation.write_joint_armature_to_sim_index(armature=armature_0[1:2], env_ids=[1])

# Non-trivial configuration via manual writes (no sim step, so the assert
# compares both quantities at exactly this state): random joint offsets,
# and for floating-base a non-identity root pose.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Included joint armature in the Factory and Automate control mass matrices.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def _compute_intermediate_values(self, dt):
self.left_finger_jacobian = jacobians[:, self.left_finger_body_idx - 1, 0:6, 0:7]
self.right_finger_jacobian = jacobians[:, self.right_finger_body_idx - 1, 0:6, 0:7]
self.fingertip_midpoint_jacobian = (self.left_finger_jacobian + self.right_finger_jacobian) * 0.5
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7]
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7].clone()
self.arm_mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._robot.data.joint_armature.torch[:, 0:7])
self.joint_pos = self._robot.data.joint_pos.torch.clone()
self.joint_vel = self._robot.data.joint_vel.torch.clone()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def _compute_intermediate_values(self, dt):
self.left_finger_jacobian = jacobians[:, self.left_finger_body_idx - 1, 0:6, 0:7]
self.right_finger_jacobian = jacobians[:, self.right_finger_body_idx - 1, 0:6, 0:7]
self.fingertip_midpoint_jacobian = (self.left_finger_jacobian + self.right_finger_jacobian) * 0.5
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7]
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7].clone()
self.arm_mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._robot.data.joint_armature.torch[:, 0:7])
self.joint_pos = self._robot.data.joint_pos.torch.clone()
self.joint_vel = self._robot.data.joint_vel.torch.clone()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def _compute_intermediate_values(self, dt):
self.left_finger_jacobian = jacobians[:, self.left_finger_body_idx - 1, 0:6, 0:7]
self.right_finger_jacobian = jacobians[:, self.right_finger_body_idx - 1, 0:6, 0:7]
self.fingertip_midpoint_jacobian = (self.left_finger_jacobian + self.right_finger_jacobian) * 0.5
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7]
self.arm_mass_matrix = self._robot.data.mass_matrix.torch[:, 0:7, 0:7].clone()
self.arm_mass_matrix.diagonal(dim1=-2, dim2=-1).add_(self._robot.data.joint_armature.torch[:, 0:7])
self.joint_pos = self._robot.data.joint_pos.torch.clone()
self.joint_vel = self._robot.data.joint_vel.torch.clone()

Expand Down
Loading