Attachment 'MICH_LOCK.py'
Download 1 import time
2 import math
3 from guardian import GuardState
4 from guardian import GuardStateDecorator
5 from guardian import NodeManager
6 import subprocess
7 import numpy as np
8 #import pyttsx
9 ##################################################
10 # initialization values
11
12 # initial REQUEST state
13 request = 'OPERATION'
14
15 # NOMINAL state, which determines when node is OK
16 nominal = 'OPERATION'
17
18 ##################################################
19 nodes = NodeManager(['IMC_LOCK','VIS_PR3','VIS_EX','VIS_EY'])
20
21 ##################################################
22 """
23 def #say(text):
24 engine = pyttsx.init()
25 engine.setProperty('rate', 100)
26 engine.#say(text)
27 engine.runAndWait()
28 """
29 def is_there_light():
30 return ezca['LSC-REFL_PDA1_DC_OUTPUT'] > 300
31
32 def is_mich_refl_quiet():
33 #"""return True if MICH is locked """
34 # How shall we make this condition?
35 if ezca['LSC-MICH_OUTMON'] != 0 and ezca['LSC-REFL_PDA1_RMSMON'] <= 400 and ezca['LSC-REFL_PDA1_DC_OUTPUT'] > 300:
36 return True
37 else:
38 return False
39
40 #else:
41 # return False
42 #Enomoto added LSC-MICH_INMON > 300 condition on 26 Mar 2016,
43 #to detect sudden lost of light.
44
45 def is_imc_locked():
46 nodes.set_managed()
47 if nodes['IMC_LOCK'] == 'IMC_LOCKED':
48 return True
49 else:
50 #return True
51 return False # IMC ga shinderu
52
53 def is_pr3_aligned():
54 nodes.set_managed()
55 if nodes['VIS_PR3'] == 'ALIGNED':
56 return True
57 else:
58 return False
59 """
60 def is_ex_aligned():
61 nodes.set_managed()
62 if nodes['VIS_EX'] == 'ALIGNED':
63 return True
64 else:
65 return False
66 """
67 def is_ey_aligned():
68 nodes.set_managed()
69 if nodes['VIS_EY'] == 'ALIGNED':
70 return True
71 else:
72 return False
73
74 #def is_everything_fine():
75
76
77 ##################################################
78 # STATE decorators
79
80 class refl_pd_check(GuardStateDecorator):
81 """Decorator to check that IMC is locked"""
82 def pre_exec(self):
83 if not is_there_light():
84 log('no light. ->FAULT')
85 if is_imc_locked():
86 notify('probably misaligned...')
87 return 'DOWN'
88
89 class mich_refl_quiet_check(GuardStateDecorator):
90 def pre_exec(self):
91 if not is_mich_refl_quiet():
92 log('Unlocked. -> LOCKLOSS')
93 notify('MICH lost lock!')
94 return 'LOCKLOSS'
95 else:
96 log('hoge-----')
97
98 class imc_lock_check(GuardStateDecorator):
99 """Decorator to check that IMC is locked"""
100 def pre_exec(self):
101 if not is_imc_locked():
102 log('unlocked. ->FAULT')
103 notify('IMC_is_unlocked!')
104 return 'DOWN'
105
106 class pr3_align_check(GuardStateDecorator):
107 #Decorator to check that PR3 is align
108 def pre_exec(self):
109 if not is_pr3_aligned():
110 log('aligned. ->FAULT')
111 notify('PR3_is_misaliged!')
112 return 'DOWN'
113 """
114 class ex_align_check(GuardStateDecorator):
115 #Decorator to check that EX is align
116 def pre_exec(self):
117 if not is_ex_aligned():
118 log('aligned. ->FAULT')
119 notify('EX_is_misaliged!')
120 return 'DOWN'
121 """
122 class ey_align_check(GuardStateDecorator):
123 #Decorator to check that EY is align
124 def pre_exec(self):
125 if not is_ey_aligned():
126 log('aligned. ->FAULT')
127 notify('EY_is_misaliged!')
128 return 'DOWN'
129 """
130 class operation_check(GuardStateDecorator):
131 #Decorator to check the operation condition
132 def pre_exec(self):
133 if is_everything_fine() == 1:
134 log('caliblation peak is not correct . ->FAULT')
135 notify('please check !')
136 return 'DOWN'
137 """
138
139 ##################################################
140 # STATE definitions
141
142 class INIT(GuardState):
143 index = 0
144 def main(self):
145 #say("I am MICH_LOCK.")
146 #nodes.set_managed()
147 nodes.set_managed()
148 nodes['VIS_EY'] = 'ALIGNED'
149 nodes['IMC_LOCK'] = 'IMC_LOCKED'
150 return True
151
152 class DOWN(GuardState):
153 index = 5
154 goto = True
155 def main(self):
156 nodes.set_managed()
157 #say("MICH is down")
158 #if nodes['VIS_EY'].stalled:
159 nodes['VIS_EY'] = 'ALIGNED'
160 #if nodes['IMC_LOCK'].stalled:
161 nodes['IMC_LOCK'] = 'IMC_LOCKED'
162 #if nodes['IMC_LOCK'].stalled:
163 nodes['VIS_PR3']='ALIGNED'
164 ezca.switch('LSC-REFL_PDA1_BANDLIM', 'FM1', 'ON')
165 self.timer['mytimer'] = 5
166 ezca['LSC-MICH_TRAMP'] = 4
167 ezca['LSC-MICH_GAIN'] = 0
168 ezca['LSC-CAL_OSC1_CLKGAIN'] = 0
169 ezca['LSC-CAL_OSC2_CLKGAIN'] = 0
170 ezca['LSC-ACT_OSC1_CLKGAIN'] = 0
171 ezca['LSC-ACT_OSC2_CLKGAIN'] = 0
172 ezca['LSC-ACT_OSC3_CLKGAIN'] = 0
173 ezca['LSC-UGF_SERVO_ENABLE'] = "OFF"
174
175 @pr3_align_check
176 @ey_align_check
177 @imc_lock_check
178 @refl_pd_check
179
180 # @ex_align_check
181 def run(self):
182 if self.timer['mytimer']:
183 return True
184 else:
185 ezca.switch('LSC-MICH', 'OUTPUT', 'OFF')
186 ezca.switch('LSC-MICH', 'FM1', 'OFF')
187 ezca.switch('LSC-MICH', 'FM2', 'OFF')
188 ezca.switch('LSC-MICH', 'FM3', 'OFF')
189 ezca['LSC-CONTROL_ENABLE'] = "OFF"
190
191 class ENGAGE_SERVO(GuardState):
192 index = 30
193 @pr3_align_check
194 @ey_align_check
195 @imc_lock_check
196 @refl_pd_check
197 def main(self):
198 ezca['LSC-CONTROL_ENABLE'] = "ON"
199 ezca.switch('LSC-MICH', 'OUTPUT', 'ON')
200 ezca.switch('LSC-MICH', 'FM1', 'ON')
201 #ezca.switch('LSC-MICH', 'FM3', 'ON')
202 time.sleep(3)
203 ezca['LSC-MICH_TRAMP'] = 4
204 ezca['LSC-MICH_GAIN'] = -50
205 self.timer['mytimer2'] = 10
206
207 @pr3_align_check
208 @ey_align_check
209 @imc_lock_check
210 #@ex_align_check
211 def run(self):
212 if self.timer['mytimer2']:
213 return True
214
215 class ENGAGE_BOOST(GuardState):
216 index = 40
217 @ey_align_check
218 @imc_lock_check
219 @pr3_align_check
220 @refl_pd_check
221 @mich_refl_quiet_check
222 def main(self):
223 ezca.switch('LSC-MICH','FM2','ON')
224 pass
225
226 class MICH_LOCKED(GuardState):
227 index = 100
228 @pr3_align_check
229 @ey_align_check
230 @imc_lock_check
231 @refl_pd_check
232 @mich_refl_quiet_check
233 def run(self):
234 return True
235
236
237 class CALIBRATION_INJECTION(GuardState):
238 index = 200
239 @pr3_align_check
240 @ey_align_check
241 @imc_lock_check
242 @refl_pd_check
243 @mich_refl_quiet_check
244 def main(self):
245 #
246 ezca['LSC-CAL_OSC1_FREQ'] = 80.0
247 ezca['LSC-CAL_OSC2_FREQ'] = 135.0
248 ezca['LSC-CAL_OSC1_SINGAIN'] = 1.0
249 ezca['LSC-CAL_OSC1_COSGAIN'] = 1.0
250 ezca['LSC-CAL_OSC2_SINGAIN'] = 1.0
251 ezca['LSC-CAL_OSC2_COSGAIN'] = 1.0
252 ezca['LSC-CAL_OSC1_CLKGAIN'] = 500 #10000
253 ezca['LSC-CAL_OSC2_CLKGAIN'] = 800 #10000
254 #
255 for i in range(1,5):
256 ezca.switch('LSC-CAL_DEMOD%d_I'%i, 'FM1', 'ON')
257 ezca.switch('LSC-CAL_DEMOD%d_Q'%i, 'FM1', 'ON')
258 ezca['LSC-CAL_DEMOD%d_I_GAIN'%i] = 1.0
259 ezca['LSC-CAL_DEMOD%d_Q_GAIN'%i] = 1.0
260 ezca.switch('LSC-CAL_DEMOD%d_I'%i, 'INPUT', 'ON')
261 ezca.switch('LSC-CAL_DEMOD%d_I'%i, 'OUTPUT', 'ON')
262 ezca.switch('LSC-CAL_DEMOD%d_Q'%i, 'INPUT', 'ON')
263 ezca.switch('LSC-CAL_DEMOD%d_Q'%i, 'OUTPUT', 'ON')
264 time.sleep(5)
265 pass
266
267
268 class ACTUATORCAL_INJECTION(GuardState):
269 index = 250
270 @pr3_align_check
271 @ey_align_check
272 @imc_lock_check
273 @refl_pd_check
274 @mich_refl_quiet_check
275 def main(self):
276 #
277 ezca['LSC-ACT_OSC1_FREQ'] = 111.0
278 ezca['LSC-ACT_OSC2_FREQ'] = 113.0
279 ezca['LSC-ACT_OSC3_FREQ'] = 115.0
280 ezca['LSC-ACT_OSC1_SINGAIN'] = 1.0
281 ezca['LSC-ACT_OSC1_COSGAIN'] = 1.0
282 ezca['LSC-ACT_OSC2_SINGAIN'] = 1.0
283 ezca['LSC-ACT_OSC2_COSGAIN'] = 1.0
284 ezca['LSC-ACT_OSC3_SINGAIN'] = 1.0
285 ezca['LSC-ACT_OSC3_COSGAIN'] = 1.0
286 ezca['LSC-ACT_OSC1_CLKGAIN'] = 600
287 ezca['LSC-ACT_OSC2_CLKGAIN'] = 600
288 ezca['LSC-ACT_OSC3_CLKGAIN'] = 600
289 #
290 for i in range(1,4):
291 ezca.switch('LSC-ACT_DEMOD%d_I'%i, 'FM1', 'ON')
292 ezca.switch('LSC-ACT_DEMOD%d_Q'%i, 'FM1', 'ON')
293 ezca['LSC-ACT_DEMOD%d_I_GAIN'%i] = 1.0
294 ezca['LSC-ACT_DEMOD%d_Q_GAIN'%i] = 1.0
295 ezca.switch('LSC-ACT_DEMOD%d_I'%i, 'INPUT', 'ON')
296 ezca.switch('LSC-ACT_DEMOD%d_I'%i, 'OUTPUT', 'ON')
297 ezca.switch('LSC-ACT_DEMOD%d_Q'%i, 'INPUT', 'ON')
298 ezca.switch('LSC-ACT_DEMOD%d_Q'%i, 'OUTPUT', 'ON')
299
300 time.sleep(5)
301 pass
302
303
304 class ENGAGE_UGF_SERVO(GuardState):
305 index = 500
306 @mich_refl_quiet_check
307 @imc_lock_check
308 @pr3_align_check
309 @ey_align_check
310 @refl_pd_check
311
312 def main(self):
313
314 ezca['LSC-OLTCALIB_MTRX_1_1'] = 0.8
315 ezca['LSC-OLTCALIB_MTRX_1_2'] = 0
316 ezca.switch('LSC-UGF_SERVO','INPUT','ON')
317 ezca.switch('LSC-UGF_SERVO','OUTPUT','ON')
318 ezca['LSC-UGF_SERVO_GAIN'] = 1.0
319 ezca['LSC-UGF_SERVO_ENABLE'] = "ON" # may need mytimer? I don't think so.
320 pass
321
322
323
324 class TAKE_SNAPSHOT(GuardState):
325 def main(self):
326 # take snapshot
327 reqfile = '/opt/rtcds/kamioka/k1/target/k1lsc/k1lscepics/autoBurt.req'
328 snapfile = '/opt/rtcds/userapps/release/lsc/k1/burtfiles/k1lsc_operation_condition.snap'
329 #subprocess.call(['burtrb', '-f', reqfile, '-o', snapfile])
330 return True
331
332 class OPERATION(GuardState):
333 index = 1000
334 @mich_refl_quiet_check
335 @imc_lock_check
336 # @pr3_align_check
337 # @ey_align_check
338
339 def run(self):
340 return True
341
342 class LOCKLOSS(GuardState):
343 """Record lockloss event"""
344 request = False
345 def main(self):
346 return True
347
348 edges = [
349 ('INIT', 'DOWN'),
350 ('DOWN', 'ENGAGE_SERVO'),
351 ('ENGAGE_SERVO','ENGAGE_BOOST'),
352 ('ENGAGE_BOOST','MICH_LOCKED'),
353 ('MICH_LOCKED','CALIBRATION_INJECTION'),
354 ('CALIBRATION_INJECTION','ACTUATORCAL_INJECTION'),
355 ('ACTUATORCAL_INJECTION','ENGAGE_UGF_SERVO'),
356 ('ENGAGE_UGF_SERVO','OPERATION'),
357 ('LOCKLOSS', 'DOWN'),
358 ]
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.