Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in 6D to quaternion rotation conversion #38

Open
ankile opened this issue Jan 21, 2024 · 0 comments
Open

Bug in 6D to quaternion rotation conversion #38

ankile opened this issue Jan 21, 2024 · 0 comments

Comments

@ankile
Copy link
Contributor

ankile commented Jan 21, 2024

Hi @minoring !

Thanks for implementing the 6D rotation control in the environment! However, I noticed that IsaacGym and pytorch3d use different conventions for quaternions that lead to trouble:

  • IsaacGym represents quaternions as (x, y, z, w)
  • pytorch3d represents quaternions as (w, x, y, z)

From pytorch3d source:

def quaternion_to_matrix(quaternions):
    """
    Convert rotations given as quaternions to rotation matrices.

    Args:
        quaternions: quaternions with real part first,
            as tensor of shape (..., 4).

From IsaacGym documentation:

classisaacgym.gymapi.Quat
Quaternion representation in Gym
dtype= dtype([('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('w', '<f4')])

Therefore, I believe this piece of code in the FurnitureSimEnv:

elif self.act_rot_repr == "rot_6d":
import pytorch3d.transforms as pt
# Create "actions" dataset.
rot_6d = action[:, 3:9]
rot_mat = pt.rotation_6d_to_matrix(rot_6d)
quat = pt.matrix_to_quaternion(rot_mat)
action_quat = quat[env_idx]

Should be something more like this:

elif self.act_rot_repr == "rot_6d":
    import pytorch3d.transforms as pt

    # Create "actions" dataset.
    rot_6d = action[:, 3:9]
    rot_mat = pt.rotation_6d_to_matrix(rot_6d)

    # pytorch3d has the real part first (w, x, y, z)
    quat = pt.matrix_to_quaternion(rot_mat)
    action_quat = quat[env_idx]

    # IsaacGym expects the real part last (x, y, z, w)
    action_quat = torch.cat([action_quat[1:], action_quat[:1]])

Or, maybe there's a nicer way to make sure the conventions align!

Thank you!

Lars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant