source: fact/tools/PyDimCtrl/ScriptsForPyDimCtrl.py@ 14453

Last change on this file since 14453 was 14453, checked in by neise, 12 years ago
intial commit
File size: 26.9 KB
Line 
1#!/usr/bin/python
2
3import time
4
5last_drive_kwargs = {}
6last_drive_method = None
7
8def FadConnectCrate( crate ):
9 cratenum = None
10
11 if cate == 'all':
12 print "connecting to all crates"
13 for i in range( 40 ):
14 time.sleep(3.8)
15 fad_control.connect(i)
16 print "... done"
17 else:
18 try:
19 cratenum = int(crate)
20 except ValueError e:
21 print "cannot convert crate parameter to integer. crate=", crate
22 print e
23 raise
24
25 if cratenum != None:
26 print "connecting to crate", cratenum
27 for i in range(cratenum*10, (cratenum+1)*10 ):
28 time.sleep(3.8)
29 fad_control.connect(i)
30 print "... done"
31
32
33def FadDisconnectCrate( crate ):
34 cratenum = None
35
36 if cate == 'all':
37 print "connecting to all crates"
38 for i in range( 40 ):
39 fad_control.disconnect(i)
40 print "... done"
41 else:
42 try:
43 cratenum = int(crate)
44 except ValueError e:
45 print "cannot convert crate parameter to integer. crate=", crate
46 print e
47 raise
48
49 if cratenum != None:
50 print "connecting to crate", cratenum
51 for i in range(cratenum*10, (cratenum+1)*10 ):
52 fad_control.disconnect(i)
53 print "... done"
54
55
56
57def IsReadyForDataTaking():
58""" Checking the system statuses if they are ready for data taking
59"""
60
61 print "--------------------------------------"
62 print "Checking the system statuses of:"
63 print "FEEDBACK, BIAS and FAD"
64 print "--------------------------------------"
65
66 print "...waiting for FEEDBACK"
67 print " to be in state 12: CurrentControl"
68 feedback.wait(12)
69
70 print "...waiting for BIAS_CONTROL"
71 print " to be in state 9: VoltageOn"
72 bias_control.wait(9)
73
74 print "...waiting for FAD_CONTROL"
75 print " to be in state 4: Connected"
76 fad_control.wait(4)
77
78 print "...system statuses OK"
79 print "--------------------------------------"
80
81def NotReadyForDataTaking( servers_n_targets = [
82 (feedback, 12),
83 (bias_control, 9),
84 (fad_control, 4) ] ):
85""" Checking the system statuses if they are ready for data taking
86 return list of servers, which are NOT ready for Data Taking
87 so one can use this function like this
88 if not NotReadyForDataTaking():
89 # freak out
90 else:
91 # start data taking
92"""
93 not_ready = []
94
95 print "--------------------------------------"
96 print "Checking the system statuses of:"
97 for server,target in servers_n_targets:
98 print server.__name__ , ','
99 print
100 print "--------------------------------------"
101
102 for n, server, target in enumerate(servers_n_targets):
103 if server.stn != target:
104 print server.__name__, "NOT in state ", target
105 not_ready.apppend((server,target))
106
107 return not_ready
108
109
110
111def IsTracking():
112""" Name is misleading, it actually *waits* until Drive is in Tracking
113 original comment: Checking if Drive is in Status Tracking
114"""
115
116 #return drive_control.stn == 8
117 drive_control.wait(8)
118
119
120def PrepareBiasForDataTaking():
121""" should have the original behaviour, no new fancy features
122 check feedback state before switching BIAS ON and ramping up to nominal Voltage
123"""
124
125 start = time()
126 while (feedback.stn != 12):
127 time.sleep(0.1)
128 if time() > start + 10.:
129 print "==================================================="
130 print " feedback is not in state 'CurrentControl' "
131 print " OPERATOR: "
132 print " goto feedback console and check the state of "
133 print " feedback by typing [st] to find out what the"
134 print " current state means and maybe needs to be done"
135 print " this script will wait for state 'CurrentControl'"
136 print "==================================================="
137 feedback.wait(12)
138
139 bias_control.set_global_dac(1)
140
141 start = time()
142 while (bias_control.stn != 9):
143 time.sleep(0.1)
144 if time() > start + 10.:
145 print '==================================================='
146 print ' switching on bias not successfull'
147 print ' biasctrl is not in state "VoltageOn"'
148 print ''
149 print ' OPERATOR:'
150 print ' goto biasctrl console and check the state of'
151 print ' biasctrl by typing [st] to find out what the'
152 print ' current state means and maybe needs to be done'
153 print ''
154 print ' this script will wait for state "VoltageOn"'
155 print '==================================================='
156 bias_control.wait(9)
157
158 bias_control.wait(5)
159 bias_control.wait(9)
160
161 print "bias is on, and feedback-program is working, but we wait 45sec for the current readings..."
162 time.sleep(45)
163 print "...done"
164
165
166def StopTracking():
167""" should have the original behaviour, no new fancy features
168 stop drivectrl tracking the current source
169"""
170 drive_control.stop()
171 drive_control.wait(6) #Armed
172
173 print "Drive Armed"
174 print "Tracking Stopped"
175
176
177def SwitchOnBias():
178""" should have the original behaviour, no new fancy features
179 bring Feedback to state CurrentControIdle and switch on Bias
180"""
181 print ' switching on current controll feedback'
182 feedback.stop()
183 print ' ... starting current control feedback '
184 feedback.start_current_control(0.)
185 feedback.enable_output(1) # 1 means True here ... this needs improvement.
186
187 print ' ...waiting for FEEDBACK to be in state 9: CurrentCtrlIdle'
188 feedback.wait(9)
189 print '... feedback is running.'
190
191 print ' switching bias on by, setting DAC to 1 globally'
192 bias_control.set_global_dac(1)
193
194 print ' ...waiting for BIAS to be in state 9: VoltageOn'
195 bias_control.wait(9)
196 print ' ...1 DAC globally set'
197
198
199 print ' ...waiting for BIAS to be in state 5: Ramping'
200 bias_control.wait(5)
201 print ' ...ramping to nominal voltage'
202
203 print ' ...waiting for BIAS to be in state 9: VoltageOn'
204 bias_control.wait(9)
205 print ' ...bias on'
206
207 print ' waiting 45sec for the current control to stabilize...'
208 time.sleep(45.)
209 print ' ... done, bias on'
210
211
212 # the feedback should be in state 'CurrentCtrlIdle'(9) now since 30.05.12
213 # if feedback.stn != 9:
214 # print "feedback is in state:", feedback.sts , "(", feedback.stn, ")"
215 # print "but is should be in state CurrentCtrlIdle (9)"
216 # print "aborting"
217 # return
218
219
220
221def waitForTracking()
222""" Wait for drivectrl to reply that its tracking the given source
223"""
224
225 print "...waiting for DRIVE_CONTROL"
226 print " to be in state 7: Moving"
227 drive_control.wait(7)
228 print "...moving"
229
230 print "...waiting for DRIVE_CONTROL"
231 print " to be in state 8: Tracking"
232 drive_control.wait(8)
233 print "...tracking requested wobble position"
234
235 print "waiting 10 sec for drive to calm down"
236 print "and tracking beeing stable"
237 time.sleep(10)
238
239
240def TakeDataRun():
241""" Take a 5min Data Run
242"""
243 # check if all subsystems are in the correct state
244 IsReadyForDataTaking()
245
246 print ' taking Data:FullTriggerArea 5min Run ...'
247 mcp.start( 300, -1, 'data')
248
249 print '...waiting for FAD to be in state 8: Writing Data'
250 fad_control.wait(8) # Writing Data
251 print '...waiting for FAD to be in state 4: Connected'
252 fad_control.wait(4) # Connected
253 print '... done'
254
255def TakeExtLpRun():
256""" Take a external Lightpulser Run
257"""
258 # check if all subsystems are in the correct state
259 IsReadyForDataTaking()
260
261 print 'taking External Light Pulser with BIAS on 1000 ...'
262 mcp.start(-1, 1000, 'light-pulser-ext')
263
264 print '...waiting for FAD to be in state 8: Writing Data'
265 fad_control.wait(8) # Writing Data
266 print '...waiting for FAD to be in state 4: Connected'
267 fad_control.wait(4) # Connected
268 print '... done'
269
270def TakePedestalOnRun():
271""" Take a Pedestal 1000 run with Bias ON
272"""
273 # check if all subsystems are in the correct state
274 IsReadyForDataTaking()
275
276 print 'taking External Light Pulser with BIAS on 1000 ...'
277 mcp.start(-1, 1000, 'pedestal')
278
279 print '...waiting for FAD to be in state 8: Writing Data'
280 fad_control.wait(8) # Writing Data
281 print '...waiting for FAD to be in state 4: Connected'
282 fad_control.wait(4) # Connected
283 print '... done'
284
285
286def Take( time, num_events, runtype):
287""" more general version of e.g. TakePedestalOnRun
288 Note: One has to check, if Ready for *Take* by oneself
289"""
290 # check if all subsystems are in the correct state
291 #IsReadyForDataTaking()
292
293 print ' taking', runtype,'. ', num_events, 'events in', time, 'seconds'
294 mcp.start(time, num_events, runtype)
295
296 print '...waiting for FAD to be in state 8: Writing Data'
297 fad_control.wait(8) # Writing Data
298 print '...waiting for FAD to be in state 4: Connected'
299 fad_control.wait(4) # Connected
300 print '... done'
301
302
303def TakeData():
304""" taking a Data Set (1x Pedestal On, 1x LPext, 4x5min DataRun)
305"""
306 # take a Pedestal run
307 IsTracking()
308 TakePedestalOnRun()
309
310 # take a ExtLP run
311 IsTracking()
312 TakeExtLpRun()
313
314 #Data Taking with Full Trigger Area (4x5min)
315 for run in range(4):
316 print 'taking data run', run+1, 'out of 4'
317 IsTracking()
318 TakeDataRun()
319
320def TakeDrsCalibration():
321""" script for DRS-Calibration before Data taking
322"""
323 print 'script for DRS-Calibration before Data taking'
324 print 'starting up...'
325
326 feedback.enable_output(1)
327 # Making sure bias is off, before the DRS calibration starts
328 bias_control.set_zero_voltage()
329 print '...ramping Voltage down'
330 print ' ...waiting for BIAS to be in state 7: Voltage Off'
331 bias_control.wait(7) #VoltageOff
332 print '...BIAS voltage is switched off'
333
334 # starting the DRS calibration
335 fad_control.start_drs_calibration()
336
337 # taking first DRS:Pedestal with 1000 Events and ROI 1024
338 print 'taking DRS:Pedestal 1000 ...'
339 fad_control.wait(4) #Connected
340 Take(-1, 1000, 'drs-pedestal')
341
342 # taking DRS:Gain with 1000 Events and ROI 1024
343 print ' taking DRS:Gain 1000 ...'
344 fad_control.wait(4) #Connected
345 Take(-1, 1000, 'drs-gain')
346
347 # taking DRS:Pedestal 1000 Events and ROI 1024
348 print 'taking DRS:Pedestal 1000 ...'
349 fad_control.wait(4) #Connected
350 Take(-1, 1000, 'drs-pedestal')
351
352 print ' ... done'
353
354 # taking again a DRS:Pedestal with 1000 Events and ROI 1024 for a crosscheck of calculated calibrations constants
355 print ' taking crosscheck DRS:Pedestal 1000 ...'
356 fad_control.set_file_format(2)
357 fad_control.wait(4) #Connected
358 Take(-1, 1000, 'drs-pedestal')
359
360
361 # taking DRS:Time with 1000 Events and ROI 1024
362 print ' taking DRS:Time 1000 ...'
363 fad_control.wait(4) #Connected
364 Take(-1, 1000, 'drs-time')
365
366
367 # taking DRS:Time upshifted 1000 Events and ROI 1024
368 print 'taking DRS:Time upshifted 1000 ...'
369 fad_control.wait(4) #Connected
370 Take(-1, 1000, 'drs-time-upshifted')
371
372 # taking a Pedestal with 1000 Events and ROI 300 for secondary baseline...
373 print 'taking Pedestal 1000 for secondary baseline... with ROI=300'
374 fad_control.reset_secondary_drs_baseline()
375 fad_control.wait(4) #Connected
376 Take(-1, 1000, 'pedestal')
377
378 # taking crosscheck Pedestal 1000 Events and ROI 300
379 print ' taking crosscheck Pedestal 1000 ...with ROI=300'
380 fad_control.set_file_format(2)
381 fad_control.wait(4) #Connected
382 Take(-1, 1000, 'pedestal')
383
384 print '----------------------------------------------------'
385 print 'This is the end of the'
386 print 'DRS-Calibration before Data taking'
387 print '----------------------------------------------------'
388
389def DataTaking1():
390""" Script for taking data when you are tracking wobble position 1
391 take a DRS CaLibration and physics Data afterwards
392"""
393 # Move Telescope to Wobble Position 1
394 print '--------------------------------------'
395 print 'data taking for Wobble 1'
396 print 'starting up...'
397 print '--------------------------------------'
398 print 'OPERATOR:'
399 print 'make sure the telescope is tracking'
400 print 'wobble position 1 of the source'
401 print '--------------------------------------'
402
403 # Take a DRS-Calibration before beginning to take physics Data
404 TakeDrsCalibration()
405
406 # check feedback state before switching BIAS ON and ramping up to nominal Voltage
407 PrepareBiasForDataTaking()
408
409 # taking a Data Set (1x Pedestal 1000 Bias On, 1x LPext 1000, 4x5min DataRun)
410 TakeData()
411
412 print '--------------------------------------'
413 print 'data taking for Wobble 1 finished'
414 print '--------------------------------------'
415
416def DataTaking2():
417""" Script for taking data when you are tracking wobble position 2
418"""
419 # Move Telescope to Wobble Position 2
420 print '--------------------------------------'
421 print 'data taking for Wobble 2'
422 print 'starting up...'
423 print '--------------------------------------'
424 print '--------------------------------------'
425 print 'OPERATOR:'
426 print '+ make sure the telescope is tracking'
427 print ' wobble position 2 of the source'
428 print '+ Measure Sky Brightness'
429 print '--------------------------------------'
430
431
432 # taking a Data Set (1x Pedestal 1000 Bias On, 1x LPext 1000, 4x5min DataRun)
433 TakeData()
434
435 print '--------------------------------------'
436 print 'data taking for Wobble 2 finished'
437 print '--------------------------------------'
438
439def TakeCrab():
440""" Data taking and tracking script for Crab
441"""
442 print '======================================'
443 print 'Data taking and tracking script for'
444 print 'Crab'
445 print '======================================'
446 print 'starting up...'
447
448 # changing tracking to Crab Wobble 1
449 TrackCrabWobble1()
450
451 # Wait for drivectrl to reply that its tracking the given source
452 WaitForTracking()
453
454 DataTaking1()
455
456 # changing tracking to Crab Wobble 2
457 TrackCrabWobble2()
458
459 # Wait for drivectrl to reply that its tracking the given source
460 WaitForTracking()
461
462 # data taking to Crab Wobble 2
463 DataTaking2()
464
465 # Stop tracking
466 StopTracking()
467
468 print '======================================'
469 print 'Data taking and tracking script for'
470 print 'Crab FINISHED'
471 print '======================================'
472
473
474def TrackCrabWobble1():
475""" changing tracking to "Crab" Wobble 1
476"""
477 print 'moving telescope to wobble position 1'
478 print '...waiting for DRIVE_CONTROL'
479 print ' to be in state 6: Armed'
480
481 drive_control.wait(6) #Armed
482 print 'DRIVE: ARMED'
483 time.sleep(5.)
484
485 drive_control.track_source( 0.6, 50, 'Crab')
486 # we store this command in global vars, so it is increadibly easy, to
487 # do this call again, when needed
488 last_drive_method = drive_control.track_source
489 last_drive_kwargs = { 'wobble_offset' : 0.6,
490 'wobble_angle' : 50,
491 'source_name' : 'Crab' }
492 # so in case, this call needs to be repeated, just do
493 # last_drive_method(**last_drive_kwargs)
494
495 print '...sent tracking command for Crab Wobble 1'
496 print 'COMMAND: DRIVE_CONTROL/TRACK_SOURCE 0.6 50 Crab'
497
498def TrackCrabWobble2():
499""" changing tracking to "Crab" Wobble 2
500"""
501 print 'moving telescope to wobble position 2'
502 print '...waiting for DRIVE_CONTROL'
503 print ' to be in state 6: Armed'
504
505 drive_control.wait(6) #Armed
506 print 'DRIVE: ARMED'
507 time.sleep(5.)
508
509 # we store this command in global vars, so it is increadibly easy, to
510 # do this call again, when needed
511 last_drive_method = drive_control.track_source
512 last_drive_kwargs = { 'wobble_offset' : 0.6,
513 'wobble_angle' : -130,
514 'source_name' : 'Crab' }
515 # so in case, this call needs to be repeated, just do
516 last_drive_method(**last_drive_kwargs)
517
518 print '...sent tracking command for Crab Wobble 2'
519 print 'COMMAND: DRIVE_CONTROL/TRACK_SOURCE 0.6 -130 Crab'
520
521
522
523def FirstDrsCalib():
524""" performs the everything, which is done in the FirstDrsCalib Script as well .
525"""
526 # As a First step we want to calibrate the current, which are read from the bias crate,
527 # and not take a DRS calibration, as it is mentioned in the data taking page...
528 # so for this we should get the feedback and biasctrl programs into known states
529 # I think it is good to try a RECONNECT to the bias, and make sure the voltage is off
530 # Since we do not know, what the feedback program is doing at the moment, we should as well,
531 # tell it to keep its mouth shut ... just to be sure, we know whats going on
532 print "stopping feedback"
533 feedback.stop()
534
535 time.sleep(2)
536 # stopping should always be possible, and end in state 'Connected'(6)
537 print " ...waiting for FEEDBACK to be in state 6: Connected"
538 feedback.wait(6)
539 print "..done"
540
541 #BIAS_CONTROL/RECONNECT
542 # If we were disconnected, and this was the first try of the night, the bias_ctrl should
543 # be in state 'VoltageOff'(7) more or less immediately
544 #.s BIAS_CONTROL 3
545 #.s BIAS_CONTROL 7 5000
546 # if these assumptions are all wrong, then we might have been properly connected anyway,
547 # and just have to ramp down... lets do it, but wait forever, in case it does not work
548 print " switching off bias"
549 bias_control.set_zero_voltage()
550 time.sleep(2)
551 print " ...waiting for BIAS to be in state 7: VoltageOff"
552 bias_control.wait(7)
553 print " ...done"
554
555 # in case we reach this line, the voltages are all off, and the feedback does not do anything
556 # So lets do the current calibration, therefor we tell the bias crate to ramp up just 1 single DAC count(~22mV)
557 # the result of this action is, to get bias_ctrl into the state 'VoltageOn'(9), but since we only go one DAC count it shouldn't take long
558 print " setting bias globally to 1 DAC"
559 bias_control.set_global_dac(1)
560
561 time.sleep(2)
562 print " ...waiting for BIAS to be in state 9: VoltageOn"
563 bias_control.wait(9)
564 print " ...done"
565
566 # now we may tell the feedback program to calibrate the currents ...
567 # I do not understand, if I have to explicitely allow the feedback program to generate output,
568 # or if it just produces output...
569 # As far as I understand, the feedback output enable status is the same,
570 # as it was before I send the STOP command... so it is unknown at this point.
571 # and in addition enabling or disabling the output, when STOPed is not possible as far as I know...
572 # I try to enable it anyway.
573 print " enabling output for feedback"
574 feedback.enable_output(1)
575 time.sleep(2)
576 print " ...done"
577
578 print " calibrating bias crate current readings..."
579 feedback.calibrate_currents()
580 time.sleep(5)
581 # in order to find out when the calibration ends, we have to wait for the transistion from state
582 # 'Calibrating'(13) back to 'Connected'(6)
583 print " ...waiting for FEEDBACK to be in state 13: Calibrating"
584 feedback.wait(13)
585 print " ...waiting for FEEDBACK to be in state 6: Connected"
586 feedback.wait(6)
587
588 # Thomas Bretz told me, that the feedback, after this is step has disabled its output
589 # and is in the mode, we might call 'temperature control' even there is no temerature beeing controlled.
590 # I don't know where the voltage is ... in order to perform the calibration, the feedback had to
591 # ramp up to 2V below the operational voltage, i.e. about 1V below the breakdown voltage
592
593 # We want to take a DRS amplitude calibration so we have to ramp down the bias voltage.
594 # this 10sec wait is needed in order for the bias not to disconect all the time...
595 print " ... current calibration done"
596 time.sleep(10)
597
598 print " switching off bias"
599 bias_control.set_zero_voltage()
600 time.sleep(5)
601 print " ...waiting for BIAS to be in state 7: VoltageOff"
602 bias_control.wait(7)
603 print " ...done"
604
605 # So now we can take the 3 runs, which are called DRS amplitude calibration:
606 # A pedestal run with ROI=1024
607 # A gain calibration run with ROI=1024
608 # and a second pedestal run, with the same ROI as our next data will be, i.e. ROI=300 in this case
609 print "taking DRS:Pedestal 1000 ..."
610 print "==================================================="
611 print "OPERATOR: "
612 print "observe Events tab and make sure there are no patches "
613 print "with strange behaviour, which can be caused "
614 print "by DRS-CHIP Problems"
615 print "==================================================="
616
617 fad_control.start_drs_calibration()
618 mcp.start(-1, 1000, "drs-pedestal")
619
620 print "...waiting for FAD to be in state 8: Writing Data"
621 fad_control.wait(8)
622 print "...waiting for FAD to be in state 4: Connected"
623 fad_control.wait(4)
624 print "... done"
625
626 print "taking DRS:Gain 1000 ..."
627 mcp.start(-1, 1000, 'drs-gain')
628 print "...waiting for FAD to be in state 8: Writing Data"
629 fad_control.wait(8)
630 print "...waiting for FAD to be in state 4: Connected"
631 fad_control.wait(4)
632 print "... done"
633
634 print "taking Pedestal 1000 ..."
635 mcp.start( -1, 1000, 'pedestal')
636 print "...waiting for FAD to be in state 8: Writing Data"
637 fad_control.wait(8)
638 print "...waiting for FAD to be in state 4: Connected"
639 fad_control(4)
640 print "... done"
641
642 # okay this is the DRS calibration for the next few runs.
643 # we are now asked to take again a pedestal run, which can be used, to
644 # calculate the electronics noise for instance ... since the shutter is closed and the
645 # voltage is off .. there should not be alot of signal in it :-)
646 print "taking crosscheck Pedestal 1000 ..."
647 fad_control.set_file_format(2)
648
649 mcp.start(-1, 1000, 'pedestal')
650 print "...waiting for FAD to be in state 8: Writing Data"
651 fad_control.wait(8)
652 print "...waiting for FAD to be in state 4: Connected"
653 fad_control.wait(4)
654 print "... done"
655
656 # now we want to take a run, with dark counts events
657 # so we need to ramp up the voltage
658 # we want to use the 'current control' more so we give the commands for this...
659 print "switching on current controll feedback ..."
660 feedback.stop()
661 feedback.start_current_control(0.0)
662 feedback.enable_output(1)
663 # the feedback should be in state 'CurrentControl'(12) now
664 # the feedback should be in state 'CurrentCtrlIdle'(9) now since 30.05.12
665 print "...waiting for FEEDBACK to be in state 9: CurrentCtrlIdle"
666 feedback.wait(9)
667 print "... done"
668 print "switching on bias"
669 # now we give the feedback a hint, that it may ramp ...
670 bias_control.set_global_dac(1)
671 # after this command the bias_ctrl should be in state 'VoltageOn'(9) after a second or so
672 print "...waiting for BIAS to be in state 9: VoltageOn"
673 bias_control.wait(9)
674 print "...1 DAC globally set"
675 # then usually it takes some time until the feedback has enough information to really start controlling the voltage
676 # when the feedback actually kicks in, the bias is first in state 'Ramping'(5) for some seconds and finally in 'VoltageOn'(9)
677 # again
678 print "...waiting for BIAS to be in state 5: Ramping"
679 bias_control.wait(5)
680 print "...ramping to nominal voltage"
681 print "...waiting for BIAS to be in state 9: VoltageOn"
682 bias_control(9)
683 print "...bias on"
684 # here we should wait 45 sec in order for the current control to get enough current readings and temp readings to stabilize..
685 print "waiting 45sec for the current control to stabilize..."
686 time.sleep(45)
687 print "... done"
688
689 # so now we can take the dark count run ...
690 # this might be changed in the future ... either the number of events or the the ROI might be changed
691 # then the DRS calibration above, and the pedestal run in between have to be changed as well.
692 print "taking Pedestal with BIAS on 3000 ..."
693 mcp.start(-1, 3000, 'pedestal')
694 print "...waiting for FAD to be in state 8: Writing Data"
695 fad_control.wait(8)
696 print "...waiting for FAD to be in state 4: Connected"
697 fad_control.wait(4)
698 print "... done"
699
700 # at the end the bias voltage should be ramped down, since in a few seconds a shifter wit ha flashlight
701 # will come out to open the shutter...
702 print "switching OFF bias ..."
703 bias_control.set_zero_voltage()
704 print "...waiting for BIAS to be in state 7: VoltageOff"
705 bias_control.wait(7)
706 print "...done"
707 print "This is the end of First DRS Calibration"
708 print "----------------------------------------------------"
709 print ">"
710
711def Ratescan( ra=None, dec=None, sourcename=None):
712"""
713# call it by: .x ScriptsForDimCtrl/Ratescan.dim mode=<trackmode> ra=<Right ascension> dec=<Declination> source=<source_name>
714# mode=0: Manual tracking Mode: set tracking in drivectrl manually
715# mode=1: Coordinate Mode: scripts sends tracking command to drivectrl with the given RaDec coordinates
716# mode=2: source Mode: scripts sends tracking command to drivectrl with the given source_name
717
718"""
719 print '======================================'
720 print 'RATESCAN'
721 print '======================================'
722 print 'Preparing Drive'
723
724
725 if None == ra and None == dec and None == sourcename:
726 print 'Manual tracking Mode'
727 print '---------------------'
728 print 'OPERATOR'
729 print 'change tracking in drivectrl manually'
730 print 'script will wait for drive'
731 print 'to be in state tracking'
732 else if None != ra or None != dec:
733 try:
734 ra = float(ra)
735 dec = float(dec)
736 except TypeError:
737 raise
738
739 print '...stop tracking'
740 StopTracking()
741 print '...change tracking of telescope to:'
742 print '...Ra = ', ra
743 print '...Dec = ', dec
744 drive_control.track( ra, dec)
745 else if None != sourcename:
746 print '...stop tracking'
747 StopTracking()
748 print '...change tracking of telescope to:', sourcename
749 drive_control.track_source( 0, 0, sourcename)
750 else:
751 print 'type(ra)', type(ra), '\tra', ra
752 print 'type(dec)', type(dec), '\tdec', dec
753 print 'type(sourcename)', type(sourcename), '\tsourcename', sourcename
754 raise ValueError('RateScan does not know what to do with its parameters. Bug!')
755 return False
756
757 IsTracking()
758 IsReadyForDataTaking()
759
760 print 'Starting Ratescan'
761 print '...waiting for Ratescan'
762 print ' to be in state 4: Connected'
763
764
765 if not rate_scan.wait(4, timeout=5.): #Connected
766 # we went into timeout!
767 print 'Rate_Scan not in correct state'
768 print 'OPERATOR:'
769 print '+ check connection to ftm control'
770 print 'we went into to 5sec. timeout while waiting for RATE_SCAN to be in state Connected'
771 print 'aborting'
772 return False
773
774 rate_scan.start_threshold_scan( 50, 1000, -10)
775 if not rate_scan.wait( 6, timeout=10.): # Statename???
776 # we went into timeout
777 print 'ratescan not started'
778 print 'we went into 10sec. timeout while waiting for RATE_SCAN to start the Scan'
779 print 'aborting'
780 return False
781
782 print '...processing ratescan'
783 if not rate_scan.wait( 4, timeout=2700.): # Connected
784 # we went into timeout
785 print 'we went into 2700sec. timeout while waiting for RATE_SCAN to finish'
786 print 'aborting'
787 return False
788
789 print 'Ratescan finished successfully'
790 return True
791
792
793def ResetCrate( crate_num ):
794""" Reset Crate
795 crate_num = 0,1,2 or 3 the number of the crate to reset.
796 crate_num = 'all' is NOT YET SUPPORTED
797"""
798 c = int(crate_num)
799
800 print '======================================'
801 print 'Crate-Reset for crate ', c
802 print '======================================'
803
804 print '...resetting MCP'
805 mcp.reset()
806 time.sleep(5.)
807 print '...diconnecting FAD boards of crate ', c
808 FadDisconnectCrate( c )
809 time.sleep(2.)
810
811 print '...disconnecting All FTUs'
812 ftm_control.enable_ftu( -1, 0) # -1 for all, and 0 for False
813 time.sleep(2.)
814
815 print '...checking state of FTM_Control'
816 print '...waiting for state 3: Idle'
817 if not ftm_control.wait(3, 2.): # Idle
818 print '...stopping trigger'
819 ftm_control.stop_trigger()
820 ftm_control.wait(3) # wait for Idle endlessly
821
822 print '...resetting crate'
823 ftm_control.reset_crate( c )
824 time.sleep(2.)
825
826 print '...connecting All FTUs'
827 ftm_control.enable_ftu( -1, 1) # -1 for all, and 1 for yes, or True
828 time.sleep(4.)
829
830 print '...pinging FTUs'
831 ftm_control.ping()
832
833 print '...connecting FAD boards of crate', c
834 FadConnectCrate(C)
835 print '======================================'
836 print 'Crate-Reset for crate'c'finished'
837 print '======================================'
Note: See TracBrowser for help on using the repository browser.