-
Notifications
You must be signed in to change notification settings - Fork 3
/
motor.py
88 lines (86 loc) · 2.46 KB
/
motor.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
import RPi.GPIO as gpio
import time
gpio.setmode(gpio.BOARD)
gpio.setup(29,gpio.OUT)#left_serve
gpio.setup(31,gpio.OUT)#right_serve
gpio.setup(35,gpio.OUT)#left_dir
gpio.setup(36,gpio.OUT)#left_pul
gpio.setup(37,gpio.OUT)#right_dir
gpio.setup(38,gpio.OUT)#right_pul
left=gpio.PWM(29,50)
right=gpio.PWM(31,50)
left.start(0)
right.start(0)
def step_degree(which,degree,dire):
if which=="left":
if dire=="positive":#zheng
gpio.output(35,gpio.HIGH)
else:
gpio.output(35,gpio.LOW)
for i in range(degree*800):
gpio.output(36,gpio.HIGH)
time.sleep(0.0001)
gpio.output(36,gpio.LOW)
time.sleep(0.0001)
else:
if dire=="positive":#zheng
gpio.output(37,gpio.HIGH)
else:
gpio.output(37,gpio.LOW)
for i in range(degree*800):#800 degree
gpio.output(38,gpio.HIGH)
time.sleep(0.0001)
gpio.output(38,gpio.LOW)
time.sleep(0.0001)
def serve_use(which,degree):
if which=="left":
left.ChangeDutyCycle(degree)
time.sleep(0.6)
left.ChangeDutyCycle(0)
else:
right.ChangeDutyCycle(degree)
time.sleep(0.6)
right.ChangeDutyCycle(0)
def posi_group(hand,deg):#########hand:left|deg:1,2
if hand=="left":
serve_use("right", 12)
else:
serve_use("left", 12)
step_degree(hand,deg, "positive")
if hand=="left":
serve_use("right",6)
else:
serve_use("left",6)
if deg!=2:
serve_use(hand, 12)
step_degree(hand,deg, "negative")
serve_use(hand, 6)
def nega_group(hand,deg):#########hand:left|deg:1,2
if hand=="left":
serve_use("right", 12)
else:
serve_use("left", 12)
step_degree(hand,deg, "negative")
if hand=="left":
serve_use("right",6)
else:
serve_use("left",6)
if deg!=2:
serve_use(hand, 12)
step_degree(hand,deg, "positive")
serve_use(hand, 6)
def posi_unit(hand,deg):#########hand:left|deg:1,2
step_degree(hand,deg, "positive")
if deg!=2:
serve_use(hand, 12)
step_degree(hand,deg, "negative")
serve_use(hand,6)
def nega_unit(hand,deg):#########hand:left|deg:1,2
step_degree(hand,deg, "negative")
if deg!=2:
serve_use(hand, 12)
step_degree(hand,deg, "positive")
serve_use(hand, 6)
#if __name__=="__main__":
# serve_use("left", 12)
# serve_use("right",12)