28 lines
659 B
Python
28 lines
659 B
Python
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))
|
|
|
|
|