forked from slaclab/exp-timing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FS11_pcav2las_alpha.py
76 lines (69 loc) · 3.05 KB
/
FS11_pcav2las_alpha.py
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
# pcav2las_alpha.py
# script looks at the FEH CAST phase shifter value
# and apply the mirror value to the FS11 drift correction PV
import epics as epics
import numpy as np
import time as time
import datetime
# source /reg/g/pcds/engineering_tools/xpp/scripts/pcds_conda
FS11_DC_sw_PV = 'LAS:FS11:VIT:TT_DRIFT_ENABLE ' # Put 0 for disable, put 1 for enable
FS11_DC_val_PV ='LAS:FS11:VIT:matlab:04' # Drift correct value in ns
HXR_PCAV_PV0 = 'SIOC:UNDH:PT01:0:TIME0' # EGU in ps
HXR_PCAV_PV1 = 'SIOC:UNDH:PT01:0:TIME1'
HXR_CAST_PS_PV_W = 'LAS:UND:MMS:02' # EGU in ps
HXR_CAST_PS_PV_R = 'LAS:UND:MMS:02.RBV'
SXR_PCAV_PV0 = 'SIOC:UNDS:PT01:0:TIME0'
SXR_PCAV_PV1 = 'SIOC:UNDS:PT01:0:TIME1'
XPP_LAS_TT_PV = 'LAS:FS11:VIT:FS_TGT_TIME' # EGU in ns
cast_avg_n = 20 # n sample moving average
time_err_th = 20 # pcav err threshold in fs
time_err_ary = np.zeros((cast_avg_n))
time_err_prev = 0
motr_step_cntr = 0 # counter for how many time the phase "motor" has moved in unit of time_err_th
motr_step_diff_mag = 0
motr_step_diff_dir = 0
cntr = 0
# PCAV0_setpoint = epics.caget(HXR_PCAV_PV0)
# PCAV1_setpoint = epics.caget(HXR_PCAV_PV1)
HXR_cast_iqs_sp = epics.caget(HXR_CAST_PS_PV_R)
print('Controller running')
while True:
print('//////////////////////////////////////////////////////////////////')
print('Counter val: ' + str(cntr))
# PCAV0_Val_tmp = epics.caget(HXR_PCAV_PV0)
cast_val_tmp = epics.caget(HXR_CAST_PS_PV_R)
time_err = np.around((cast_val_tmp - HXR_cast_iqs_sp), decimals=6)
time_err_delta = time_err - time_err_prev
if cntr == 0:
time_err_ary = np.array(time_err)
elif (cntr >= cast_avg_n):
if np.abs(time_err_delta) < (0.100):
time_err_ary = np.delete(time_err_ary, 0)
time_err_ary = np.append(time_err_ary, time_err)
else:
time_err_ary = np.append(time_err_ary, time_err)
time_err_mean = np.mean(time_err_ary)
time_err_mean_fs = np.around(np.multiply(time_err_mean, 1000), 3)
pm_step = np.trunc(np.true_divide(time_err_mean_fs, time_err_th))
if pm_step != motr_step_cntr:
print('moving drift compensation')
motr_step_diff = pm_step - motr_step_cntr
motr_step_diff_mag = np.abs(motr_step_diff)
motr_step_diff_dir = np.sign(motr_step_diff)
current_DC_val = epics.caget(FS11_DC_val_PV)
print('current drift comp val = ' + str(current_DC_val) + '\n')
pm_val = np.multiply(pm_step, time_err_th)
new_DC_val = current_DC_val + np.true_divide(pm_val, 1e6)
print('epics.caput(FS11_DC_val_PV, new_DC_val)')
motr_step_cntr = pm_step
print('move time by: ' + str(pm_val))
print('pm delta: ' + str(motr_step_diff))
print('Time err delta: ' + str(np.around(time_err_delta, 3)) + 'ps')
print('motor steps: ' + str(pm_step))
print('current pm cntr: ' + str(motr_step_cntr))
print(str(cast_avg_n) + ' sample moving average error: ' + str(time_err_mean_fs) + 'fs')
print('Time err array: ')
print(time_err_ary)
time_err_prev = time_err
cntr = cntr + 1
time.sleep(1)