Skip to content

Commit

Permalink
Merge pull request #469 from pollen-robotics/468-add-gripper-paramete…
Browse files Browse the repository at this point in the history
…r-in-goto_posture

468 add gripper parameter in goto posture
  • Loading branch information
ClaireHzl authored Jan 8, 2025
2 parents ce48fbf + 0d14eb0 commit b6a29a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/reachy2_sdk/parts/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ def goto_posture(
wait: bool = False,
wait_for_goto_end: bool = True,
interpolation_mode: str = "minimum_jerk",
open_gripper: bool = False,
) -> GoToId:
"""Send all joints to standard positions with optional parameters for duration, waiting, and interpolation mode.
Expand All @@ -616,14 +617,15 @@ def goto_posture(
will cancel all executing moves and queues. Defaults to `True`.
interpolation_mode: The type of interpolation used when moving the arm's joints.
Can be 'minimum_jerk' or 'linear'. Defaults to 'minimum_jerk'.
open_gripper: If `True`, the gripper will open, if `False`, it stays in its current position.
Defaults to `False`.
Returns:
A unique GoToId identifier for this specific movement.
"""
joints = self.get_default_posture_joints(common_posture=common_posture)
if common_posture == "default":
if self._gripper is not None and self._gripper.is_on():
self._gripper.open()
if self._gripper is not None and self._gripper.is_on() and open_gripper:
self._gripper.open()
if not wait_for_goto_end:
self.cancel_all_goto()
if self.is_on():
Expand Down
5 changes: 5 additions & 0 deletions src/reachy2_sdk/reachy_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def goto_posture(
wait: bool = False,
wait_for_goto_end: bool = True,
interpolation_mode: str = "minimum_jerk",
open_gripper: bool = False,
) -> GoToHomeId:
"""Move the robot to a predefined posture.
Expand All @@ -625,6 +626,8 @@ def goto_posture(
will cancel all executing moves and queues. Defaults to `True`.
interpolation_mode: The type of interpolation used when moving the arm's joints.
Can be 'minimum_jerk' or 'linear'. Defaults to 'minimum_jerk'.
open_gripper: If `True`, the gripper will open, if `False`, it stays in its current position.
Defaults to `False`.
Returns:
A GoToHomeId containing movement GoToIds for each part.
Expand All @@ -651,6 +654,7 @@ def goto_posture(
wait=wait_r_arm,
wait_for_goto_end=wait_for_goto_end,
interpolation_mode=interpolation_mode,
open_gripper=open_gripper,
)
if self.l_arm is not None:
l_arm_id = self.l_arm.goto_posture(
Expand All @@ -659,6 +663,7 @@ def goto_posture(
wait=wait,
wait_for_goto_end=wait_for_goto_end,
interpolation_mode=interpolation_mode,
open_gripper=open_gripper,
)
ids = GoToHomeId(
head=head_id,
Expand Down
4 changes: 2 additions & 2 deletions tests/units/online/test_advanced_goto_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_reachy_goto_posture(reachy_sdk_zeroed: ReachySDK) -> None:
# Test the default pose
reachy_sdk_zeroed.l_arm.gripper.close()
reachy_sdk_zeroed.r_arm.gripper.close()
reachy_sdk_zeroed.goto_posture("default")
reachy_sdk_zeroed.goto_posture("default", open_gripper=True)
time.sleep(2)
assert reachy_sdk_zeroed.l_arm.gripper.opening == 100.0
assert reachy_sdk_zeroed.r_arm.gripper.opening == 100.0
Expand All @@ -283,7 +283,7 @@ def test_reachy_goto_posture(reachy_sdk_zeroed: ReachySDK) -> None:
reachy_sdk_zeroed.goto_posture("elbow_90")
time.sleep(2)
reachy_sdk_zeroed.l_arm.turn_off()
reachy_sdk_zeroed.goto_posture("default")
reachy_sdk_zeroed.goto_posture("default", open_gripper=True)
time.sleep(2)
assert np.isclose(reachy_sdk_zeroed.l_arm.gripper.opening, 30, atol=5)
assert reachy_sdk_zeroed.r_arm.gripper.opening == 100.0
Expand Down
6 changes: 6 additions & 0 deletions tests/units/online/test_basic_movements.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def test_get_default_posture_matrix(reachy_sdk_zeroed: ReachySDK) -> None:
with pytest.raises(ValueError):
reachy_sdk_zeroed.r_arm.get_default_posture_matrix("coucou")

reachy_sdk_zeroed.l_arm.gripper.set_opening(50)
reachy_sdk_zeroed.goto_posture(common_posture="default", wait=True)
assert np.allclose(reachy_sdk_zeroed.l_arm.gripper.opening, 50, atol=5)
reachy_sdk_zeroed.goto_posture(common_posture="default", wait=True, open_gripper=True)
assert np.allclose(reachy_sdk_zeroed.l_arm.gripper.opening, 100, atol=5)


@pytest.mark.online
def test_get_default_posture_joints(reachy_sdk_zeroed: ReachySDK) -> None:
Expand Down

0 comments on commit b6a29a1

Please sign in to comment.