-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaster.py
122 lines (93 loc) · 3.13 KB
/
master.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
118
119
120
121
122
import RPi.GPIO as GPIO
import time
'''
duty clycle (degree)
10 : 160
7.5 : 120
5 : 80
2.5 : 40
'''
class motorz:
def __init__(self):
self.SERVO_1 = 18
self.SERVO_2 = 23
self.MOVE_TIME = 0.3
self.COUNT = 1
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.SERVO_1, GPIO.OUT)
GPIO.setup(self.SERVO_2, GPIO.OUT)
self.pwm1 = GPIO.PWM(self.SERVO_1, 50)
self.pwm2 = GPIO.PWM(self.SERVO_2, 50)
self.pwm1.start(0)
self.pwm2.start(0)
GPIO.setwarnings(False)
def Servo1Routine(self, iterations):
GPIO.setup(self.SERVO_1, GPIO.OUT)
for i in range(iterations):
self.pwm1.ChangeDutyCycle(7.5)
time.sleep(self.MOVE_TIME)
self.pwm1.ChangeDutyCycle(10)
time.sleep(self.MOVE_TIME)
self.pwm1.ChangeDutyCycle(7.5)
time.sleep(self.MOVE_TIME)
GPIO.setup(self.SERVO_1, GPIO.IN)
print(f'servo1 activated for {iterations} times')
def Servo2Routine(self, iterations):
for i in range(iterations):
GPIO.setup(self.SERVO_2, GPIO.OUT)
self.pwm2.ChangeDutyCycle(7.5)
time.sleep(self.MOVE_TIME)
self.pwm2.ChangeDutyCycle(10)
time.sleep(self.MOVE_TIME)
self.pwm2.ChangeDutyCycle(7.5)
time.sleep(self.MOVE_TIME)
GPIO.setup(self.SERVO_2, GPIO.IN)
print(f'servo2 activated for {iterations} times')
def PrintTime(self):
print(time.strftime('%H:%M:%S'))
def test(self):
try:
while True:
if time.localtime().tm_sec % 1 == 0:
print('test routine start')
self.Servo1Routine(1)
self.Servo2Routine(4)
print('test routine ended')
except KeyboardInterrupt:
self.pwm1.stop()
self.pwm2.stop()
print('End')
GPIO.cleanup()
def main(self):
try:
while True:
if ((time.localtime().tm_hour % 3 == 0) and (time.localtime().tm_min == 0)) :
time.sleep(240)
self.PrintTime()
self.Servo1Routine(1) # 00:04:00
self.Servo2Routine(4)
time.sleep(1820)
self.PrintTime()
self.Servo2Routine(4) # 00:34:20
time.sleep(1840)
self.PrintTime()
self.Servo2Routine(4) # 01:05:00
time.sleep(1860)
self.PrintTime()
self.Servo2Routine(4) # 01:36:00
time.sleep(1880)
self.PrintTime()
self.Servo2Routine(4) # 02:07:20
time.sleep(1900)
self.PrintTime()
self.Servo2Routine(4) # 02:39:00
except KeyboardInterrupt:
self.pwm1.stop()
self.pwm2.stop()
print('End')
GPIO.cleanup()
if __name__ == "__main__":
a = motorz()
a.main()
else:
print('Excution Failed')