Commit 9a0c78f4 authored by beamdyn's avatar beamdyn

changes of MDT of 7 july 2020

parent bc6672e9
......@@ -3,9 +3,17 @@ function run_by_hand_singlemagnets(MagType,Range,varargin)
%
% MagType can be OCT, SEXT, SF, SD
%
% if Range is a single value then the range is from K0-range to K0+range
% if Range is an arrray of 2 elements:
% if MagType is SEXT then Range(1) is for SF, Range(2) is for SD
% if MagType is OCT then the range is from Range(1) to Range(2)
%
%
[automatic,~]=getflag(varargin,'Automatic');
rips = tango.Device('sy/ps-rips/manager');
rips=tango.Device('sy/ps-rips/manager');
npointscan = 7;
nacq=2;
......@@ -13,7 +21,6 @@ switch MagType
case 'OCT'
mags = tango.Attribute('srmag/m-o/all/Strengths');
all_mags = [1:64];
case 'SF'
mags = tango.Attribute('srmag/m-o/all/Strengths');
all_mags = sort([2:6:192 5:6:192]);
......@@ -26,7 +33,8 @@ switch MagType
end
names = mags.device.MagnetNames.read;
figure;
f=figure;
f.Position=[93 937 560 420];
plot(0,0);
xlabel(MagType);
ylabel('total losses');
......@@ -40,26 +48,33 @@ mkdir(dirname);
for is = 1:length(indmags)
sel = indmags(is);
name = names(sel);
name = names{sel};
disp(['Magnet ' num2str(is) '/' num2str(length(indmags(is)))]);
disp(['Magnet ' name ': ' num2str(is) '/' num2str(length(indmags))]);
pause(1);
K0 = tango.Attribute([name '/Strength']).set;
if length(Range)==2
range=Range;
if strcmp(MagType,'SEXT')
if name(10)=='f'
range=[K0-abs(Range(1)) K0+abs(Range(1))];
else
range=[K0-abs(Range(2)) K0+abs(Range(2))];
end
else
range=Range;
end
else
range=[K0-abs(Range) K0+abs(Range)];
end
K_mid = mean(range);%-175;
K_delta = abs(diff(range));
K_delta = abs(diff(range))/2;
% define variation steps
mag_values=[linspace(K_mid,range(1),ceil(npointscan/2)),...
linspace(range(1),range(2),npointscan),...
linspace(range(2),0,ceil(npointscan/2))];
linspace(range(2),K_mid,ceil(npointscan/2))];
% % sort to start at closest to present setpoint
[~,imin]=min((abs(mag_values-K0)));
......@@ -73,19 +88,33 @@ for is = 1:length(indmags)
ii=0;
jj=0;
while ii < length(mag_values)+1
while ii < length(mag_values)
% check rips running. if running. reset scan to start from zero
% again
magStrAttr=tango.Attribute([name '/Strength']);
if rips.State==10
disp('RIPS running set to initial values');
tango.Attribute([name '/Strength']).set=K0;
magStrAttr.set=K0;
pause(10);
ii=0;
jj=0;
if ~magsaved
globalfilename=['Settings' datestr(now,'yyyymmmdd_HHMMSS') ];
famsave=tango.Device('sys/settings/m-strengths');famsave.Timeout=10000;
famsave.GenerateSettingsFile({['FILE:' globalfilename ''],'AUTHOR: sext optimization','COMMENTS: '});
famsave=tango.Device('sys/settings/m-currents');famsave.Timeout=10000;
famsave.GenerateSettingsFile({['FILE:' globalfilename ''],'AUTHOR: sext optimization','COMMENTS: '});
magsaved=true;
ii=0;
jj=0;
else
ii=0;
jj=0;
end
else
magsaved=false;
ii=ii+1;
tango.Attribute([name '/Strength']).set=mag_values(ii);
magStrAttr.set=mag_values(ii);
pause(1);
for nn=1:nacq
......@@ -95,7 +124,7 @@ for is = 1:length(indmags)
end
plot(ax,DS,TL,'*-','MarkerSize',12,'LineWidth',2);
xlim([range(1)-0.2*K_delta + range(2)+0.2*K_delta]);
xlim([range(1)-0.2*K_delta range(2)+0.2*K_delta]);
xlabel([name]);
ylabel('total losses');
ax.FontSize = 12;
......@@ -127,15 +156,16 @@ for is = 1:length(indmags)
optimal,f(ind),'x',...
DS(1),TL(1),'s',...
'LineWidth',3,'MarkerSize',10);
xlabel([names{1}]);
xlabel([name]);
ylabel('total losses');
ax.FontSize = 12;
grid on;
legend('measured',['fit - rmse = ' num2str(rmse)],'optimum','initial');
filename=strrep(['Scan_' names{1} '.fig'],'/','_');
filename=strrep(['Scan_' name '.fig'],'/','_');
filenamemat=strrep(['Scan_' name '.mat'],'/','_');
filename=strrep(filename,'-','_');
saveas(gcf,fullfile(dirname,filename));
save(fullfile(dirname,filenamemat),'DS','TL','fitres','gof','name');
if optimal~=0
if ~automatic
prompt = ['Input factor to optimal correction K*' num2str(optimal) '? [0=no correction] K= '];
......@@ -149,21 +179,27 @@ for is = 1:length(indmags)
% check rips runnning. if running wait.
if scale_factor~=0
% set skews
tango.Attribute([name '/Strength']).set=K0+(optimal-K0)*scale_factor;
magStrAttr.set=K0+(optimal-K0)*scale_factor;
disp('optimum has been set');
pause(2);
else
% set skews
tango.Attribute([name '/Strength']).set=K0;
magStrAttr.set=K0;
disp('initial has been set');
pause(2);
end
else
tango.Attribute([name '/Strength']).set=K0;
magStrAttr.set=K0;
disp('initial values has been set back');
end
end
globalfilename=['Settings_endOpt_' datestr(now,'yyyymmmdd_HHMMSS') ];
famsave=tango.Device('sys/settings/m-strengths');famsave.Timeout=10000;
famsave.GenerateSettingsFile({['FILE:' globalfilename ''],'AUTHOR: sext optimization','COMMENTS: '});
famsave=tango.Device('sys/settings/m-currents');famsave.Timeout=10000;
famsave.GenerateSettingsFile({['FILE:' globalfilename ''],'AUTHOR: sext optimization','COMMENTS: '});
end
Markdown is supported
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