Unverified Commit 762f4e32 authored by Octi Zhang's avatar Octi Zhang Committed by GitHub

Computes Jacobian in the root frame inside the `DifferentialInverseKinematicsAction` class (#967)

# Description

This pull request fix the bug where jacobian returned by
DifferentialInverseKinematicsAction._compute_fame_jacobian are not truly
in robot base frame because it did not consider robot's base rotation.
After the change, _compute_fame_jacobian returns the correct local frame
jacobian. In addition, properties get_jacobian_w and get_jacobian_b is
added to differentiate frame differences

Fixes #911 

## Type of change
- Bug fix (non-breaking change which fixes an issue)

## Screenshots

<img width="1109" alt="image"
src="https://github.com/user-attachments/assets/5d47dfb3-8c44-4115-b5a0-28c671e99459">

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
Signed-off-by: 's avatarOcti Zhang <127588710+zoctipus@users.noreply.github.com>
Signed-off-by: 's avatarKelly Guo <kellyg@nvidia.com>
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
parent 902fb806
[package] [package]
# Note: Semantic Versioning is used: https://semver.org/ # Note: Semantic Versioning is used: https://semver.org/
version = "0.27.24" version = "0.27.25"
# Description # Description
title = "Isaac Lab framework for Robot Learning" title = "Isaac Lab framework for Robot Learning"
......
Changelog Changelog
--------- ---------
0.27.25 (2024-12-11)
~~~~~~~~~~~~~~~~~~~~
Fixed
^^^^^
* Modified :class:`omni.isaac.lab.envs.mdp.actions.DifferentialInverseKinematicsAction` class to use the geometric
Jacobian computed w.r.t. to the root frame of the robot. This helps ensure that root pose does not affect the tracking.
0.27.24 (2024-12-09) 0.27.24 (2024-12-09)
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
......
...@@ -117,6 +117,19 @@ class DifferentialInverseKinematicsAction(ActionTerm): ...@@ -117,6 +117,19 @@ class DifferentialInverseKinematicsAction(ActionTerm):
def processed_actions(self) -> torch.Tensor: def processed_actions(self) -> torch.Tensor:
return self._processed_actions return self._processed_actions
@property
def jacobian_w(self) -> torch.Tensor:
return self._asset.root_physx_view.get_jacobians()[:, self._jacobi_body_idx, :, self._jacobi_joint_ids]
@property
def jacobian_b(self) -> torch.Tensor:
jacobian = self.jacobian_w
base_rot = self._asset.data.root_quat_w
base_rot_matrix = math_utils.matrix_from_quat(math_utils.quat_inv(base_rot))
jacobian[:, :3, :] = torch.bmm(base_rot_matrix, jacobian[:, :3, :])
jacobian[:, 3:, :] = torch.bmm(base_rot_matrix, jacobian[:, 3:, :])
return jacobian
""" """
Operations. Operations.
""" """
...@@ -178,7 +191,7 @@ class DifferentialInverseKinematicsAction(ActionTerm): ...@@ -178,7 +191,7 @@ class DifferentialInverseKinematicsAction(ActionTerm):
the right Jacobian from the parent body Jacobian. the right Jacobian from the parent body Jacobian.
""" """
# read the parent jacobian # read the parent jacobian
jacobian = self._asset.root_physx_view.get_jacobians()[:, self._jacobi_body_idx, :, self._jacobi_joint_ids] jacobian = self.jacobian_b
# account for the offset # account for the offset
if self.cfg.body_offset is not None: if self.cfg.body_offset is not None:
# Modify the jacobian to account for the offset # Modify the jacobian to account for the offset
......
...@@ -22,7 +22,14 @@ from omni.isaac.cloner import GridCloner ...@@ -22,7 +22,14 @@ from omni.isaac.cloner import GridCloner
import omni.isaac.lab.sim as sim_utils import omni.isaac.lab.sim as sim_utils
from omni.isaac.lab.assets import Articulation from omni.isaac.lab.assets import Articulation
from omni.isaac.lab.controllers import DifferentialIKController, DifferentialIKControllerCfg from omni.isaac.lab.controllers import DifferentialIKController, DifferentialIKControllerCfg
from omni.isaac.lab.utils.math import compute_pose_error, subtract_frame_transforms
from omni.isaac.lab.utils.math import ( # isort:skip
compute_pose_error,
matrix_from_quat,
quat_inv,
random_yaw_orientation,
subtract_frame_transforms,
)
## ##
# Pre-defined configs # Pre-defined configs
...@@ -169,6 +176,10 @@ class TestDifferentialIKController(unittest.TestCase): ...@@ -169,6 +176,10 @@ class TestDifferentialIKController(unittest.TestCase):
robot.write_joint_state_to_sim(joint_pos, joint_vel) robot.write_joint_state_to_sim(joint_pos, joint_vel)
robot.set_joint_position_target(joint_pos) robot.set_joint_position_target(joint_pos)
robot.write_data_to_sim() robot.write_data_to_sim()
# randomize root state yaw, ik should work regardless base rotation
root_state = robot.data.root_state_w.clone()
root_state[:, 3:7] = random_yaw_orientation(self.num_envs, self.sim.device)
robot.write_root_state_to_sim(root_state)
robot.reset() robot.reset()
# reset actions # reset actions
ee_pose_b_des[:] = self.ee_pose_b_des_set[current_goal_idx] ee_pose_b_des[:] = self.ee_pose_b_des_set[current_goal_idx]
...@@ -185,6 +196,10 @@ class TestDifferentialIKController(unittest.TestCase): ...@@ -185,6 +196,10 @@ class TestDifferentialIKController(unittest.TestCase):
jacobian = robot.root_physx_view.get_jacobians()[:, ee_jacobi_idx, :, arm_joint_ids] jacobian = robot.root_physx_view.get_jacobians()[:, ee_jacobi_idx, :, arm_joint_ids]
ee_pose_w = robot.data.body_state_w[:, ee_frame_idx, 0:7] ee_pose_w = robot.data.body_state_w[:, ee_frame_idx, 0:7]
root_pose_w = robot.data.root_state_w[:, 0:7] root_pose_w = robot.data.root_state_w[:, 0:7]
base_rot = root_pose_w[:, 3:7]
base_rot_matrix = matrix_from_quat(quat_inv(base_rot))
jacobian[:, :3, :] = torch.bmm(base_rot_matrix, jacobian[:, :3, :])
jacobian[:, 3:, :] = torch.bmm(base_rot_matrix, jacobian[:, 3:, :])
joint_pos = robot.data.joint_pos[:, arm_joint_ids] joint_pos = robot.data.joint_pos[:, arm_joint_ids]
# compute frame in root frame # compute frame in root frame
ee_pos_b, ee_quat_b = subtract_frame_transforms( ee_pos_b, ee_quat_b = subtract_frame_transforms(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment