-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_quadscan_methods.py
More file actions
71 lines (61 loc) · 2.16 KB
/
Copy pathpython_quadscan_methods.py
File metadata and controls
71 lines (61 loc) · 2.16 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
import datetime
import epics
import math
import time
import numpy as np
import pandas as pd
import subprocess
import sys
import os
# Methods
def abort_script(DISP=False, scanner='melba_020:scan'):
"""Script to close shutter or turn of laser an abort script"""
if not DISP:
try:
print("Closing shutter and setting dc off")
epics.caput('steam:laser_shutter:ls_set', 0)
epics.caput('steam:laser:dc_set', 0)
epics.caput(scanner + ':trig_input_FU00_set', 0)
except:
epics.caput('steam:laser:on_set', 0)
try:
if os.path.exists(outfile):
print("Deleting {}".format(outfile))
os.system("rm {}".format(outfile))
except:
pass
sys.exit()
def check_laser(pv_laser):
"""Safety function to check if laser power is too high while waiting"""
if pv_laser.get() >= 5e-6:
print("Laser power too high! Aborting!")
abort_script()
def fahre_zu(pos, pv_scan_stoppos, pv_scan_start, pv_scan_run_get):
"""Moves Scanner to position and handles waiting before stopping"""
print("Fahre Scanner zu Position {}".format(pos))
pv_scan_stoppos.put(pos)
pv_scan_start.put(0)
time.sleep(1.1)
while pv_scan_run_get.value != 0:
time.sleep(.5)
pv_scan_start.put(1)
def set_quadrupol(i_set, i_set_pv, i_get_pv, shot_mode=False, pv_laser=None):
"""Sets quadrupol to i_set and waits until i_get is updated accordingly"""
print("Quadrupol i_set: {:+05d}mA".format(int(i_set*1000)))
i_set_pv.put(i_set)
info = True
"""condition1 for i_set >= 0; condition2 for i_set < 0"""
interval = 0.075
time.sleep(3)
wait_start_time = time.time()
while (not (i_set*(1-interval) <= i_get_pv.get() <= i_set * (1 + interval) + 3e-3) and
not (i_set*(1-interval) >= i_get_pv.get() >= i_set * (1 + interval))):
if info:
print("Waiting for i_get to be updated...")
info = False
time.sleep(0.1)
if shot_mode: check_laser(pv_laser)
wait_stop_time = time.time()
if wait_stop_time - wait_start_time > 15:
break
return i_get_pv.get()