-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb6643kq_driver.py
44 lines (32 loc) · 1.25 KB
/
tb6643kq_driver.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
import pigpio
class Tb6643kq_driver:
def __init__(self, pi: pigpio.pi, pin_1: int, pin_2: int, freq=1000, range=100) -> None:
self.pi = pi
self.PIN_1 = pin_1
self.PIN_2 = pin_2
self.FREQ = freq
self.RANGE = range
self.pi.set_PWM_frequency(self.PIN_1, freq)
self.pi.set_PWM_frequency(self.PIN_2, freq)
self.pi.set_PWM_range(self.PIN_1, range)
self.pi.set_PWM_range(self.PIN_2, range)
self.pi.set_mode(self.PIN_1, pigpio.OUTPUT)
self.pi.set_mode(self.PIN_2, pigpio.OUTPUT)
def drive(self, speed: int) -> None:
follow_pin = self.PIN_1
back_pin = self.PIN_2
if speed < 0:
follow_pin = self.PIN_2
back_pin = self.PIN_1
speed = -speed
self.pi.set_PWM_dutycycle(follow_pin, self.RANGE)
self.pi.set_PWM_dutycycle(back_pin, self.RANGE - speed)
def accelatation(self, start: int, end: int, at_time: int) -> None:
at = (end - start) / at_time
for i in range(start, end, at):
self.drive(i)
time.sleep(1)
def stop(self) -> None:
self.pi.set_PWM_dutycycle(self.PIN_1, self.RANGE)
self.pi.set_PWM_dutycycle(self.PIN_2, self.RANGE)