forked from badders/solar_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solar_drive.py
161 lines (129 loc) · 4.92 KB
/
solar_drive.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
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
# -*- coding: utf-8 -*-
"""
GUI Application for controlling the solar telescope
"""
import logging
import solar
import os
import sys
from datetime import datetime
from PyQt4 import QtGui, QtCore, uic
def get_ui_file(name):
"""
Helper function to automatically correct path for files in ui/
"""
return os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui', name)
class SolarDriverApp(QtGui.QApplication):
"""
The actual application. Handles loading the interface and connecting together
the interface elements to their respective functions
"""
def __init__(self):
super(SolarDriverApp, self).__init__([])
ui = uic.loadUi(get_ui_file('solar_drive.ui'))
self.ui = ui
logging.getLogger().setLevel(logging.INFO)
self.telescope = solar.TelescopeManager()
self.telescope.start()
self.ui.latitude.valueChanged.connect(self.set_latitude)
self.ui.longitude.valueChanged.connect(self.set_longitude)
self.ui.azAdjust.valueChanged.connect(self.tune)
self.ui.altAdjust.valueChanged.connect(self.tune)
ui.show()
ui.raise_()
timer = QtCore.QTimer(self)
timer.timeout.connect(self.update_time)
timer.start(200)
ui.trackButton.clicked.connect(self.track)
ui.findSun.clicked.connect(self.find_sun)
ui.zeroReturn.clicked.connect(self.return_to_zero)
ui.azLeft.clicked.connect(self.azLeft)
ui.azRight.clicked.connect(self.azRight)
ui.altLeft.clicked.connect(self.altLeft)
ui.altRight.clicked.connect(self.altRight)
ui.setZero.clicked.connect(self.telescope.set_zero)
ui.setSun.clicked.connect(self.telescope.set_sun)
ui.setZero.hide()
self.aboutToQuit.connect(self.terminating)
self.load_config()
def terminating(self):
"""
Called just before the application quits
"""
self.telescope.join()
self.save_config()
def load_config(self):
"""
Load the configuration
"""
settings = QtCore.QSettings('Solar Control', 'solar_drive')
settings.beginGroup('Position')
self.telescope.az = settings.value('az', 0).toPyObject()
self.telescope.alt = settings.value('alt', 0).toPyObject()
self.telescope.latitude = settings.value('lat', self.ui.latitude.value()).toPyObject()
self.telescope.longitude = settings.value('long', self.ui.longitude.value()).toPyObject()
settings.endGroup()
def save_config(self):
"""
Save the configuration
"""
settings = QtCore.QSettings('Solar Control', 'solar_drive')
settings.beginGroup('Position')
settings.setValue('az', self.telescope.az)
settings.setValue('alt', self.telescope.alt)
settings.setValue('lat', self.telescope.latitude)
settings.setValue('lat', self.telescope.longitude)
def set_latitude(self, value):
self.telescope.latitude = value
def set_longitude(self, value):
self.telescope.longitude = value
def azLeft(self):
arc = self.ui.calArcSec.value()
self.telescope.slew_az(-arc)
def azRight(self):
arc = self.ui.calArcSec.value()
self.telescope.slew_az(arc)
def altLeft(self):
arc = self.ui.calArcSec.value()
self.telescope.slew_alt(-arc)
def altRight(self):
arc = self.ui.calArcSec.value()
self.telescope.slew_alt(arc)
def track(self):
if self.telescope.tracking:
logging.info('Tracking Cancelled')
self.telescope.stop_tracking()
self.ui.calibrationTab.setEnabled(True)
return
logging.info('Tracking Sun Commencing')
self.ui.calibrationTab.setEnabled(False)
self.find_sun()
self.telescope.start_tracking()
def find_sun(self):
self.telescope.slew_to_sun()
def return_to_zero(self):
self.telescope.return_to_zero()
def tune(self):
t_az = self.ui.azAdjust.value()
t_alt = self.ui.altAdjust.value()
self.telescope.tune([t_az, t_alt])
def update_time(self):
"""
Called repeatedly to check for any updates and to update the time
and position displays
"""
self.telescope.flush_messages()
lt = datetime.now()
qlt = QtCore.QTime(lt.hour, lt.minute, lt.second)
self.ui.localTime.setTime(qlt)
utc = datetime.utcnow()
qutc = QtCore.QTime(utc.hour, utc.minute, utc.second)
self.ui.utcTime.setTime(qutc)
mst = solar.mean_solar_time(self.ui.longitude.value())
qmst = QtCore.QTime(mst.hour, mst.minute, mst.second)
self.ui.solarTime.setTime(qmst)
self.ui.azDisplay.setText(solar.az_to_str(self.telescope.az))
self.ui.altDisplay.setText(solar.alt_to_str(self.telescope.alt))
if __name__ == '__main__':
app = SolarDriverApp()
sys.exit(app.exec_())