Skip to content

Commit

Permalink
modify test and add explanation on 10° offset
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireHzl committed Oct 23, 2024
1 parent e4a8e0d commit 8a75a7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/reachy2_sdk/parts/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def goto(
wait: bool = False,
interpolation_mode: str = "minimum_jerk",
degrees: bool = True,
) -> GoToId:
...
) -> GoToId: ...

@overload
def goto(
Expand All @@ -145,8 +144,7 @@ def goto(
wait: bool = False,
interpolation_mode: str = "minimum_jerk",
degrees: bool = True,
) -> GoToId:
...
) -> GoToId: ...

def goto(
self,
Expand Down Expand Up @@ -365,6 +363,9 @@ def rotate_by(

if joints_request is not None:
initial_orientation = joints_request.goal_positions

# as there is a 10° offset between the joint space
# and the zero position in cartesian space in Reachy's frame for the yaw joint :
initial_orientation[1] += 10
initial_quaternion = quaternion_from_euler_angles(
initial_orientation[0], initial_orientation[1], initial_orientation[2], degrees=True
Expand Down
7 changes: 4 additions & 3 deletions tests/units/offline/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ def test_quaternion_from_euler_angles() -> None:
q4 = quaternion_from_euler_angles(0, 0, 90)
assert q4 == Quaternion(axis=[0, 0, 1], angle=np.pi / 2)
q5 = quaternion_from_euler_angles(45, 45, 45).normalised
expected_quat = Quaternion(axis=[0.57735027, 0.57735027, 0.57735027], angle=np.pi / 4).normalised
dot_product = np.dot(q5.elements, expected_quat.elements)
assert np.isclose(dot_product, 1.0, atol=1e-1) or np.isclose(dot_product, -1.0, atol=1e-1)
q5_ref = Quaternion(axis=[0.679, 0.281, 0.679], angle=convert_to_radians(85.8))
unit_quat = Quaternion()
expected_unit = q5 * q5_ref.inverse
assert np.allclose(unit_quat.elements, expected_unit.elements, atol=1e-3)

q6 = quaternion_from_euler_angles(np.pi / 2, 0, 0, degrees=False)
assert q6 == Quaternion(axis=[1, 0, 0], angle=np.pi / 2)
Expand Down

0 comments on commit 8a75a7f

Please sign in to comment.