Skip to content

Commit 6b2f275

Browse files
committed
Revert "Add math tests for transforms, rotations, and conversions (#103)"
This reverts commit 3e77641.
1 parent 6eeb642 commit 6b2f275

File tree

1 file changed

+13
-7
lines changed
  • source/isaaclab/isaaclab/utils

1 file changed

+13
-7
lines changed

source/isaaclab/isaaclab/utils/math.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def copysign(mag: float, other: torch.Tensor) -> torch.Tensor:
133133
Returns:
134134
The output tensor.
135135
"""
136-
mag_torch = abs(mag) * torch.ones_like(other)
137-
return torch.copysign(mag_torch, other)
136+
mag_torch = torch.tensor(mag, device=other.device, dtype=torch.float).repeat(other.shape[0])
137+
return torch.abs(mag_torch) * torch.sign(other)
138138

139139

140140
"""
@@ -250,7 +250,7 @@ def quat_conjugate(q: torch.Tensor) -> torch.Tensor:
250250
"""
251251
shape = q.shape
252252
q = q.reshape(-1, 4)
253-
return torch.cat((q[..., 0:1], -q[..., 1:]), dim=-1).view(shape)
253+
return torch.cat((q[:, 0:1], -q[:, 1:]), dim=-1).view(shape)
254254

255255

256256
@torch.jit.script
@@ -401,7 +401,7 @@ def _axis_angle_rotation(axis: Literal["X", "Y", "Z"], angle: torch.Tensor) -> t
401401

402402
def matrix_from_euler(euler_angles: torch.Tensor, convention: str) -> torch.Tensor:
403403
"""
404-
Convert rotations given as Euler angles (intrinsic) in radians to rotation matrices.
404+
Convert rotations given as Euler angles in radians to rotation matrices.
405405
406406
Args:
407407
euler_angles: Euler angles in radians. Shape is (..., 3).
@@ -436,7 +436,7 @@ def euler_xyz_from_quat(
436436
"""Convert rotations given as quaternions to Euler angles in radians.
437437
438438
Note:
439-
The euler angles are assumed in XYZ extrinsic convention.
439+
The euler angles are assumed in XYZ convention.
440440
441441
Args:
442442
quat: The quaternion orientation in (w, x, y, z). Shape is (N, 4).
@@ -928,8 +928,14 @@ def compute_pose_error(
928928
Raises:
929929
ValueError: Invalid rotation error type.
930930
"""
931-
# Compute quaternion error (i.e., quat_box_minus)
932-
quat_error = quat_mul(q01, quat_conjugate(q02))
931+
# Compute quaternion error (i.e., difference quaternion)
932+
# Reference: https://personal.utdallas.edu/~sxb027100/dock/quaternion.html
933+
# q_current_norm = q_current * q_current_conj
934+
source_quat_norm = quat_mul(q01, quat_conjugate(q01))[:, 0]
935+
# q_current_inv = q_current_conj / q_current_norm
936+
source_quat_inv = quat_conjugate(q01) / source_quat_norm.unsqueeze(-1)
937+
# q_error = q_target * q_current_inv
938+
quat_error = quat_mul(q02, source_quat_inv)
933939

934940
# Compute position error
935941
pos_error = t02 - t01

0 commit comments

Comments
 (0)