-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotorControl.py
72 lines (63 loc) · 1.8 KB
/
motorControl.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
import RPi.GPIO as GPIO
from time import sleep
class MotorControl:
PWMValue=""
mf_pwm=""
mb_pwm=""
mf_p1=""
mf_p2=""
mb_p2=""
mb_p1=""
pwmSpeed=""
def __init__(self):
self.pwmSpeed=80
self.pwmSpeed1=80
self.pwmSpeed2=80
self.mb_p1=11
self.mb_p2=12
self.mf_p1=15
self.mf_p2=16
self.PWMValue = 100
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
self.mb_pwm=GPIO.PWM(7,self.PWMValue)
self.mf_pwm=GPIO.PWM(13,self.PWMValue)
GPIO.setup(self.mf_p1,GPIO.OUT,initial=0)
GPIO.setup(self.mf_p2,GPIO.OUT,initial=0)
GPIO.setup(self.mb_p1,GPIO.OUT,initial=0)
GPIO.setup(self.mb_p2,GPIO.OUT,initial=0)
self.mf_pwm.start(0)
self.mb_pwm.start(0)
def MoveForward(self):
GPIO.output(self.mb_p1,GPIO.HIGH)
GPIO.output(self.mb_p2,GPIO.LOW)
GPIO.output(self.mf_p1,GPIO.LOW)
GPIO.output(self.mf_p2,GPIO.LOW)
self.mb_pwm.ChangeDutyCycle(self.pwmSpeed)
def MoveBackward(self):
GPIO.output(self.mb_p1,GPIO.LOW)
GPIO.output(self.mb_p2,GPIO.HIGH)
GPIO.output(self.mf_p1,GPIO.LOW)
GPIO.output(self.mf_p1,GPIO.LOW)
self.mb_pwm.ChangeDutyCycle(self.pwmSpeed)
def MoveLeft(self):
GPIO.output(self.mb_p1,GPIO.HIGH)
GPIO.output(self.mb_p2,GPIO.LOW)
GPIO.output(self.mf_p1,GPIO.HIGH)
GPIO.output(self.mf_p2,GPIO.LOW)
self.mb_pwm.ChangeDutyCycle(self.pwmSpeed2)
self.mf_pwm.ChangeDutyCycle(self.pwmSpeed1)
def MoveRight(self):
GPIO.output(self.mb_p1,GPIO.HIGH)
GPIO.output(self.mb_p2,GPIO.LOW)
GPIO.output(self.mf_p1,GPIO.LOW)
GPIO.output(self.mf_p2,GPIO.HIGH)
self.mb_pwm.ChangeDutyCycle(self.pwmSpeed2)
self.mf_pwm.ChangeDutyCycle(self.pwmSpeed1)
def Stopper(self):
GPIO.output(self.mb_p1,GPIO.LOW)
GPIO.output(self.mb_p2,GPIO.LOW)
GPIO.output(self.mf_p1,GPIO.LOW)
GPIO.output(self.mf_p2,GPIO.LOW)
self.mf_pwm.ChangeDutyCycle(0)