-
Notifications
You must be signed in to change notification settings - Fork 0
/
Motor_test.py
117 lines (98 loc) · 2.35 KB
/
Motor_test.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from time import sleep
import RPi.GPIO as gpio
#GPIO.setmode(GPIO.BCM)
gpio.setwarnings(False)
def init():
gpio.setmode(gpio.BCM)
gpio.setup(26, gpio.OUT)
gpio.setup(19, gpio.OUT)
gpio.setup(13, gpio.OUT)
gpio.setup(6, gpio.OUT)
gpio.setup(21, gpio.OUT)##enable pin
def turn_left(tf):
gpio.output(26, False)
gpio.output(19, True)
gpio.output(13, False)
gpio.output(6, True)
sleep(tf)
def turn_right(tf):
gpio.output(26, True)
gpio.output(19, False)
gpio.output(13, True)
gpio.output(6, False)
sleep(tf)
def forward(tf):
gpio.output(26, True)
gpio.output(19, False)
gpio.output(13, False)
gpio.output(6, True)
sleep(tf)
def reverse(tf):
gpio.output(26, False)
gpio.output(19, True)
gpio.output(13, True)
gpio.output(6, False)
sleep(tf)
def stop(tf):
gpio.output(26, False)
gpio.output(19, False)
gpio.output(13, False)
gpio.output(6, False)
sleep(tf)
gpio.cleanup()
######
######def driveMotor(enable,dc):
###### assert dc >=0 and dc <= 100
###### motorPwm = gpio.PWM(enable, 1000)
###### motorPwm.start(1)
###### ###dutyCycle = angle / 18. + 3.
###### motorPwm.ChangeDutyCycle(dc)
###### sleep(1)
###### motorPwm.stop()
def drive(direction, tym, dc):
init()
assert dc >=0 and dc <= 100
motorPwm = gpio.PWM(21, 1000)
motorPwm.start(1)
###dutyCycle = angle / 18. + 3.
motorPwm.ChangeDutyCycle(dc)
###### sleep(1)
###### motorPwm.stop()
if direction == "forward":
###### driveMotor(21, dc)
forward(tym + 0.38)
motorPwm.stop()
stop(tym)
elif direction == "reverse":
###### driveMotor(21, dc)
reverse(tym +0.38)
motorPwm.stop()
stop(tym)
elif direction == "left":
turn_left(tym)
###### driveMotor(21, dc)
motorPwm.stop()
stop(tym)
elif direction == "right":
turn_right(tym)
###### driveMotor(21, dc)
motorPwm.stop()
stop(tym)
elif direction == "stop":
stop(tym)
else :
stop(tym)
if __name__ == '__main__':
import sys
drive((sys.argv[1]), float(sys.argv[2]), float(sys.argv[3]))
gpio.cleanup()
##
##init()
##forward(0.6)
##sleep(1)
##reverse(0.6)
##sleep(1)
##turn_right(0.6)
##sleep(1)
##turn_left(0.6)
##stop(1)