-
Notifications
You must be signed in to change notification settings - Fork 0
/
robotControl.py
86 lines (67 loc) · 1.95 KB
/
robotControl.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from RpiMotorLib import rpi_dc_lib as motorlib
import RPi.GPIO as GPIO
import time
class motorControl(object):
def __init__(self, speed=25):
self.speed = speed
self.Lspeed = self.speed
self.Rspeed = self.speed
self.motorL = motorlib.L298NMDc(19, 13, 26, 50, True, "motor_left")
self.motorR = motorlib.L298NMDc(21, 20, 16, 50, True, "motor_right")
def start(self):
return self
def forward(self):
# while not stopped:
# self.stop()
# self.state = 1
self.motorL.forward(self.Lspeed)
self.motorR.forward(self.Rspeed)
def turnL(self):
self.motorL.stop()
self.motorR.forward(self.Rspeed)
time.sleep(0.5)
self.motorR.stop()
def turnR(self):
self.motorR.stop()
self.motorL.forward(self.Lspeed)
time.sleep(0.5)
self.motorL.stop()
def turnB(self):
self.motorR.stop()
self.motorL.forward(self.Lspeed)
time.sleep(self.duration)
self.motorL.stop()
def stop(self):
self.motorL.stop()
self.motorR.stop()
def move(self, dir):
if dir == 'F':
self.forward()
elif dir == 'B':
self.turnB()
elif dir == 'L':
self.turnL()
elif dir == 'R':
self.turnR()
elif dir == 'S':
self.stop()
else:
self.stop()
def motorDeinit(self):
self.stop()
self.motorL.cleanup()
self.motorR.cleanup()
class gpioControl(object):
def __init__(self, irPin=5, ledPin=6):
GPIO.setmode(GPIO.BCM)
GPIO.setup(irPin, GPIO.OUT)
GPIO.setup(ledPin, GPIO.OUT)
# these pins are low en
self.state = {
'ON': GPIO.LOW,
'OFF': GPIO.HIGH
}
GPIO.output(irPin, self.state['OFF'])
GPIO.output(ledPin, self.state['OFF'])
def start(self):
return self