-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslew.py
More file actions
376 lines (309 loc) · 13 KB
/
Copy pathslew.py
File metadata and controls
376 lines (309 loc) · 13 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
'''
SLEWING, with error detect and status output
import slew
type = 'hor' (alt/az) or 'equ' (ra/dec)
axis1 = r/a or alt
axis2 = dec or az
slew.slew(type, axis1, axis2)
#[com dot hotmail @ rlw1138] -- 2020-APR-15
'''
import logging
import time
from datetime import datetime
class Slew:
def abort(self, parent, controller):
'''stops movement'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.stop()
self.controller.scope.tracking_off()
msg = "Movement Stopped"
self.controller.DisplayWarning(msg)
def home(self, parent, controller):
'''go to the home position
return codes:
0 - returning home
1 - already home
2 - parked
'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.update_status()
type = self.controller.scope.slew_type
if self.controller.scope.is_home is True:
msg=' Mount is already at Home'
self.controller.DisplayWarning(msg)
self.controller.app_data["var_GTobject"].set('')
rc = 1
return rc, msg
elif self.controller.scope.is_parked is True:
msg=' Mount is already Parked'
self.controller.DisplayWarning(msg)
self.controller.app_data["var_GTobject"].set('')
rc = 2
return rc, msg
else:
msg=' Returning to home postion'
self.controller.DisplayWarning(msg)
logging.info(f"Returning Home") #to the logfile
# return-home command does not return a value
self.controller.scope.return_home()
self.controller.app_data["var_GTobject"].set('')
rc = 0
return rc, msg
def reset_home(self, parent, controller):
'''reset the home position'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
#print(' Reset Home will clear the corrective pointing model!')
# self.controller.scope.reset_home() does not return a value
self.controller.scope.reset_home()
msg=' Home position reset -- re-Align recommended'
self.controller.DisplayWarning(msg)
logging.info(f"Home position reset") #to the logfile
def park(self, parent, controller):
'''go to the park position
return codes:
0 - parking
1 - already parked
2 - error
'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.update_status()
if self.controller.scope.is_parked is True:
self.controller.app_data["var_IsTracking"].set(0)
msg = ' Mount is already parked'
self.controller.DisplayWarning(msg)
self.controller.app_data["var_GTobject"].set('')
rc = 1
return rc, msg
else:
#print(' Returning to Parked postion')
if self.controller.scope.park(): # SUCCESS == 1
self.controller.DisplayWarning("Parking")
logging.info(f"Parking") #to the logfile
self.controller.app_data["var_GTobject"].set('')
rc = 0
return rc, "Parking"
else:
msg=' ERROR: Park command failed'
self.controller.DisplayError(msg)
logging.error(msg.replace(' ERROR: ','')) #to the logfile
rc = 2
return rc, msg
def un_park(self, parent, controller):
'''allow leaving the park position'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.update_status()
if self.controller.scope.is_parked is True:
if self.controller.scope.un_park(): # SUCCESS == 1
msg=' UN-Parked -- tracking ON'
self.controller.DisplayWarning(msg)
logging.info(f'UN-Parked -- tracking ON')
self.controller.scope.tracking_on() #SUCCESS == 1
self.controller.app_data["var_IsTracking"].set(1)
self.controller.app_data["var_GTobject"].set('')
else:
msg=' ERROR: Un-Park command failed'
self.controller.DisplayError(msg)
logging.error(f"Un-Park command failed")
def set_park(self, parent, controller):
'''set the park position'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
if self.controller.scope.set_park(): # SUCCESS == 1
msg=' Park position reset'
self.controller.DisplayWarning(msg)
logging.info(f"Park position reset")
else:
msg=' ERROR: Reset Park command failed'
self.controller.DisplayError(msg)
logging.error(f"Reset-Park command failed")
def toggle_tracking(self, parent, controller):
'''tracking on and off
errors:
0 - success (on or off)
1 - parked
2 - cannot switch OFF
3 - cannot switch ON
'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.update_status()
if self.controller.scope.is_parked is True:
msg = "Cannot turn on Tracking -- Mount is parked"
self.controller.DisplayWarning(msg)
self.controller.app_data["var_GTobject"].set('')
rc = 1
return rc, msg
if self.controller.scope.is_tracking:
if self.controller.scope.tracking_off(): #SUCCESS == 1
self.controller.app_data["var_IsTracking"].set(0)
msg=" Tracking switched 'off'"
logging.info(msg)
rc = 0
return rc, msg
else:
msg=" ERROR: Tracking could not be switched 'off'"
self.controller.DisplayError(msg)
logging.error(msg.replace(' ERROR: ',''))
rc = 2
return rc, msg
else:
if self.controller.scope.tracking_on(): #SUCCESS == 1
self.controller.app_data["var_IsTracking"].set(1)
msg=" Tracking switched 'on'"
logging.info(msg)
rc = 0
return rc, msg
else:
msg=" ERROR: Tracking could not be switched 'on'"
self.controller.DisplayError(msg)
logging.error(msg.replace(' ERROR: ',''))
rc = 3
return rc, msg
def toggle_autoflip(self, parent, controller):
'''automatic meridian flip on and off'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.update_status()
if self.controller.scope.auto_flip is True:
self.controller.scope.set_autoflip_off() # success == 1
self.controller.app_data["var_AFlip_State"].set(0)
else:
self.controller.scope.set_autoflip_on()
self.controller.app_data["var_AFlip_State"].set(1)
def toggle_pauseHome(self, parent, controller):
'''automatic meridian flip pause-at-home on and off'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
self.controller.scope.update_status()
if self.controller.scope.pause_at_home is True:
self.controller.scope.set_aflip_pause_off() # success == 1
self.controller.app_data["var_Pause_State"].set(0)
else:
self.controller.scope.set_aflip_pause_on()
self.controller.app_data["var_Pause_State"].set(1)
def flip_now(self, parent, controller, type):
'''do a meridian flip if possible'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
rc, text = self.controller.scope.flip_now()
if rc != '0': # SUCCESS == ZERO!
msg=' ERROR: Meridian-flip failed: rc: {} - {}'.format(rc, text)
self.controller.DisplayError(msg)
logging.error(msg.replace(' ERROR: ','')) #to the logfile
return rc, msg
else:
slew_end = False
msg = ' Starting Meridian flip'
self.controller.DisplayWarning(msg)
logging.info(msg) #to the logfile
# time.sleep(2)
# msg = ' flip: rc({}) - {}'.format(rc,text)
# self.controller.DisplayWarning(msg)
'''
I thought about having slew() use the mount type that's
stored in the OnStep controller, or at least compare the
saved type to the one that's passed-in as a param,
because that makes sense, right?
Then I remembered that stress_test() uses Alt/Az params
even on an EQU mount
So....
'''
def slew(self, parent, controller, type, axis1, axis2):
'''do the actual slewing motion
errors:
0 - success
1 - Error turning tracking on
2 - ALT must be signed +/-
3 - Error setting target ALT or R/A
4 - AZ must be 3 digits
5 - Error setting target AZ or DEC
6 - SLEW FAILED
7 -
'''
def __init__(self, parent, controller, *args, **kwargs):
self.parent = parent
self.controller = controller
rc = self.controller.scope.tracking_on()
# if rc == '0': # SUCCESS == 1
# msg = 'Error turning tracking on'
# self.controller.DisplayError(msg)
# rc = 1
# return rc, msg
self.type = type.lower()
self.controller.scope.update_status()
#saved_type = self.controller.scope.slew_type.lower()
#if saved_type != type:
# print('SLEW: parameter "type" [{}] does not match saved mount type [{}]'.format(type, saved_type))
# return False
if self.type == 'hor' or self.type == 'altaz':
# check for 'Signed' Altitude
if axis1[0] != '+' and axis1[0] != '-':
msg = 'Error: ALT must be signed +/-'
rc = 2
return rc, msg
rc = self.controller.scope.set_target_alt(axis1)
if rc == '0': # SUCCESS == 1
msg = 'Error setting target ALT: ' + axis1
rc = 3
return rc, msg
# check Azimuth for 3-digit degrees
if (len(axis2) > 3 and axis2[3] != ':') or len(axis2) < 3:
msg = 'Error: AZ must be 3 digits'
rc = 4
return rc, msg
rc = self.controller.scope.set_target_azm(axis2)
if rc == '0': # SUCCESS == 1
msg = 'Error setting target AZ: ' + axis2
rc = 5
return rc, msg
rc, msg = self.controller.scope.slew_hor()
if rc != '0': # SUCCESS == ZERO!
text = 'ERROR: Slew to Alt: {} Az: {} failed: rc: {}: {}'.format(axis1, axis2, rc, msg)
logging.error(text.replace('ERROR: ','')) #to the logfile
rc = 6
return rc, text
else:
self.app_data["var_Slewing"].set( 'YES <--' )
text = 'Slewing to Alt: {} Az: {}'.format(axis1, axis2)
logging.info(text)
rc = 0
return rc, text
else:
self.type == 'equ' # force equatorial, until we TO-DO: figure out what "fork alternate" means!
# it's probably "alt-az fork on a wedge....."
rc = self.controller.scope.set_target_ra(axis1)
if rc == '0': # SUCCESS == 1
msg = 'Error setting target R/A: ' + axis1
rc = 3
return rc, msg
rc = self.controller.scope.set_target_de(axis2)
if rc == '0': # SUCCESS == 1
msg = 'Error setting target DEC: ' + axis2
rc = 5
return rc, msg
rc, msg = self.controller.scope.slew_equ()
if rc != '0': # SUCCESS == ZERO!
text = 'ERROR: Slew to R/A: {} DEC: {} failed: rc: {}: {}'.format(axis1, axis2, rc, msg)
logging.error(text.replace('ERROR: ','')) #to the logfile
rc = 6
return rc, text
else:
self.app_data["var_Slewing"].set( 'YES <--' )
text = 'Slewing to R/A: {} DEC: {}'.format(axis1, axis2)
logging.info(text)
return rc, text