-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelcoll_gui
More file actions
executable file
·341 lines (297 loc) · 8.27 KB
/
elcoll_gui
File metadata and controls
executable file
·341 lines (297 loc) · 8.27 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
#!/usr/bin/ruby
require 'gtk2'
require 'thread'
require 'timeout'
require 'socket'
# Tom uses this to test on his home machine
$offline = Socket.gethostname =~ /trona/
# set a global path to find scripts and stuff
$wfsroot = "/mmt/shwfs"
$wfsroot = "." if $offline
$wfsroot = ENV['WFSROOT'] if ENV['WFSROOT']
require "#{$wfsroot}/msg.rb"
Thread.abort_on_exception = true
### define the main GUI window
class MainWindow
include MSG
def initialize(mode)
@mode = mode
@hostname = "hacksaw"
@wfsroot = $wfsroot
@offline = $offline
@dir = "#{@wfsroot}/datadir"
@netdir = "/net/#{@hostname}/home/mmt/shwfs/datadir"
#@glade = GladeXML.new("#{@wfsroot}/glade/elcoll_gui.glade") {|handler| method(handler)}
@builder = Gtk::Builder.new
@builder.add_from_file "#{@wfsroot}/glade/elcoll_gui.xml"
@builder.connect_signals {|handler| method(handler) }
@mainwindow = @builder.get_object("MainWindow")
@mainwindow.set_title("ElColl GUI")
@status = @builder.get_object("StatusBar")
@menubar = @builder.get_object("menubar1")
# exposure configuration
@expose = @builder.get_object("Expose")
@elstep = @builder.get_object("ElStep")
@azimuth = @builder.get_object("Azimuth")
@fileentry = @builder.get_object("FileEntry")
@fileentry.set_text("elcoll")
unless @offline
# Talk to the MSG server in the back end of shwfs_unified,
# which must be running on the same machine this runs on.
@wfsock = sockopen("localhost", 6868)
@telsock = sockopen("hacksaw", 5403)
@hexsock = sockopen("hexapod", 5350)
end
@el = 85.0
@step_sign = -1.0
system("touch #{@dir}/ELCOLL")
end
# kill the main window on a destroy
def on_MainWindow_destroy
unless @offline
@wfsock.close
@telsock.close
@hexsock.close
end
Gtk.main_quit
end
# routine to print to statusbar
def report(text)
@status.pop(0)
@status.push(0, text)
end
# menubar callbacks
def on_quit_activate
on_MainWindow_destroy
end
def on_about1_activate
report("First cut at a remote WFS interface")
end
# configure and take exposure
def on_Expose_toggled
if (@expose.active?)
@run = true
@expose.child.set_text("STOP")
azimuth = @azimuth.value.to_f
exptime = 5.0
step = @elstep.value.to_f
file = @fileentry.text
t = Thread.new {
while @run do
# figure out HA and Dec from alt and az
result = `#{@wfsroot}/wfscat/azel2radec #{azimuth} #{@el}`.split(' ')
ha = result[0].to_f
dec = result[1].to_f
# get lst
lst_hms = msg_get(@telsock, 'lst')
lst = hms2deg(lst_hms)
ra = lst - ha
if (ra > 24.0)
ra = ra - 24.0
end
if (ra < 0.0)
ra = ra + 24.0
end
# now lets find the closest WFS star to this ra/dec
star = `#{@wfsroot}/wfscat/findstars #{ra} #{dec} 5.0 10.0 | grep S | sort -n -k11 | head -5 | sort -rn -k3 | head -1`.split(' ')
star_ra = star[6]
star_dec = star[7]
pma = star[8]
pmd = star[9]
name = star[0] + " " + star[1]
# move the telescope there
report("Moving to: #{name} #{star_ra} #{star_dec}")
flag = move_tel(name, star_ra, star_dec, pma, pmd, 2000.0)
if !flag
report("Problem commanding slew.")
break
end
# sit in a loop until slew completes
inpos = 0
sleep(2)
loop do
inpos = msg_get(@telsock, 'inpos').to_i
break if inpos == 1
sleep(1)
end
system("echo \"apply_offsets\" | nc -w 5 hexapod 5340")
sleep(2)
# sit in a loop until hexapod completes moves
inmotion = 1
loop do
inmotion = msg_get(@hexsock, 'motionFlag').to_i
break if inmotion == 0
sleep(1)
end
sleep(2)
report("Slew Completed.")
sleep(1)
if @run == false
report("Aborting Elcoll.")
sleep(1)
break
end
# do two iterations per el
2.times {
# take and average 3 images
list = ""
3.times {
if @run == false
report("Aborting Elcoll.")
sleep(1)
break
end
# figure out the filename
num = 0
fullfilename = sprintf("%s/%s_%2d_%04d.fits", @dir, file, @el, num)
netfullfilename = sprintf("%s/%s_%2d_%04d.fits", @netdir, file, @el, num)
filename = sprintf("%s_%2d_%04d.fits", file, @el, num)
while test(?e, fullfilename)
num = num + 1
fullfilename = sprintf("%s/%s_%2d_%04d.fits", @dir, file, @el, num)
netfullfilename = sprintf("%s/%s_%2d_%04d.fits", @netdir, file, @el, num)
filename = sprintf("%s_%2d_%04d.fits", file, @el, num)
end
if exptime > 1
count = Thread.new {
left = exptime.to_i
left.times {
report("Exposing (#{filename})...#{left} sec left.")
sleep(1)
left = left - 1
}
report("Reading out (#{filename})....")
}
else
report("Exposing (#{filename})....")
end
# take the image
if (@mode == "F5")
system("#{@wfsroot}/getimage #{exptime} #{fullfilename}")
else
system("sudo -u mmtop /usr/bin/rsh -n -l tim f9wfs \"/home/tim/get_apogee_image.tcl #{exptime} #{filename} \> /dev/null\"")
system("sudo -u mmtop /usr/bin/rcp tim@f9wfs:/home/tim/#{filename} #{fullfilename}")
system("sudo -u mmtop /usr/bin/rsh -n -l tim f9wfs \"rm -f #{filename} \> /dev/null\"")
system("sudo -u mmtop chmod g+w #{fullfilename}")
end
system("#{@wfsroot}/header.pl #{fullfilename} #{exptime} #{@mode}")
system("/usr/bin/xpaset -p WFS zoom to 1.0")
system("/usr/bin/xpaset -p WFS file #{fullfilename}")
if list == ""
list = "#{fullfilename}"
else
list = list + ",#{fullfilename}"
end
}
if @run == false
report("Aborting Elcoll.")
sleep(1)
break
end
# analyze the image and apply corrections
report("Centroiding #{list}....")
msg_cmd(@wfsock, "centroid", list)
report("Applying Corrections....")
msg_cmd(@wfsock, "recenter", nil)
msg_cmd(@wfsock, "corr_coma", nil)
msg_cmd(@wfsock, "corr_focus", nil)
#msg_cmd(@wfsock, "corr_primary", nil)
sleep(2)
# sit in a loop until hexapod completes moves
inmotion = 1
loop do
inmotion = msg_get(@hexsock, 'motionFlag').to_i
break if inmotion == 0
sleep(1)
end
sleep(2)
inmotion = 1
loop do
inmotion = msg_get(@hexsock, 'motionFlag').to_i
break if inmotion == 0
sleep(1)
end
}
# figure out new el
if @el == 85.0
@step_sign = -1.0
end
if @el == 25.0
@step_sign = 1.0
end
@el = @el + @step_sign*step
report("Corrections done; going on to El = #{@el}....")
sleep(3)
# hexapod is done so log its current position
system("/mmt/shwfs/getm2info >> #{@dir}/ELCOLL")
system("echo \"all\" | nc hacksaw 7692 | egrep 'cell_(time|e_tc)' | xargs >> #{@dir}/ELCOLL_cell.log")
end
report("Completed Exposures.")
@expose.child.set_text("Take Exposures")
@expose.set_sensitive(true)
}
else
@run = false
@expose.set_sensitive(false)
end
end
def move_tel(name, ra, dec, rapm, decpm, epoch)
ra = hms2deg(ra)
dec = hms2deg(dec)
socket = sockopen('mount', 5241)
socket.send("newstar\n", 0)
socket.send("#{name}\n", 0)
socket.send("#{ra}\n", 0)
socket.send("#{dec}\n", 0)
socket.send("#{rapm}\n", 0)
socket.send("#{decpm}\n", 0)
socket.send("#{epoch}\n", 0)
socket.send("J\n", 0)
socket.send("elcoll: #{name}\n", 0)
answer = socket.gets
socket.close
socket = nil
if (answer =~ /OK/)
return true
else
return false
end
end
def sexagesimal(angle)
angle = angle.to_f
if (angle < 0)
angle = -angle
sign = "-"
else
sign = "+"
end
d = angle.to_i
x = (angle - d.to_f)*60.0
m = x.to_i
s = (x - m.to_f)*60.0
return sprintf("%s%02d:%02d:%05.2f", sign, d, m, s)
end
def hms2deg(string)
vals = string.split(':')
return 'bad' if vals.size != 3
hour = vals[0].to_f
if hour < 0
hour = hour * -1
end
min = vals[1].to_f
sec = vals[2].to_f
blah = hour + min/60.0 + sec/3600.0
if (string =~ /-/ && blah > 0.0)
blah = blah * -1
end
return blah
end
end
if !(ARGV[0] == "F5" || ARGV[0] == "F9")
puts "Specify F5 or F9."
else
# get the ball rolling!
Gtk.init
MainWindow.new(ARGV[0])
Gtk.main
end