Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
surgura committed Dec 5, 2023
1 parent faade76 commit a70ce8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class PhysicalInterface(ABC):
"""Abstract implementation for interfacing with hardware."""

@abstractmethod
def set_servo_target(self, pin: int, target: float) -> None:
def set_servo_targets(self, pins: list[int], targets: list[float]) -> None:
"""
Set the target for a single Servo.
Set the target for multiple servos.
:param pin: The GPIO pin number.
:param target: The target angle.
:param pin: The GPIO pin numbers.
:param target: The target angles.
"""

@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,23 @@ def __init__(self, debug: bool, dry: bool, careful: bool) -> None:
self._robohat.do_buzzer_beep()
self._robohat.set_servo_direct_mode(careful)

def set_servo_target(self, pin: int, target: float) -> None:
def set_servo_targets(self, pins: list[int], targets: list[float]) -> None:
"""
Set the target for a single Servo.
Set the target for multiple servos.
:param pin: The GPIO pin number.
:param target: The target angle.
:param pin: The GPIO pin numbers.
:param target: The target angles.
"""
if self._debug:
print(f"{pin:03d} | {target}")
for pin, target in zip(pins, targets):
if self._debug:
print(f"{pin:03d} | {target}")

if not self._dry:
angle = target / (2 * math.pi) * 180 + 90
self._robohat.set_servo_single_angle(pin, angle)
all_angles = [0.0] * 32
angles = [target / (2 * math.pi) * 180 + 90 for target in targets]
for pin, angle in zip(pins, angles):
all_angles[pin] = angle
self._robohat.set_servo_multiple_angles(all_angles)

def enable(self) -> None:
"""Start the robot."""
Expand Down

0 comments on commit a70ce8a

Please sign in to comment.