Skip to content

Commit fa82013

Browse files
authored
Check quaternions for equal dot_product instead of comparing their components individually (#1238)
The lookup can result in quaternions that look different component-wise while still being very similar. Instead of comparing them component-wise to decide whether they are similar, we check whether their dot-product is equal to 1.0. That should be more robust.
1 parent 6ebe03a commit fa82013

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

ur_robot_driver/test/integration_test_force_mode.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
TIMEOUT_EXECUTE_TRAJECTORY = 30
6868

6969

70+
def are_quaternions_same(q1, q2, tolerance):
71+
dot_product = q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w
72+
return (abs(dot_product) - 1.0) < tolerance
73+
74+
7075
@pytest.mark.launch_test
7176
@launch_testing.parametrize(
7277
"tf_prefix",
@@ -195,25 +200,10 @@ def run_force_mode(self, tf_prefix):
195200
trans_before.transform.translation.z,
196201
delta=0.001,
197202
)
198-
self.assertAlmostEqual(
199-
trans_after.transform.rotation.x,
200-
trans_before.transform.rotation.x,
201-
delta=0.01,
202-
)
203-
self.assertAlmostEqual(
204-
trans_after.transform.rotation.y,
205-
trans_before.transform.rotation.y,
206-
delta=0.01,
207-
)
208-
self.assertAlmostEqual(
209-
trans_after.transform.rotation.z,
210-
trans_before.transform.rotation.z,
211-
delta=0.01,
212-
)
213-
self.assertAlmostEqual(
214-
trans_after.transform.rotation.w,
215-
trans_before.transform.rotation.w,
216-
delta=0.01,
203+
self.assertTrue(
204+
are_quaternions_same(
205+
trans_after.transform.rotation, trans_before.transform.rotation, 0.001
206+
)
217207
)
218208

219209
res = self._force_mode_controller_interface.stop_force_mode()

0 commit comments

Comments
 (0)