36 lines
904 B
Python
36 lines
904 B
Python
from PCA9685 import PCA9685
|
|
|
|
SERVO_COUNT = 10
|
|
|
|
pwm = PCA9685(0x40, debug=True)
|
|
pwm.setPWMFreq(50)
|
|
|
|
MIN_ANGLE = -90.0
|
|
MAX_ANGLE = 90.0
|
|
|
|
|
|
class Servo:
|
|
"""Control the servo ports on the robot
|
|
"""
|
|
|
|
@staticmethod
|
|
def set_position(channel: int, angle: int, offset: float =90):
|
|
"""Set position of servo connected to port
|
|
|
|
:param channel: channel between 0 and 7
|
|
:param angle: Angle of servo
|
|
"""
|
|
if channel < 0 or channel >= SERVO_COUNT:
|
|
raise IndexError("Invalid Servo channel specified!")
|
|
|
|
angle = max(min(angle, MAX_ANGLE), MIN_ANGLE)
|
|
|
|
pwm.setServoPulse(channel + 8, 500+int((angle+offset)/0.09))
|
|
|
|
@staticmethod
|
|
def setup_position():
|
|
"""Set position of servos to the position used during the setup process
|
|
"""
|
|
|
|
Servo.set_position(0, 0)
|
|
Servo.set_position(1, 0)
|