Skip to content

Commit 1708d3f

Browse files
authored
Merge pull request #538 from bitcraze/rik/fix-rotation-check
Fix rotvec comparison to handle 180° rotation ambiguity
2 parents 17f0fe2 + a029f4f commit 1708d3f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

test/localization/lighthouse_test_base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ def assertPosesAlmostEqual(self, expected: Pose, actual: Pose, places: int = 5):
4747
self.assertAlmostEqual(0.0, np.linalg.norm(translation_diff), places,
4848
f'Translation different, expected: {expected.translation}, actual: {actual.translation}')
4949

50-
def un_ambiguize(rot_vec):
51-
quat = Rotation.from_rotvec(rot_vec).as_quat()
52-
return Rotation.from_quat(quat).as_rotvec()
50+
_expected_rot = Rotation.from_rotvec(expected.rot_vec)
51+
_actual_rot = Rotation.from_rotvec(actual.rot_vec)
5352

54-
_expected_rot_vec = un_ambiguize(expected.rot_vec)
55-
_actual_rot_vec = un_ambiguize(actual.rot_vec)
53+
# Compute the rotation needed to go from expected to actual.
54+
# This avoids sign ambiguity in rotvecs (e.g., π vs. -π) by comparing actual orientation difference.
55+
_relative_rot = _expected_rot.inv() * _actual_rot
5656

57-
rotation_diff = _expected_rot_vec - _actual_rot_vec
58-
self.assertAlmostEqual(0.0, np.linalg.norm(rotation_diff), places,
57+
angle_diff = _relative_rot.magnitude()
58+
self.assertAlmostEqual(0.0, angle_diff, places,
5959
f'Rotation different, expected: {expected.rot_vec}, actual: {actual.rot_vec}')

0 commit comments

Comments
 (0)