Files
PBSwissMX/python/5camMeas.py

87 lines
3.8 KiB
Python
Executable File

#!/usr/bin/env python
# *-----------------------------------------------------------------------*
# | |
# | Copyright (c) 2017 by Paul Scherrer Institute (http://www.psi.ch) |
# | |
# | Author Thierry Zamofing (thierry.zamofing@psi.ch) |
# *-----------------------------------------------------------------------*
'''
generate code to find HomeOffset for the 5cam systems
the results are:
amplitude: 5mm
#1: homeoffset: -20907.5928142
#2: homeoffset: 102320.329068
#3: homeoffset: 168946.772022
#4: homeoffset: -87830.7554146
#5: homeoffset: -47956.2759182
'''
import numpy as np
import matplotlib.pyplot as plt
def meas_rot_ctr(y,per=1):
# find the amplitude bias and phase of an equidistant sampled sinus
# it needs at least 3 measurements e.g. at 0,120 240 deg or 0 90 180 270 deg
# per is the number of persiods, default is 1 period =360 deg
n=len(y)
f = np.fft.fft(y)
idx=int(per)
bias=np.absolute(f[0]/n)
phase=np.angle(f[idx])
ampl=np.absolute(f[idx])*2/n
print('len: '+str(n))
print('bias: '+str(bias))
print('amplitude: '+str(ampl))
print('phase: '+str(phase*360./2/np.pi))
print('homeoffset: '+str(-phase*360./2/np.pi*1000))
def gen_code():
pos=np.arange(0,360000,12000)
mot=range(1,6)
#mot=range(1,2)
for m in mot:
print('''open prog %i
call15
abslinear
'''%(10+m))
for p in pos:
print(""" jog%i=%i
dwell 5000"""%(m,p))
print(""" jog%i=0
call16
close
"""%(m,))
for m in mot:
print("&1;b%ir"%(10+m))
def plot():
'''
&1;b11r
&1;b12r
&1;b13r
&1;b14r
&1;b15r
'''
#data1=[0,-.475,-1.123,-1.916,-2.819,-3.797,-4.799,-5.786,-6.708,-7.531,-8.219,-8.746,-9.085,-9.229,-9.176,-8.929,-8.499,-7.895,-7.142,-6.271,-5.320,-4.325,-3.329,-2.377,-1.513,-.780,-.216,.151,.305,.241]
#data2=[0,1.04,2.092,3.108,4.041,4.847,5.496,5.946,6.184,6.196,5.976,5.540,4.907,4.110,3.181,2.162,1.103,0.051,-.953,-1.859,-2.639,-3.252,-3.677,-3.892,-3.893,-3.677,-3.256,-2.648,-1.878,-.980]
#data3=[0,.296,0.785,1.445,2.248,3.160,4.146,5.165,6.170,7.120,7.968,8.676,9.210,9.541,9.660,9.564,9.274,8.807,8.154,7.340,6.398,5.378,4.318,3.271,2.310,1.485,.790,.282,-.028,-.130,]
#data4=[0,-1.035,-2.021,-2.930,-3.713,-4.333,-4.777,-5.018,-5.057,-4.888,-4.522,-3.967,-3.249,-2.393,-1.430,-0.402,.650,1.678,2.633,3.470,4.146,4.626,4.887,4.916,4.711,4.297,3.69,2.917,2.010,1.021]
#data5=[0,-.847,-1.786,-2.794,-3.815,-4.808,-5.727,-6.537,-7.194,-7.681,-7.987,-8.089,-7.990,-7.688,-7.204,-6.547,-5.745,-4.831,-3.840,-2.814,-1.799,-.844,0.015,.726,1.257,1.58,1.683,1.562,1.223,.685]
#measurement ID-Lab
data1=[2.044,2.950,3.724,4.333,4.748,4.955,4.960,4.739,4.303,3.674,2.881,1.967,0.963,-.082,-1.126,-2.119,-3.020,-3.794,-4.398,-4.814,-5.022,-5.018,-4.795,-4.362,-3.734,-2.947,-2.029,-1.025,0.022,1.067,]
data2=[-4.713,-5.064,-5.203,-5.133,-4.844,-4.343,-3.665,-2.831,-1.885,-0.861,.190,1.222,2.197,3.064,3.789,4.336,4.693,4.827,4.758,4.461,3.957,3.273,2.438,1.491,.468,-.582,-1.614,-2.581,-3.447,-4.169,]
data3=[0,-.213,-.669,-1.356,-2.231,-3.263,-4.403,-5.597,-6.790,-7.932,-8.970,-9.856,-10.556,-11.035,-11.280,-11.278,-11.034,-10.558,-9.872,-9.010,-8.005,-6.900,-5.743,-4.581,-3.462,-2.433,-1.540,-0.817,-0.310,-0.033]
data4=[2.547,1.665,0.669,-.4,-1.496,-2.573,-3.586,-4.491,-5.249,-5.821,-6.202,-6.353,-6.276,-5.970,-5.450,-4.734,-3.852,-2.847,-1.762,-0.645,0.457,1.490,2.409,3.172,3.746,4.104,4.236,4.132,3.803,3.263,]
data5=[-1.412,-.328,.728,1.706,2.556,3.244,3.739,4.014,4.064,3.890,3.490,2.896,2.126,1.216,.212,-.849,-1.915,-2.949,-3.901,-4.731,-5.408,-5.902,-6.189,-6.257,-6.105,-5.888,-5.149,-4.389,-3.483,-2.466,]
data=[data1,data2,data3,data4,data5]
for d in data:
meas_rot_ctr(d,1)
plt.plot(d)
plt.show()
#gen_code()
plot()