Commit fbafc8eb authored by Simone Liuzzo's avatar Simone Liuzzo

initial qempanel commit

parent 7374d90a
function [normI,phi,firstX,MresH,MresVH] = CalMresfdaH(n_and_dateX,Xamp,qemres)
%uses calculated sine and cosine instead of fda CorNSTEXZstuf signals with a shift by 22 samples for the Q Cor signal
% to get the Iand Q data
% set_path % TO BE COMMENTED OUT WHEN MERGING WITH QEMPANEL
tic
%load lastMresV
[Xsnif, Zsnif] =getFDAreaderXZ(n_and_dateX);
[XCor, ZCor] =getFDAreaderXZCor(n_and_dateX);
siz=size(Xsnif);
NBPM=siz(1); NSTE=size(XCor,1);
MresH=zeros(NBPM,NSTE);
% MresV=zeros(NBPM,NSTE);
MresVH=zeros(NBPM,NSTE);
% MresHI=zeros(NBPM,NSTE);
% MresVI=zeros(NBPM,NSTE);
% MresHQ=zeros(NBPM,NSTE);
% MresVQ=zeros(NBPM,NSTE);
% MresHVQ=zeros(NBPM,NSTE);
%for i=1:NSTE
% CorNSTEXstuf(i,1:siz(2))=XCor(i,1:siz(2))-mean(XCor(i,:));
%end
CorNSTEXstuf=XCor-repmat(mean(XCor,2)',siz(2),1)';
disp(['Xamp=' num2str(Xamp) ...
' # steerers=', num2str(size(CorNSTEXstuf,1)) ...
' buffer size=',num2str(size(CorNSTEXstuf,2)) ])
[ CXI,CXQ,firstX,lastX,lengthX] = Corfast_fda2(CorNSTEXstuf,Xamp,Xamp/20);
% Xres=zeros(1,siz(2));
% Zres=zeros(1,siz(2));
% CX=zeros(1,siz(2));
% CZ=zeros(1,siz(2));
C=CXI./repmat(sum(abs(CXI),2),1,siz(2));
A=max(abs(CXI),[],2);
MresHI=Xsnif*C'./repmat(A',NBPM,1);
MresVI=Zsnif*C'./repmat(A',NBPM,1);
CQ=CXQ./repmat(sum(abs(CXQ),2),1,siz(2));
AQ=max(abs(CXQ),[],2);
MresHQ=Xsnif*CQ'./repmat(AQ',NBPM,1);
MresVQ=Zsnif*CQ'./repmat(AQ',NBPM,1);
% for j=1:NSTE
% j
%
% CX(1:siz(2))=CXI(j,1:siz(2));
% C=CX/sum(abs(CX))/max(abs(CX));
%
% [ DX] = CXQ(j,1:siz(2));
% D=DX/sum(abs(DX))/max(abs(DX));
%
% for k=1:NBPM
%
% Xres(1:siz(2))=Xsnif(k,1:siz(2));
% Zres(1:siz(2))=Zsnif(k,1:siz(2));
%
%
% MresHI(k,j)=MresH(k,j)+Xres*C';
% MresVI(k,j)=MresV(k,j)+Zres*C';
%
% MresHQ(k,j)=MresH(k,j)+Xres*D';
% MresVQ(k,j)=MresV(k,j)+Zres*D';
%
% 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:NSTE
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];
save(fullfile(qemres.datadir,file),'n_and_dateX' , 'MresH','MresVH');
toc
\ No newline at end of file
function [normI,phi,firstZ,MresHV,MresV] = CalMresfdaV(n_and_dateZ,Zamp,qemres)
%uses calculated sine and cosine instead of fda CorNSTEXZstuf signals with a shift by 22 samples for the Q Cor signal
% to get the Iand Q data
% set_path % TO BE COMMENTED OUT WHEN MERGING WITH QEMPANEL
tic
%load lastMresV
[Xsnif, Zsnif] =getFDAreaderXZ(n_and_dateZ);
[XCor, ZCor] =getFDAreaderXZCor(n_and_dateZ);
siz=size(Xsnif);
NBPM=siz(1); NSTE=size(XCor,1);
% MresH=zeros(NBPM,NSTE);
MresV=zeros(NBPM,NSTE);
MresHV=zeros(NBPM,NSTE);
% MresHI=zeros(NBPM,NSTE);
% MresVI=zeros(NBPM,NSTE);
% MresHQ=zeros(NBPM,NSTE);
% MresVQ=zeros(NBPM,NSTE);
% MresHVQ=zeros(NBPM,NSTE);
% for i=1:NSTE
% CorNSTEZstuf(i,1:siz(2))=ZCor(i,1:siz(2))-mean(ZCor(i,:));
% end
CorNSTEZstuf=ZCor-repmat(mean(ZCor,2)',siz(2),1)';
disp(['Zamp=' num2str(Zamp) ...
' # steerers=', num2str(size(CorNSTEZstuf,1)) ...
' buffer size=',num2str(size(CorNSTEZstuf,2)) ])
[ CZI,CZQ,firstZ,lastZ,lengthZ] = Corfast_fda2(CorNSTEZstuf,Zamp,Zamp/10);
% Xres=zeros(1,siz(2));
% Zres=zeros(1,siz(2));
% CX=zeros(1,siz(2));
% CZ=zeros(1,siz(2));
C=CZI./repmat(sum(abs(CZI),2),1,siz(2));
A=max(abs(CZI),[],2);
MresHI=Xsnif*C'./repmat(A',NBPM,1);
MresVI=Zsnif*C'./repmat(A',NBPM,1);
CQ=CZQ./repmat(sum(abs(CZQ),2),1,siz(2));
AQ=max(abs(CZQ),[],2);
MresHQ=Xsnif*CQ'./repmat(AQ',NBPM,1);
MresVQ=Zsnif*CQ'./repmat(AQ',NBPM,1);
% for j=1:NSTE
% j
%
% for k=1:NBPM
%
% 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:NSTE
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];
save(fullfile(qemres.datadir,file),'n_and_dateZ' , 'MresV','MresHV');
toc
\ No newline at end of file
function[ CorI,CorQ,first,last,length] = Corfast_fda2( Cor,CorAmp ,mx)
%generate a signal CorQ pi/2 shifted in phase with respect to the sine signal Cor; CorI and corQ are true sine and cosine signals
%at the frequencies used for each corrector by the script getAllSnifferXZandCorTestSigNew2.
%ftab=[1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,1,1,1,1,1,1,1,1,1];
sizeCor=size(Cor);
NSTE=sizeCor(1);
if NSTE ~= 96
error('in Corfast_fda2 # of steerers must be 96, because of reordering from cell 1 to cell 4 at the end of the script');
end
n=sizeCor(2);
amp=4*CorAmp;
CorQ=zeros(NSTE,n);
CorI=zeros(NSTE,n);
first=20*ones(1,NSTE);
last=zeros(1,NSTE);
length=zeros(1,NSTE);
for i=1:NSTE
m=0;
for j=5:n
if (abs(Cor(i,j)<mx && m==0 ))||((abs(Cor(i,j))>=mx && abs(Cor(i,j+25))<CorAmp*2 && m==0))
first(i)=j+1;
else
first(i);
length(i)=5071;
m=1;
end
end
%First=first(i)
end
%for i=1:48
%for j=1:2
%if first(2*(i-1)+j)<74932
%fir=first(2*(i-1)+j);
%ps=round(length(i)/256);
%CorI(2*(i-1)+j,fir:fir+5066+j)=Cor(2*(i-1)+j,fir:fir+5066+j);
%CorQ(2*(i-1)+j,fir+ps:fir+5066+j)=CorI(2*(i-1)+j,fir:fir+5066+j-ps);
%CorQ(2*(i-1)+j,fir:fir+ps-1)=-CorI(2*(i-1)+j,fir+5066+j-ps+1:fir+5066+j);
%else
%CorI(2*(i-1)+j,:)=Cor(2*(i-1)+j,:);
% end
%end
%end
for i=1:NSTE
if first(i)<n-5072
sp=abs(fft(Cor(i,first(i):first(i)+5071)));
[mf,k]=max(sp(1:5071));
f=((k-1)*2);
for j=1:5072
%CorI(i,first(i)+j-1)=amp*sin(2*pi*j*(114+2*ftab(i))/10135) ;
%CorQ(i,first(i)+j-1)=amp*cos(2*pi*j*(114+2*ftab(i))/10135) ;
CorI(i,first(i)+j-1)=amp*sin(2*pi*j*(f)/10144) ;
CorQ(i,first(i)+j-1)=amp*cos(2*pi*j*(f)/10144) ;
end
else
CorI(i,:)=Cor(i,:);
end
end
sizeCor=size(CorI);
Cor=zeros(NSTE,sizeCor(2));
Cor(1:87,:)=CorI(10:NSTE,:);
Cor(88:NSTE,:)=CorI(1:9,:);
CorI=Cor;
Cor=zeros(NSTE,sizeCor(2));
Cor(1:87,:)=CorQ(10:NSTE,:);
Cor(88:NSTE,:)=CorQ(1:9,:);
CorQ=Cor;
function ReadFullRespMatData(dirrmdata, fileRMACraw, fileMeasuredGain)
% converts AC RM data from data archiver to qempanel usable format
%
% INPUT:
% fileRMACraw : name of AC RM file containing variables MresH MresV MresVH
% MresHV
%
%
%see also:
if nargin<3
fileMeasuredGain = 'Gain_new_180604.mat';
end
%======== AC ORM
load(fileRMACraw,'MresH','MresV','MresVH','MresHV') % load file with measured AC RM raw
ACresph=MresH; ACrespv=MresV; ACresphv=MresVH; ACrespvh=MresHV;
% calibration coefficents (empirically found during MDT)
ACresph_norm=-ACresph/2.8; ACrespvh_norm=-ACrespvh/3.8;
ACrespv_norm=-ACrespv/3.8; ACresphv_norm=-ACresphv/2.8;
% apply measured Gain (fine adjustment, cable lengths)
load(fileMeasuredGain,'GainX','GainZ');
% apply new calibration factors
ACresph_norm = bsxfun(@rdivide, ACresph_norm, GainX);
ACrespv_norm = bsxfun(@rdivide, ACrespv_norm, GainZ);
%%======== save for qempanel
fileformat=['%.4f\t%s,%d' repmat('\t%.5f',1,224)];
deltaH=0.08; % from respmat.py
deltaV=0.10; % from respmat.py
for ist=1:96
f=fopen([dirrmdata '/steerH' num2str(ist,'%.2d')],'w');
fprintf(f,fileformat,deltaH,sr.steername(ist,'SR/ST-H%i/C%i/CURRENT'),0,ACresph_norm(:,ist)*1e3);
fclose(f);
f=fopen([dirrmdata '/steerV' num2str(ist,'%.2d')],'w');
fprintf(f,fileformat,deltaV,sr.steername(ist,'SR/ST-V%i/C%i/CURRENT'),0,ACrespv_norm(:,ist)*1e3);
fclose(f);
% off diagonal
f=fopen([dirrmdata '/steerH2V' num2str(ist,'%.2d')],'w');
fprintf(f,fileformat,deltaH,sr.steername(ist,'SR/ST-H%i/C%i/CURRENT'),0,ACresphv_norm(:,ist)*1e3);
fclose(f);
f=fopen([dirrmdata '/steerV2H' num2str(ist,'%.2d')],'w');
fprintf(f,fileformat,deltaV,sr.steername(ist,'SR/ST-V%i/C%i/CURRENT'),0,ACrespvh_norm(:,ist)*1e3);
fclose(f);
end
end
function [n_and_dateX] =StartMresStimX(n,Xamp,qemres)
% set_path
t1=clock
[IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= savePID(qemres)
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(fullfile(qemres.datadir,'lastMresH'),'n_and_dateX','Xamp');
time=time_label;
file=['TimeLabelX',time];
save(fullfile(qemres.datadir,file),'n_and_dateX' , 'Xamp')
err=dvcmd(devfofbcorh,'StopCorrection');
\ No newline at end of file
function [n_and_dateZ] =StartMresStimZ(n,Zamp,qemres)
%set_path
t1=clock
[IX, IZ, PX, PZ, N1X, N1Z ,N2X, N2Z]= savePID(qemres)
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(fullfile(qemres.datadir,'lastMresV'),'n_and_dateZ','Zamp');
time=time_label;
file=['TimeLabelZ',time];
save(fullfile(qemres.datadir,file),'n_and_dateZ','Zamp')
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 [Xsnif, Zsnif] =getFDAreaderXZ(n_and_date)
%uses the fda data extractor to get Intensity n data recorded at the date
%"date"
%Extractor argin description: (DevVarStringArray)
%[0] Number of samples to read
%[1] Start date (ex: 22/06/2015 16:15:00[.103647], les us sont optionnelles)
%for instance: n_and_date = {'100','28/09/2015 08:00:00'} or {'100','28/09/2015 08:00:00.178546'}
n=str2double(n_and_date(1));
fda='tango:sr/d-bpmlibera/fda_reader';
devfda=dvopen(fda);
dvtimeout(devfda,50);
pause(10); % some times 5s are not enough
XZ=dvcmd(devfda,'ReadXZPositions',n_and_date);
size(XZ);
X=XZ(1:224*n);
Z=XZ(1+(224*n):448*n);
Xsnif=reshape(X,224,n);
Zsnif=reshape(Z,224,n);
function [XCor, ZCor] =getFDAreaderXZCor(n_and_date)
%uses the fda data extractor to get Intensity n data recorded at the date
%"date"
%Extractor argin description: (DevVarStringArray)
%[0] Number of samples to read
%[1] Start date (ex: 22/06/2015 16:15:00[.103647], les us sont optionnelles)
%for instance: n_and_date = {'100','28/09/2015 08:00:00'} or {'100','28/09/2015 08:00:00.178546'}
n=str2double(n_and_date(1));
fda='tango:sr/d-bpmlibera/fda_reader';
devfda=dvopen(fda);
dvtimeout(devfda,50);
XZcor=dvcmd(devfda,'ReadXZCorrectionsSorted',n_and_date);
pause(5);
siz2=size(XZcor);
siz=siz2(2);
Xcor=XZcor(1:siz/2);
Zcor=XZcor(1+siz/2:siz);
XCor=reshape(Xcor,96,siz/2/96);
ZCor=reshape(Zcor,96,siz/2/96);
function devfofbcor= open_fofbCor_allX
namefofbcor=['tango:sr/d-fofbcorrection/globalX'];
devfofbcor=dvopen(namefofbcor);
function devfofbcor= open_fofbCor_allZ
namefofbcor=['tango:sr/d-fofbcorrection/globalZ'];
devfofbcor=dvopen(namefofbcor);
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(qemres)
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(fullfile(qemres.datadir,'lastPIDset'),'IX',...
'IZ', 'PX', 'PZ', 'N1X', 'N1Z', 'N2X', 'N2Z');