Skip to content

Commit

Permalink
added enum class to specifiy stroke options
Browse files Browse the repository at this point in the history
  • Loading branch information
RemkoPr committed Jan 7, 2025
1 parent 7927360 commit 1ed12f0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions airo-robots/airo_robots/grippers/hardware/schunk_egk40_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
from typing import Optional
from airo_robots.awaitable_action import AwaitableAction
from airo_robots.grippers.parallel_position_gripper import ParallelPositionGripper, ParallelPositionGripperSpecs
from enum import Enum


def rescale_range(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float:
return to_min + (x - from_min) / (from_max - from_min) * (to_max - to_min)


class SCHUNK_STROKE_OPTIONS(Enum):
DEFAULT = 0
CALIBRATE = 1


class SchunkEGK40_USB(ParallelPositionGripper):
# values obtained from https://schunk.com/be/nl/grijpsystemen/parallelgrijper/egk/egk-40-mb-m-b/p/000000000001491762
SCHUNK_DEFAULT_SPECS = ParallelPositionGripperSpecs(0.083, 0.0, 150, 55, 0.0575, 0.0055)

def __init__(self, usb_interface="/dev/ttyUSB0",
fingers_max_stroke: Optional[float] = None) -> None:
max_stroke_setting: Optional[SCHUNK_STROKE_OPTIONS, float] = None) -> None:
"""
usb_interface: the USB interface to which the gripper is connected.
Expand All @@ -31,13 +37,20 @@ def __init__(self, usb_interface="/dev/ttyUSB0",
the Schunk's maximum width of 83mm. Such fingertips would not touch when the Schunk is "closed".
"""
super().__init__(self.SCHUNK_DEFAULT_SPECS)
if fingers_max_stroke == -1:
# keep default width settings
pass
elif fingers_max_stroke:
self._gripper_specs.max_width = fingers_max_stroke
elif fingers_max_stroke is None:
self.calibrate_width()
if isinstance(max_stroke_setting, SCHUNK_STROKE_OPTIONS):
if max_stroke_setting == SCHUNK_STROKE_OPTIONS.DEFAULT:
# keep default width setting
pass
elif max_stroke_setting == SCHUNK_STROKE_OPTIONS.CALIBRATE:
self.calibrate_width()
else:
raise ValueError("Incorrect stroke setting.")
else:
if not isinstance(max_stroke_setting, float):
raise ValueError("Incorrect stroke setting.")
else:
# overwrite width setting
self._gripper_specs.max_width = fingers_max_stroke
self.width_loss_due_to_fingers = self.SCHUNK_DEFAULT_SPECS.max_width - self.gripper_specs.max_width

self.bks = BKSModule(usb_interface, sleep_time=None, debug=False)
Expand Down

0 comments on commit 1ed12f0

Please sign in to comment.