Commit 8674b781 authored by Simone Liuzzo's avatar Simone Liuzzo
Browse files

added subdirectory with functions for AC RM measurement (E.Plouviez)

parent d62df2f5
function [normI,phi,firstX,MresH,MresVH] = CalMresfdaH(n_and_dateX,Xamp)
%uses calculated sine and cosine instead of fda Cor96XZstuf signals with a shift by 22 samples for the Q Cor signal
% to get the Iand Q data
set_path
clockstart=clock
%load lastMresV
[Xsnif, Zsnif] =getFDAreaderXZ(n_and_dateX);
[XCor, ZCor] =getFDAreaderXZCor(n_and_dateX);
siz=size(Xsnif)
MresH=zeros(224,96);
MresV=zeros(224,96);
MresVH=zeros(224,96);
MresHI=zeros(224,96);
MresVI=zeros(224,96);
MresHQ=zeros(224,96);
MresVQ=zeros(224,96);
MresHVQ=zeros(224,96);
%[Cor96Xstuf,Cor96Zstuf ] = SortCorrXZstuf( XZCor );
for i=1:96
Cor96Xstuf(i,1:siz(2))=XCor(i,1:siz(2))-mean(XCor(i,:));
end
[ CXI,CXQ,firstX,lastX,lengthX] = Corfast_fda2(Cor96Xstuf,Xamp,Xamp/20);
%[ CZI,CZQ,firstZ,lastZ,lengthZ] = Corfast_fda2(Cor96Zstuf,Zamp,Zamp/20);
Xres=zeros(1,siz(2));
Zres=zeros(1,siz(2));
CX=zeros(1,siz(2));
CZ=zeros(1,siz(2));
for j=1:96
j
for k=1:224
Xres(1:siz(2))=Xsnif(k,1:siz(2));
Zres(1:siz(2))=Zsnif(k,1:siz(2));
CX(1:siz(2))=CXI(j,1:siz(2));
%CZ(1:siz(2))=CZI(j,1:siz(2));
C=CX/sum(abs(CX));
A=max(abs(CX));
MresHI(k,j)=MresH(k,j)+Xres*C'/A;
MresVI(k,j)=MresV(k,j)+Zres*C'/A;
[ CX] = CXQ(j,1:siz(2));
C=CX/sum(abs(CX));
A=max(abs(CX));
MresHQ(k,j)=MresH(k,j)+Xres*C'/A;
MresVQ(k,j)=MresV(k,j)+Zres*C'/A;
end
end
stdHI=std(MresHI);
stdHQ=std(MresHQ);
stdVI=std(MresVI);
stdVQ=std(MresVQ);
%calibration factor OK for.1A=32768
G=1e9*.2/pi*2*.5/32768;
normI=sqrt(stdHI.^2+stdHQ.^2)./stdHI;
normQ=sqrt(stdHI.^2+stdHQ.^2)./stdHQ;
phi=stdHQ./sqrt(stdHI.^2+stdHQ.^2);
for i=1:96
if phi(i)< .8
MresH(:,i)=MresHI(:,i)*normI(i)/G;
MresVH(:,i)=MresVI(:,i)*normI(i)/G;
else
MresH(:,i)=MresHQ(:,i)*normQ(i)/G;
MresVH(:,i)=MresVQ(:,i)*normQ(i)/G;
end
end
time=time_label;
file=['TimeLabelMresX',time];
DirLabel=pwd
cd ..
cd libera_data
cd TimeLabel
pwd
save(file,'n_and_dateX' , 'MresH','MresVH')
dir
cd (DirLabel)
clock-clockstart
\ No newline at end of file
function [normI,phi,firstZ,MresHV,MresV] = CalMresfdaV(n_and_dateZ,Zamp)
%uses calculated sine and cosine instead of fda Cor96XZstuf signals with a shift by 22 samples for the Q Cor signal
% to get the Iand Q data
set_path
clockstart=clock
%load lastMresV
set_path
[Xsnif, Zsnif] =getFDAreaderXZ(n_and_dateZ);
[XCor, ZCor] =getFDAreaderXZCor(n_and_dateZ);
siz=size(Xsnif)
MresH=zeros(224,96);
MresV=zeros(224,96);
MresHV=zeros(224,96);
MresHI=zeros(224,96);
MresVI=zeros(224,96);
MresHQ=zeros(224,96);
MresVQ=zeros(224,96);
MresHVQ=zeros(224,96);
%[Cor96Xstuf,Cor96Zstuf ] = SortCorrXZstuf( XZCor );
for i=1:96
%Cor96Xstuf(i,1:siz(2))=XCor(i,1:siz(2))-mean(XCor(i,:));
Cor96Zstuf(i,1:siz(2))=ZCor(i,1:siz(2))-mean(ZCor(i,:));
end
%[ CXI,CXQ,firstX,lastX,lengthX] = Corfast_fda2(Cor96Xstuf,Xamp,Xamp/20);
[ CZI,CZQ,firstZ,lastZ,lengthZ] = Corfast_fda2(Cor96Zstuf,Zamp,Zamp/10);
Xres=zeros(1,siz(2));
Zres=zeros(1,siz(2));
CX=zeros(1,siz(2));
CZ=zeros(1,siz(2));
for j=1:96
j
for k=1:224
Xres(1:siz(2))=Xsnif(k,1:siz(2));
Zres(1:siz(2))=Zsnif(k,1:siz(2));
%CX(1:siz(2))=CXI(j,1:siz(2));
CZ(1:siz(2))=CZI(j,1:siz(2));
C=CZ/sum(abs(CZ));
A=max(abs(CZ));
MresHI(k,j)=MresH(k,j)+Xres*C'/A;
MresVI(k,j)=MresV(k,j)+Zres*C'/A;
[ CZ ] = CZQ(j,1:siz(2));
C=CZ/sum(abs(CZ));
A=max(abs(CZ));
MresHQ(k,j)=MresH(k,j)+Xres*C'/A;
MresVQ(k,j)=MresV(k,j)+Zres*C'/A;
end
end
stdHI=std(MresHI);
stdHQ=std(MresHQ);
stdVI=std(MresVI);
stdVQ=std(MresVQ);
%calibration factor OK for.1A=32768
G=1e9*.2/pi*2*.5/32768;
normI=sqrt(stdVI.^2+stdVQ.^2)./stdVI;
normQ=sqrt(stdVI.^2+stdVQ.^2)./stdVQ;
phi=stdVQ./sqrt(stdVI.^2+stdVQ.^2);
for i=1:96
if phi(i)< .8
MresV(:,i)=MresVI(:,i)*normI(i)/G;
MresHV(:,i)=MresHI(:,i)*normI(i)/G;
else
MresV(:,i)=MresVQ(:,i)*normQ(i)/G;
MresHV(:,i)=MresHQ(:,i)*normQ(i)/G;
end
end
time=time_label;
file=['TimeLabelMresZ',time];
DirLabel=pwd
cd ..
cd libera_data
cd TimeLabel
pwd
save(file,'n_and_dateZ' , 'MresV','MresHV')
dir
cd (DirLabel)
clock-clockstart
\ No newline at end of file
function [n_and_dateX] =StartMresStimX(n,Xamp)
set_path
t1=clock
[IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= savePID
pause(.1)
setPID(0,0,0,0,0,0,0,0,2000,2000)
devaclock=dvopen ('tango:sr/d-mfdbk/aclock')
err=dvcmd(devaclock,'Stop')
devAutoCor=dvopen('tango:sr/svd-orbitcor/auto');
%err=dvcmd(devAutoCor,'Off')
devBilt=dvopen('tango:sr/bilt/all')
err=dvcmd(devBilt,'EnableAcCurrent')
devSwitchTrig=dvopen('tango:sr/d-fofbcorrection/switch_trig/Source')
err=dvcmd(devSwitchTrig,'DevWrite',1);
devInjPDamp=dvopen('tango:sr/septa-perturb-damping/ctrl')
DampState=dvcmd(devInjPDamp,'devSTATE')
err=dvcmd(devInjPDamp,'devOFF')
namefofbcorh=['tango:sr/d-fofbcorrection/globalX'];
namefofbcorv=['tango:sr/d-fofbcorrection/globalZ'];
devfofbcorh=dvopen(namefofbcorh)
devfofbcorv=dvopen(namefofbcorv)
% Xamp or Zamp: 32000=200mA, 1000 is OK for V, 8000 is OK for H
%buffer=zeros(8,7168);
Xamp;
%pause(5)
err=dvcmd(devfofbcorh,'ResetErrors')
pause(2)
for i=1:8
%StimTest2(Xamp,Zamp,2*i-1,64+1,i);
StimTest2(Xamp,0,2*i-1,57+i,i);
end
pause(.5)
err=dvcmd(devfofbcorh,'WritePIDCoeffsToFPGA');
err=dvcmd(devfofbcorv,'WritePIDCoeffsToFPGA');
pause(1)
t2=clock
pause(2)
err=dvcmd(devfofbcorh,'StartCorrection');
pause(1)
disp('Trig')
time=clock
n_and_date2 = [int2str(floor(time(3)/10)),int2str(mod(floor(time(3)),10)), '/', int2str(floor(time(2)/10)),int2str(mod(floor(time(2)),10)), '/', int2str(floor(time(1))),' ' , int2str(floor(time(4)/10)),int2str(mod(floor(time(4)),10)) ,':', int2str(floor(time(5)/10)),int2str(mod(floor(time(5)),10)) ,':',int2str(floor(time(6)/10)),int2str(mod(floor(time(6)),10)),'.',int2str(floor(time(6)*1000000)-1000000*floor(time(6)))];
n_and_dateX={int2str(n),n_and_date2}
err=dvcmd(devaclock,'ForcedOneShot')
clock
pause(1.5+n/10000);
err=dvcmd(devaclock,'Stop')
for j=1:8
StimTest2(0,0,2*j,64,j);
end
pause(1)
err=dvcmd(devfofbcorh,'ResetErrors')
pause(.1)
err=dvcmd(devSwitchTrig,'DevWrite',0);
pause(.1)
err=dvcmd(devInjPDamp,'devON')
[IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= restorePID4OP
devaclock=dvopen ('tango:sr/d-mfdbk/aclock')
err=dvcmd(devaclock,'Stop')
save lastMresH n_and_dateX Xamp
time=time_label;
file=['TimeLabelX',time];
DirLabel=pwd;
cd ..
cd libera_data
cd TimeLabel
pwd
save(file,'n_and_dateX' , 'Xamp')
dir
cd (DirLabel)
err=dvcmd(devfofbcorh,'StopCorrection');
\ No newline at end of file
function [n_and_dateZ] =StartMresStimZ(n,Zamp)
set_path
t1=clock
[IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= savePID
pause(.1)
setPID(0,0,0,0,0,0,0,0,2000,2000)
devaclock=dvopen ('tango:sr/d-mfdbk/aclock')
err=dvcmd(devaclock,'Stop')
devAutoCor=dvopen('tango:sr/svd-orbitcor/auto');
%err=dvcmd(devAutoCor,'Off')
devBilt=dvopen('tango:sr/bilt/all')
err=dvcmd(devBilt,'EnableAcCurrent')
devSwitchTrig=dvopen('tango:sr/d-fofbcorrection/switch_trig/Source')
err=dvcmd(devSwitchTrig,'DevWrite',1);
devInjPDamp=dvopen('tango:sr/septa-perturb-damping/ctrl')
DampState=dvcmd(devInjPDamp,'devSTATE')
err=dvcmd(devInjPDamp,'devOFF')
namefofbcorh=['tango:sr/d-fofbcorrection/globalX'];
namefofbcorv=['tango:sr/d-fofbcorrection/globalZ'];
devfofbcorh=dvopen(namefofbcorh)
devfofbcorv=dvopen(namefofbcorv)
% Xamp or Zamp: 32000=200mA, 1000 is OK for V, 8000 is OK for H
%buffer=zeros(8,7168);
Zamp;
%pause(5)
err=dvcmd(devfofbcorh,'ResetErrors')
pause(2)
for i=1:8
%StimTest2(Xamp,Zamp,2*i-1,64+1,i);
StimTest2(0,Zamp,2*i-1,57+i,i);
end
pause(.5)
err=dvcmd(devfofbcorh,'WritePIDCoeffsToFPGA');
err=dvcmd(devfofbcorv,'WritePIDCoeffsToFPGA');
pause(1)
t2=clock
pause(2)
err=dvcmd(devfofbcorh,'StartCorrection');
pause(1)
disp('Trig')
time=clock
n_and_date2 = [int2str(floor(time(3)/10)),int2str(mod(floor(time(3)),10)), '/', int2str(floor(time(2)/10)),int2str(mod(floor(time(2)),10)), '/', int2str(floor(time(1))),' ' , int2str(floor(time(4)/10)),int2str(mod(floor(time(4)),10)) ,':', int2str(floor(time(5)/10)),int2str(mod(floor(time(5)),10)) ,':',int2str(floor(time(6)/10)),int2str(mod(floor(time(6)),10)),'.',int2str(floor(time(6)*1000000)-1000000*floor(time(6)))];
n_and_dateZ={int2str(n),n_and_date2}
err=dvcmd(devaclock,'ForcedOneShot')
clock
pause(1.5+n/10000);
err=dvcmd(devaclock,'Stop')
for j=1:8
StimTest2(0,0,2*j,64,j);
end
pause(1)
err=dvcmd(devfofbcorh,'ResetErrors')
pause(.1)
err=dvcmd(devSwitchTrig,'DevWrite',0);
err=dvcmd(devInjPDamp,'devON')
pause(.1)
[IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= restorePID4OP
devaclock=dvopen ('tango:sr/d-mfdbk/aclock')
err=dvcmd(devaclock,'Stop')
save lastMresV n_and_dateZ Zamp
time=time_label;
file=['TimeLabelZ',time];
DirLabel=pwd
cd ..
cd libera_data
cd TimeLabel
pwd
save(file,'n_and_dateZ','Zamp')
dir
cd (DirLabel)
err=dvcmd(devfofbcorh,'StopCorrection');
\ No newline at end of file
function StimTest2(Xamp,Zamp,indf,np,n)
ns=floor((n+1)/2);
nb=mod(n+1,2)+1;
namedev=['tango:sr/d-FOFBCorrection/Station',num2str(ns),'Board',num2str(nb)];
dev=dvopen(namedev);
dvcmd(dev,'FPGAWrite',[143,indf]);
dvcmd(dev,'FPGAWrite',[200,np]);
dvcmd(dev,'FPGAWrite',[201,Xamp]);
dvcmd(dev,'FPGAWrite',[202,Zamp]);
ns
%SetTestSigAmp(Xamp,Zamp,n)
nb
devfofbcorv= open_fofbCor_allZ;
devfofbcorh= open_fofbCor_allX;
err=dvcmd(devfofbcorh,'WritePIDCoeffsToFPGA');
err=dvcmd(devfofbcorv,'WritePIDCoeffsToFPGA');
function [IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z,MaxX,MaxZ]= restorePID4OP
%load lastPIDset
load PIDset4OP
fofbcorh=dvopen('tango:sr/d-fofbcorrection/globalX');
fofbcorv=dvopen('tango:sr/d-fofbcorrection/globalZ');
devIX=dvopen('tango:sr/d-fofbcorrection/globalX/IntegralGain');
devPX=dvopen('tango:sr/d-fofbcorrection/globalX/ProportionalGain');
devN1X=dvopen('tango:sr/d-fofbcorrection/globalX/Notch1Gain');
devN2X=dvopen('tango:sr/d-fofbcorrection/globalX/Notch2Gain');
devMaxPosX=dvopen('tango:sr/d-fofbcorrection/globalX/PositionMaxDeviation');
devIZ=dvopen('tango:sr/d-fofbcorrection/globalZ/IntegralGain');
devPZ=dvopen('tango:sr/d-fofbcorrection/globalZ/ProportionalGain');
devN1Z=dvopen('tango:sr/d-fofbcorrection/globalZ/Notch1Gain');
devN2Z=dvopen('tango:sr/d-fofbcorrection/globalZ/Notch2Gain');
devMaxPosZ=dvopen('tango:sr/d-fofbcorrection/globalZ/PositionMaxDeviation');
IX=dvcmd(devIX,'DevWrite',double(IX));
PX=dvcmd(devPX,'DevWrite',double(PX));
N1X=dvcmd(devN1X,'DevWrite',double(N1X));
N2X=dvcmd(devN2X,'DevWrite',double(N2X));
IZ=dvcmd(devIZ,'DevWrite',double(IZ));
PZ=dvcmd(devPZ,'DevWrite',double(PZ));
N1Z=dvcmd(devN1Z,'DeVWrite',double(N1Z));
N2Z=dvcmd(devN2Z,'DevWrite',double(N2Z));
MaxX=dvcmd(devMaxPosX,'DevWrite',double(2000));
MaxZ=dvcmd(devMaxPosZ,'DevWrite',double(500));
pause(.5)
err=dvcmd(fofbcorh,'WritePIDCoeffsToFPGA');
err=dvcmd(fofbcorv,'WritePIDCoeffsToFPGA');
pause(.5)
\ No newline at end of file
function [IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= savePID
namefofbcorh=['tango:sr/d-fofbcorrection/globalX'];
namefofbcorv=['tango:sr/d-fofbcorrection/globalX'];
devIX=dvopen('tango:sr/d-fofbcorrection/globalX/IntegralGain');
devPX=dvopen('tango:sr/d-fofbcorrection/globalX/ProportionalGain');
devN1X=dvopen('tango:sr/d-fofbcorrection/globalX/Notch1Gain');
devN2X=dvopen('tango:sr/d-fofbcorrection/globalX/Notch2Gain');
devIZ=dvopen('tango:sr/d-fofbcorrection/globalZ/IntegralGain');
devPZ=dvopen('tango:sr/d-fofbcorrection/globalZ/ProportionalGain');
devN1Z=dvopen('tango:sr/d-fofbcorrection/globalZ/Notch1Gain');
devN2Z=dvopen('tango:sr/d-fofbcorrection/globalZ/Notch2Gain');
IX=dvcmd(devIX,'DevRead');
PX=dvcmd(devPX,'DevRead');
N1X=dvcmd(devN1X,'DevRead');
N2X=dvcmd(devN2X,'DevRead');
IZ=dvcmd(devIZ,'DevRead');
PZ=dvcmd(devPZ,'DevRead');
N1Z=dvcmd(devN1Z,'DevRead');
N2Z=dvcmd(devN2Z,'DevRead');
save lastPIDset IX IZ PX PZ N1X N1Z N2X N2Z
function setPID(IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z,MaxX,MaxZ)
fofbcorh=dvopen('tango:sr/d-fofbcorrection/globalX');
fofbcorv=dvopen('tango:sr/d-fofbcorrection/globalX');
devIX=dvopen('tango:sr/d-fofbcorrection/globalX/IntegralGain');
devPX=dvopen('tango:sr/d-fofbcorrection/globalX/ProportionalGain');
devN1X=dvopen('tango:sr/d-fofbcorrection/globalX/Notch1Gain');
devN2X=dvopen('tango:sr/d-fofbcorrection/globalX/Notch2Gain');
devMaxPosX=dvopen('tango:sr/d-fofbcorrection/globalX/PositionMaxDeviation');
devIZ=dvopen('tango:sr/d-fofbcorrection/globalZ/IntegralGain');
devPZ=dvopen('tango:sr/d-fofbcorrection/globalZ/ProportionalGain');
devN1Z=dvopen('tango:sr/d-fofbcorrection/globalZ/Notch1Gain');
devN2Z=dvopen('tango:sr/d-fofbcorrection/globalZ/Notch2Gain');
devMaxPosZ=dvopen('tango:sr/d-fofbcorrection/globalZ/PositionMaxDeviation');
err=dvcmd(devIX,'DevWrite',double(IX));
err=dvcmd(devPX,'DevWrite',double(PX));
err=dvcmd(devN1X,'DevWrite',double(N1X));
err=dvcmd(devN2X,'DevWrite',double(N2X));
err=dvcmd(devIZ,'DevWrite',double(IZ));
err=dvcmd(devPZ,'DevWrite',double(PZ));
err=dvcmd(devN1Z,'DeVWrite',double(N1Z));
err=dvcmd(devN2Z,'DevWrite',double(N2Z));
MaxX=dvcmd(devMaxPosX,'DevWrite',double(MaxX));
MaxZ=dvcmd(devMaxPosZ,'DevWrite',double(MaxZ));
pause(1)
err=dvcmd(fofbcorh,'WritePIDCoeffsToFPGA');
err=dvcmd(fofbcorv,'WritePIDCoeffsToFPGA');
pause(1)
function set_path
%addpath /users/diag/matlab/libera_data
addpath /mntdirect/_users/diag/matlab/FOC_op
addpath /mntdirect/_users/diag/matlab/libera_data
addpath /mntdirect/_users/diag/matlab/TMonLibera
addpath /users/diag/matlab/liberaFOC_test
addpath /segfs/tango/cppserver/machine/diagnostic/bpm/FastDataArchiver/fa-archiver/matlab
addpath /users/diag/matlab/FastMres
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment