The VisAO Camera
gimbalops.py
1 
2 import visao
3 import numpy
4 import time
5 from Numeric import *
6 
7 
8 #to do: Move these to the main visao module.
9 
10 def dither_phot(filters, nims, ndarks, dx, dy, subdir="", appendts=1):
11 
12  try:
13  if subdir == "":
14  subdir = "phot_dither"
15 
16 
17  if appendts:
18  sdbase = visao.get_visao_filename_now(subdir)
19  else:
20  sdbase = subdir
21 
22  vis=visao.VisAO()
23  vis.take_control()
24 
25  for i in range(len(filters)):
26 
27  print "Changing filter to %s . . ." % filters[i]
28  resp = vis.fw2.set_filter(filters[i])
29  time.sleep(2)
30 
31  print "Moving to focus preset . . ."
32  vis.focus.preset()
33 
34  resp = vis.fw2.wait_move()
35 
36  filt = vis.fw2.get_filter()
37 
38  print "In filter %s . . ." % filt
39 
40  if filt!= filters[i]:
41  print "Filter not correct."
42  break
43 
44  if(resp != 0):
45  print "Focus motor error. "
46  return
47 
48  vis.focus.wait_move()
49 
50  filtname = filt.replace(" ", "_")
51  filtname = filt.replace("'", "p")
52 
53  sd = "%s/%s" % (sdbase, filtname)
54  print sd
55 
56  vis.dither(dx, dy, nims, ndarks, sd, 0,0)
57 
58 
59  vis.giveup_control()
60  visao_script_complete()
61 
62  except:
63  print '******************\nSomething bad happened\n******************\n'
64  visao.visao_alert(1)
65  raise
66 
67 
68 def scan(xcen, ycen, r0, dr, ang, ims, ndarks, subdir=""):
69 
70  ang = ang*3.14159/180.0
71 
72  x0 = xcen - r0*cos(ang)
73  y0 = ycen - r0*sin(ang)
74 
75  vis = visao.VisAO()
76 
77  dx = range(2*r0/dr)
78 
79  vis.take_control()
80 
81  #gimb = visao.Gimbal()
82  vis.gimbal.take_control()
83 
84  #ccd = VisAOScript.CCD47Ctrl()
85  #vi.ccd.take_control()
86 
87  if subdir=="":
88  subdir = visao.get_visao_filename_now("scan_")
89 
90  print "Moving to %f %f . . ." % (x0 , y0)
91 
92  rv = vis.gimbal.move_xabs(x0)
93  if rv != 0:
94  print "Error during x dither. Halting."
95  return
96 
97  rv = vis.gimbal.move_yabs(y0)
98  if rv != 0:
99  print "Error during y dither. Halting."
100  return
101 
102  vis.ccd47.subdir(subdir)
103 
104  vis.take_darks(ndarks)
105 
106  print "Saving %i images at position 1/%i" % (ims, len(dx))
107  vis.take_science(ims)
108 
109  for i in range(len(dx)):
110  x0 = xcen - r0*cos(ang) + dr*cos(ang)*i
111  y0 = ycen - r0*sin(ang) + dr*sin(ang)*i
112 
113  print "Dither %i/%i: %f %f . . ." % (i,len(dx), x0 , y0)
114  rv = vis.gimbal.move_xabs(x0)
115  if rv != 0:
116  print "Error during x dither. Halting."
117  break
118 
119  rv = vis.gimbal.move_yabs(y0)
120  if rv != 0:
121  print "Error during y dither. Halting."
122  break
123 
124  rv = vis.gimbal.wait_move()
125  if rv != 0:
126  print "Error during dither. Halting."
127  break
128 
129  rv = vis.take_science(ims)
130 
131  rv = vis.gimbal.move_xabs(xcen)
132 
133  rv = vis.gimbal.move_yabs(ycen)
134 
135  rv = vis.gimbal.wait_move()
136 
137  vis.ccd47.subdir(".")
138 
139  #vis.giveup_control()
140  #gimb.giveup_control()
141  #ccd.giveup_control()
142