This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/compLib/Servo.py
Konstantin Lampalzer 76a01e4cd9
Fix servo imports
2021-01-29 17:45:22 +01:00

36 lines
912 B
Python

from compLib.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)