tr2023-robot/beta/Driver.py

29 lines
659 B
Python
Raw Normal View History

2023-03-25 09:33:33 +00:00
from Adafruit_PCA9685 import PCA9685
class PWMDriver:
def __init__(self):
self.driver = PCA9685()
self.driver.set_pwm_freq(50)
def set_pwm(self, slot, off, on):
self.driver.set_pwm(slot, off, on)
# comme map() dans arduino
def mappyt(self, x, inMin, inMax, outMin, outMax):
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
def init_esc(self, slot):
self.set_pwm(slot, 0, 307)
def set_esc(self, slot, speed):
self.set_pwm(
slot,
0,
self.convert_speed_to_esc(speed)
)
def convert_speed_to_esc(self, speed):
return round(self.mappyt(speed, 0, 100, 210, 410))