-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomeCommanderX.py
More file actions
175 lines (143 loc) · 5.7 KB
/
DomeCommanderX.py
File metadata and controls
175 lines (143 loc) · 5.7 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from PyQt5 import QtWidgets, uic
from PyQt5.QtCore import QTimer, QThread, pyqtSignal
from DCXui3 import Ui_MainWindow
import sys, time
from socket import *
def sendcommand(command):
#Function to comunicate with KoeppelX and issue commands
HOST = 'Hercules'
PORT = 65000
BUFSIZ = 1024
ADDR = (HOST, PORT)
tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)
tcpCliSock.send(command.encode('utf-8'))
response = tcpCliSock.recv(BUFSIZ)
tcpCliSock.close()
return response
def domestatus():
#Function to grab dome position and status
info = sendcommand('POSITION')
angle = float((info.split('\n'))[0])
if angle < 0.: angle = angle + 360.
if angle > 360.: angle = angle % 360.
info = sendcommand('DOMEBUSY')
status = int((info.split('\n'))[0])
return (angle,status)
class initThread(QThread):
#Class to run the initialization procedure moving the dome to +35 and calibrating
def __init__(self):
QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
jnk = sendcommand('goto +40')
time.sleep(1)
while domestatus()[1] == 1:
time.sleep(1)
jnk = sendcommand('calibrate')
time.sleep(1)
while domestatus()[1] == 1:
time.sleep(1)
class parkThread(QThread):
#Class to execute comands to park the dome at -30 from the calibrate point
def __init__(self):
QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
jnk = sendcommand('calibrate')
time.sleep(1)
while domestatus()[1] == 1:
time.sleep(1)
jnk = sendcommand('goto -30')
time.sleep(1)
while domestatus()[1] == 1:
time.sleep(1)
class mywindow(QtWidgets.QMainWindow):
#Main GUI for the dome commander, listens to Signals and activates Slots
def __init__(self):
#Initiate the GUI
super(mywindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#Listeners for all control button signals, connects them to slots
self.ui.initButton.clicked.connect(self.initClicked)
self.ui.calibButton.clicked.connect(self.calibClicked)
self.ui.parkButton.clicked.connect(self.parkClicked)
self.ui.trackButton.clicked.connect(self.trackClicked)
self.ui.stopButton.clicked.connect(self.stopClicked)
self.ui.gotoButton.clicked.connect(self.gotoClicked)
self.ui.lineEdit.returnPressed.connect(self.gotoClicked)
self.ui.gp5Button.clicked.connect(self.gp5Clicked)
self.ui.gm5Button.clicked.connect(self.gm5Clicked)
#This loops the posBar procedure every timer cycle in ms
timer=QTimer(self)
timer.timeout.connect(self.posBar)
timer.start(500)
def initClicked(self):
#Actions once Initialize is clicked (uses new threaded class)
self.statusBar().showMessage('Initializing Dome')
try:
if self.myThread.isRunning():
self.myThread.terminate()
except:
pass
self.myThread = initThread()
self.myThread.finished.connect(lambda: self.statusBar().showMessage('Initialized!'))
self.myThread.start()
def calibClicked(self):
#Actions when Calibrate is Clicked (functions built into KoepelX)
self.statusBar().showMessage(sendcommand('calibrate'))
def parkClicked(self):
#Actions once Park is clicked (uses new threaded class)
self.statusBar().showMessage('Parking Dome')
try:
if self.myThread.isRunning():
self.myThread.terminate()
except:
pass
self.myThread = parkThread()
self.myThread.finished.connect(lambda: self.statusBar().showMessage('Parked!'))
self.myThread.start()
def trackClicked(self):
#Actions once Track is clicked (functions built into KoepelX)
self.statusBar().showMessage(sendcommand('track'))
def stopClicked(self):
#Actions once Stop is clicked (informs KoepelX and tries to stop other threads)
try:
if self.myThread.isRunning():
self.myThread.terminate()
except:
pass
self.statusBar().showMessage(sendcommand('stop'))
def gotoClicked(self):
#Actions when GoTo is clicked (sends contents of list box, checks first that somewhere)
if self.ui.lineEdit.text() == '':
self.statusBar().showMessage('Nowhere to GoTo!')
else:
self.statusBar().showMessage(sendcommand('goto '+self.ui.lineEdit.text()))
self.ui.lineEdit.setText('')
def gp5Clicked(self):
#Actions when rotate plus 5 button is clicked
self.statusBar().showMessage(sendcommand('goto +5'))
def gm5Clicked(self):
#Actions when rotate miuns 5 button is clicked
self.statusBar().showMessage(sendcommand('goto -5'))
def posBar(self):
#Cycle to update postition bar and status indicator (blinks if active)
status = domestatus()
self.ui.progressBar.setValue(status[0])
if status[1] == 1:
if self.ui.radioButton.isChecked():
self.ui.radioButton.setChecked(False)
else:
self.ui.radioButton.setChecked(True)
else:
self.ui.radioButton.setChecked(False)
#Run the application
app = QtWidgets.QApplication([])
application = mywindow()
application.setFixedSize(application.size())
application.show()
sys.exit(app.exec_())