-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrive.py
30 lines (25 loc) · 1011 Bytes
/
drive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
class PCA9685:
'''
PWM motor controler using PCA9685 boards.
This is used for most RC Cars
'''
def __init__(self, channel, address=0x40, frequency=60, busnum=None, init_delay=0.1):
self.default_freq = 60
self.pwm_scale = frequency / self.default_freq
import Adafruit_PCA9685
# Initialise the PCA9685 using the default address (0x40).
if busnum is not None:
from Adafruit_GPIO import I2C
#replace the get_bus function with our own
def get_bus():
return busnum
I2C.get_default_bus = get_bus
self.pwm = Adafruit_PCA9685.PCA9685(address=address)
self.pwm.set_pwm_freq(frequency)
self.channel = channel
time.sleep(init_delay) # "Tamiya TBLE-02" makes a little leap otherwise
def set_pulse(self, pulse):
self.pwm.set_pwm(self.channel, 0, int(pulse * self.pwm_scale))
def run(self, pulse):
self.set_pulse(pulse)