forked from saltastro/timDIMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GTO900.rb
executable file
·484 lines (419 loc) · 9.36 KB
/
GTO900.rb
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
##### this is a ruby implementation of the Astro-Physics GTO900 serial command protocol
require 'timeout'
require 'socket'
require 'ast_utils'
### GTO900 routines
class GTO900
def initialize(host='massdimm.suth', port=7001)
@port = sockopen(host, port)
@catalog = hr_catalog
end
# wrapper for opening socket and dealing with timeouts
def sockopen(host, port)
socket = nil
status = nil
time = 3.0
begin
timeout(time) {
socket = TCPSocket.open(host, port)
}
rescue TimeoutError
status = "Timeout"
return nil
rescue Errno::ECONNREFUSED
status = "Refusing connection"
return nil
rescue => why
status = "Error: #{why}"
return nil
end
return socket
end
def close
@port.close
@port = nil
end
# read output from the GTO900. the GTO900 usually outputs a '#'
# terminated string, but not always....
def read_GTO900
string = ""
begin
timeout(5) {
loop {
char = @port.read(1)
if char
break if char =~ /#/
string = string + char
else
break
end
}
}
rescue TimeoutError
status = "Timeout"
return nil
rescue Errno::ECONNREFUSED
status = "Refusing connection"
return nil
rescue => why
status = "Error: #{why}"
return nil
end
return string
clear
end
# check the boolean 1/0 returns from the mount
def check_GTO900
result = @port.read(1)
clear
return result
end
# send a command off to the GTO900
def command(string)
@port.send(string, 0)
end
# clear input buffer
def clear
command("#")
end
# set long format
def long_format
command("#:U#")
end
# set the offset from greenwich mean time
def set_gmt_offset(hrs)
command("#:SG #{hrs}#")
return check_GTO900
end
# set the current longitude
def set_longitude(d, m, s)
str = "%d*%02d:%02d" % [d, m, s]
command("#:Sg #{str}#")
return check_GTO900
end
# set the current latitude
def set_latitude(d, m, s)
str = "%d*%02d:%02d" % [d, m, s]
command("#:St #{str}#")
return check_GTO900
end
# set current date (MM/DD/YY)
def set_current_date
time = Time.new
ut = time.getutc
date = ut.strftime("%m/%d/%Y")
command("#:SC #{date}#")
blah = read_GTO900
return read_GTO900
end
# set local time (HH:MM:SS)
def set_local_time
time = Time.new
str = time.strftime("%H:%M:%S")
command("#:SL #{str}#")
return check_GTO900
end
# get UTC offset from GTO900
def get_UTC_offset
command("#:GG#")
string = read_GTO900
sign, h, m, s, ds = string.scan(/(.)(\d+):(\d+):(\d+).(\d+)/)[0]
return sign + h
end
# get current site longitude
def get_longitude
command("#:Gg#")
string = read_GTO900
sign, d, m, s = string.scan(/(.)(\d+)\*(\d+):(\d+)/)[0]
output = sign + d + ":" + m + ":" + s
return output
end
# get current site latitude
def get_latitude
command("#:Gt#")
string = read_GTO900
sign, d, m, s = string.scan(/(.)(\d+)\*(\d+):(\d+)/)[0]
output = sign + d + ":" + m + ":" + s
return output
end
# get local time
def get_local_time
command("#:GL#")
string = read_GTO900
return string
end
# get local date
def get_local_date
command("#:GC#")
string = read_GTO900
string.gsub(':', '/')
return string
end
# get LST
def lst
command("#:GS#")
return read_GTO900
end
# read the current RA from the GTO900
def ra
command("#:GR#")
return read_GTO900
end
# read the current declination from the GTO900
def dec
command("#:GD#")
string = read_GTO900
output = ""
sign, d, m, s = string.scan(/(.)(\d+)\*(\d+):(\d+)/)[0]
output = sign + d + ":" + m + ":" + s
return output
end
# read the current altitude from the GTO900
def alt
command("#:GA#")
string = read_GTO900
output = ""
sign, d, m, s = string.scan(/(.)(\d+)\*(\d+):(\d+)/)[0]
output = sign + d + ":" + m + ":" + s
return output
end
# calculate current GTO900 airmass
def airmass
a = alt
ang = Math::PI*(90.0-hms2deg(a))/180.0
return 1.0/Math::cos(ang)
end
# read the current azimuth from the GTO900
def az
command("#:GZ#")
string = read_GTO900
output = ""
if string
d, m, s = string.scan(/(\d+)\*(\d+):(\d+)/)[0]
output = d + ":" + m + ":" + s
return output
else
return nil
end
end
# command the GTO900 to slew to the target RA and Dec
def slew
command("#:MS#")
result = @port.read(1)
if result.to_i == 0
return "Slewing...."
else
return read_GTO900
end
end
# command the GTO900 to move in the given direction at
# the current guide or centering rate
def move(dir)
if dir == "e" || dir == "n" || dir == "s" || dir == "w"
command("#:M#{dir}#")
end
end
# command the GTO900 to move in the given direction at
# the current guide or centering rate
# for a given number of ms
def move_ms(dir, ms)
if dir == "e" || dir == "n" || dir == "s" || dir == "w"
command("#:M#{dir}#{ms}#")
end
end
# swap north-south buttons
def swap_ns
command("#:NS#")
end
# swap east-west buttons
def swap_ew
command("#:EW#")
end
# command the GTO900 to stop motion in the given direction
def halt(dir)
if dir == "e" || dir == "n" || dir == "s" || dir == "w"
command("#:Q#{dir}#")
end
end
# command the GTO900 to halt all mount motion
def haltall
command("#:Q#")
end
# select guide rate
def select_guide_rate(rate='')
if rate == '' || rate == '0' || rate == '1' || rate == '2'
command("#:RG#{rate}#")
end
end
# select centering rate
def select_center_rate(rate='')
if rate == '' || rate == '0' || rate == '1' || rate == '2' || rate == '3'
command("#:RC#{rate}#")
end
end
# set centering rate
def set_center_rate(rate)
if rate > 0 && rate < 256
command("#:Rc#{rate}#")
end
end
# select slew rate
def select_slew_rate(rate='')
if rate == '' || rate == '0' || rate == '1' || rate == '2'
command("#:RS#{rate}#")
end
end
# set slew rate
def set_slew_rate(rate)
if rate > 0 && rate <= 1200
command("#:Rs#{rate}#")
end
end
# select tracking rate
def select_tracking_rate(rate='')
if rate == '' || rate == '0' || rate == '1' || rate == '2' || rate == '9'
command("#:RS#{rate}#")
end
end
# set RA tracking rate
def set_RA_rate(rate)
command("#:RR #{rate}#")
end
# set Dec tracking rate
def set_Dec_rate(rate)
command("#:RD #{rate}#")
end
# set amount of Dec backlash compensation (in seconds)
def set_Dec_backlash(sec)
command("#:Bd 00*00:#{sec}#")
return read_GTO900
end
# set amount of RA backlash compensation (in seconds)
def set_RA_backlash(sec)
command("#:Br 00:00:#{sec}#")
return read_GTO900
end
# invoke parked mode
def park_mode
command("#:KA#")
end
# park off
def park_off
command("#PO:#")
end
# query pier
def pier?
command("#:pS#")
return read_GTO900
end
# sync mount
def sync
command("#:CM#")
return read_GTO900
end
# re-cal mount
def recal
command("#:CMR#")
return read_GTO900
end
# define commanded RA
def command_ra(h, m, s)
str = "%02d:%02d:%02d" % [h,m,s]
command("#:Sr #{str}#")
return check_GTO900
end
def command_ra_raw(str)
command("#:Sr #{str}#")
return check_GTO900
end
# define commanded Dec
def command_dec(d, m, s)
str = "%d*%02d:%02d" % [d,m,s]
command("#:Sd #{str}#")
return check_GTO900
end
def command_dec_raw(str)
command("#:Sd #{str}#")
return check_GTO900
end
# define commanded Alt
def command_alt(d, m, s)
str = "%d*%02d:%02d" % [d,m,s]
command("#:Sa #{str}#")
return check_GTO900
end
# define commanded Az
def command_az(d, m, s)
str = "%d*%02d:%02d" % [d,m,s]
command("#:Sz #{str}#")
return check_GTO900
end
# increase reticle brightness
def increase_reticle_brightness
command("#:B+#")
end
# decrease reticle brightness
def decrease_reticle_brightness
command("#:B-#")
end
# command the focuser to move inward (toward the primary)
def focus_in
command("#:F+#")
end
# command the focuser to move outward (away from the primary)
def focus_out
command("#:F-#")
end
# focus fast
def focus_fast
command("#:FF#")
end
# focus slow
def focus_slow
command("#FS#")
end
# halt all focuser motion
def focus_halt
command("#:FQ#")
end
# get telescope firmware
def get_firmware
command("#:V#")
return read_GTO900
end
# slew to star in HR catalog
def slew_HR(hr)
hr = hr.to_s
ra = @catalog[hr][:ra]
dec = @catalog[hr][:dec]
command_ra_raw(ra)
command_dec_raw(dec)
slew
end
# startup procedure
def startup
clear
clear
clear
long_format
# set_RA_backlash(0)
# set_Dec_backlash(0)
# set_local_time
# set_current_date
# set_latitude(-32, 22, 32)
# set_longitude(-20, 48, 30)
# set_gmt_offset(-2)
# park_off
# haltall
end
# shutdown procedure
def shutdown
clear
# set_local_time
# set_current_date
# set_latitude(-32, 22, 32)
# set_longitude(-20, 48, 30)
# set_gmt_offset(-2)
# park_mode
end
end