forked from rasplay/RAS_RC_CAR_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRAS_RC_Motor_2WD.py
86 lines (68 loc) · 1.63 KB
/
RAS_RC_Motor_2WD.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
85
86
import RPi.GPIO as GPIO
from time import sleep
ENABLE_PIN1 = 18
ENABLE_PIN2 = 13
IN1 = 24
IN2 = 23
IN3 = 21
IN4 = 20
ENGINE_FREQ1 = 300
ENGINE_FREQ2 = 300
enable_pin1 = ENABLE_PIN1
enable_pin2 = ENABLE_PIN2
in1_pin = IN1
in2_pin = IN2
in3_pin = IN3
in4_pin = IN4
GPIO.setmode(GPIO.BCM)
GPIO.setup(enable_pin1, GPIO.OUT)
GPIO.setup(in1_pin, GPIO.OUT)
GPIO.setup(in2_pin, GPIO.OUT)
GPIO.setup(enable_pin2, GPIO.OUT)
GPIO.setup(in3_pin, GPIO.OUT)
GPIO.setup(in4_pin, GPIO.OUT)
pwm1 = GPIO.PWM(enable_pin1, ENGINE_FREQ1)
pwm2 = GPIO.PWM(enable_pin2, ENGINE_FREQ2)
def Forward():
pwm1.start(0)
pwm2.start(0)
print "GO Forward"
GPIO.output(in1_pin, True)
GPIO.output(in2_pin, False)
GPIO.output(in3_pin, False)
GPIO.output(in4_pin, True)
pwm1.ChangeDutyCycle(30)
pwm2.ChangeDutyCycle(30)
def Backward():
pwm1.start(0)
pwm2.start(0)
print "GO backward"
GPIO.output(in1_pin, False)
GPIO.output(in2_pin, True)
GPIO.output(in3_pin, True)
GPIO.output(in4_pin, False)
pwm1.ChangeDutyCycle(30)
pwm2.ChangeDutyCycle(30)
def TurnLeft():
pwm1.start(0)
pwm2.start(0)
print "GO TurnLeft"
GPIO.output(in1_pin, True)
GPIO.output(in2_pin, False)
GPIO.output(in3_pin, False)
GPIO.output(in4_pin, True)
pwm1.ChangeDutyCycle(100)
pwm2.ChangeDutyCycle(10)
def TurnRight():
pwm1.start(0)
pwm2.start(0)
print "GO TurnRight"
GPIO.output(in1_pin, True)
GPIO.output(in2_pin, False)
GPIO.output(in3_pin, False)
GPIO.output(in4_pin, True)
pwm1.ChangeDutyCycle(10)
pwm2.ChangeDutyCycle(100)
def Stop():
pwm1.start(0)
pwm2.start(0)