-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPIOControl.py
86 lines (73 loc) · 3.24 KB
/
GPIOControl.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
import time
import asyncio
class GPIOControl:
def __init__(self):
print("setting up the gpio board")
GPIO.setmode(GPIO.BCM)
self.chan_list = [5, 6, 16, 17, 22, 23, 24, 25, 26, 27]
GPIO.setup (self.chan_list, GPIO.OUT)
GPIO.output (self.chan_list, GPIO.HIGH)
def abort (self, info):
print("abort in GPIO")
GPIO.output (self.chan_list, GPIO.HIGH)
# print("666")
# info.setInf("ABORT", 666)
def upper_shutter_open (self, wait):
print("GPIOControl: upper_shutter_open")
GPIO.output ([26, 23, 24], (GPIO.HIGH, GPIO.LOW, GPIO.HIGH))
time.sleep(wait)
GPIO.output ([26, 23, 24], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH))
def upper_shutter_close (self, wait):
print("GPIOControl: upper_shutter_close")
GPIO.output ([26, 23, 24], (GPIO.LOW, GPIO.HIGH, GPIO.LOW))
time.sleep(wait)
GPIO.output ([26, 23, 24], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH))
def lower_shutter_open (self, wait):
print("GPIOControl: lower_shutter_open")
GPIO.output ([6, 25, 16], (GPIO.HIGH, GPIO.LOW, GPIO.HIGH))
time.sleep(wait)
GPIO.output ([6, 25, 16], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH))
def lower_shutter_close (self, wait):
print("GPIOControl: lower_shutter_close")
GPIO.output ([6, 25, 16], (GPIO.LOW, GPIO.HIGH, GPIO.LOW))
time.sleep(wait)
GPIO.output ([6, 25, 16], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH))
async def rotate_left (self, wait):
print("GPIOControl: rotate_left")
GPIO.output ([27, 5, 17], (GPIO.HIGH, GPIO.LOW, GPIO.HIGH))
await asyncio.sleep(wait)
GPIO.output ([27, 5, 17], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH))
async def rotate_right (self, wait):
print("GPIOControl: rotate_right")
GPIO.output ([27, 5, 22], (GPIO.LOW, GPIO.HIGH, GPIO.LOW))
await asyncio.sleep(wait)
GPIO.output ([27, 5, 22], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH))
async def rotate_left_az (self, azimuth, info):
print("GPIOControl: rotate_left_az")
targ_az = (int(azimuth) + info.getInf("DOMEOFF") + 2) % 360 # 2 for coast
got_there = False
GPIO.output ([27, 5, 17], (GPIO.HIGH, GPIO.LOW, GPIO.HIGH)) # start rotation
curr_az = int(info.getInf("ADAZ"))
while (not got_there):
await asyncio.sleep(.2)
curr_az = int(info.getInf("ADAZ"))
if (curr_az <= (targ_az + 1) and curr_az >= (targ_az - 1)):
got_there = True
if (curr_az <= (targ_az + 1) and curr_az >= (targ_az - 10)):
got_there = True
GPIO.output ([27, 5, 17], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH)) # end rotation
async def rotate_right_az (self, azimuth, info):
print("GPIOControl: rotate_right_az")
targ_az = (int(azimuth) + info.getInf("DOMEOFF") - 2) % 360 # 2 for coast
got_there = False
GPIO.output ([27, 5, 22], (GPIO.LOW, GPIO.HIGH, GPIO.LOW)) # rotate
curr_az = int(info.getInf("ADAZ"))
while (not got_there):
await asyncio.sleep(.2)
curr_az = int(info.getInf("ADAZ"))
if (curr_az <= (targ_az + 1) and curr_az >= (targ_az - 1)):
got_there = True
if (curr_az <= (targ_az + 10) and curr_az >= (targ_az - 1)):
got_there = True
GPIO.output ([27, 5, 22], (GPIO.HIGH, GPIO.HIGH, GPIO.HIGH)) # end rotation