source: MML/trunk/machine/SOLEIL/StorageRing/orbit/solorbit.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 7.7 KB
Line 
1% GUI for orbit correction
2%
3%=============================================================
4% Instruction sequence to launch orbit program for SOLEIL
5% Laurent S. Nadolski
6% Adaptation from William J. Corbett SPEAR3 application
7%=============================================================
8%
9% TODO Amman's Factor not take off of the R-matrix: to do in the future
10%
11% See Also orbgui, bpmgui, corgui, respgui, sortbpms, soleilrestore, sortcors, restoreorbit
12
13NanoFlag = 1;
14
15disp('   Initializing orbit control panel...');
16
17%Check to see AcceleratorObjects loaded
18global THERING
19if isempty(getao) || ~exist('THERING','var')
20    disp('Warning: Load Accelerator Model and AcceleratorObjects first');
21    return
22end
23
24%Software operates in HW units
25switch2hw;
26
27%change directory to SOLEIL
28vpath = getfamilydata('Directory','Orbit');
29cd(vpath);
30
31%Clear global structures
32clear global SYS BPM COR RSP
33setappdata(0,'SYS',[]);
34setappdata(0,'BPM',[]);
35setappdata(0,'COR',[]);
36setappdata(0,'RSP',[]);
37
38%Declare global structures
39global SYS BPM COR RSP %... in the command window workspace for timer
40
41%Clear previous ORBIT figure
42orbfig = findobj(0,'tag','orbfig');  %orbfig "global"
43if ~isempty(orbfig), delete(orbfig); end
44
45%Initialize Structures for Orbit Program (no control parameters)
46BPM = BPMInit_Orb;
47COR = CORInit_Orb;
48
49%SYS parameters are required for initialization
50SYS.machine    = 'SOLEIL';
51if NanoFlag
52SYS.restorefile= 'soleilrestore_nano';
53else
54    SYS.restorefile= 'soleilrestore';
55end
56SYS.localdata  = [vpath 'localdata/'];
57SYS.reffile    = 'silver.dat';
58SYS.bpmode     = 'slowacquisition';
59SYS.plane      = 1;          % H-plane
60SYS.cortype    = COR(SYS.plane).AOFamily; % consistent with SYS.plane=1
61SYS.relative   = 1;          % Absolute mode
62SYS.current    = getdcct;        % Amperes
63SYS.energy     = getenergy;  % In GeV
64SYS.lifetime   = 15;         % Lifetime in hours
65SYS.units      ='HW';        %default to hardware units
66
67%Draw main figure
68orbgui('OrbFig');               %Figure with tag 'orbfig'
69% SYS.ahbpm = orbgui('Axes_1');   % Create handles for  Axes for BPM
70% setappdata(0,'SYS',SYS);
71orbgui('BPMAxes');              %establish upper axes for BPMs, use ah_1 for BPMs
72orbgui('CorAxes');              %COR axes with tag 'SYS.ahbpm'
73orbgui('SVDAxes');              %SVD axes with tag 'SYS.ahbpm'
74orbgui('BPMbox');               %BPM information display box
75orbgui('CorBox');               %COR information display box
76orbgui('SVDBox');               %SVD information display box
77orbgui('LstBox');               %List Box to display program information
78orbgui('PlotMenu');             %Menu for plot options
79orbgui('BPMMenu');              %Menu for BPM options
80orbgui('CORMenu');              %Menu for COR options
81orbgui('RespMenu');             %Menu for Response Matrix options
82orbgui('EtaMenu');              %Dispersion control panel
83orbgui('OptMenu');              %Menu for Optics options
84orbgui('SimMenu');              %Menu for Simulation options
85orbgui('SuperperiodMenu');      %Menu for Response Matrix options
86orbgui('SYSMenu');              %Menu for System options
87orbgui('UIControls');           %UIControls
88%orbgui('AlgorithmMenu');       %Algo choice
89%orbgui('BumpSlider');          %Bump height adjustment
90orbgui('MachineParameters');    %Text fields for system parameters, load initial values
91
92
93% init maximum x-scale
94SYS.xlimax = getcircumference;
95setappdata(0,'SYS',SYS);
96 
97orbgui('LoadRaw2Real'); %Load Raw2Real coefficients from physdata
98orbgui('LatticeAxes');  %Used to zoom abscissa
99orbgui('plotxaxis','allmachine');   %set default xaxis
100
101%Read reference orbit (to load iref; .abs and .des=.ref in routine)
102BPM = RefOrb2Zero(BPM);
103
104%Restore user parameters, load response matrices, golden orbit
105[SYS BPM COR RSP] = restoreorbit(vpath,SYS.restorefile,'auto',SYS,BPM,COR,RSP);  %no graphics commands
106
107%% Determine the mode used in the workspace
108switch getmode(COR(1).AOFamily);
109    case 'Online'
110        SYS.mode   = 'Online';
111        set(SYS.online, 'Checked', 'On');
112        set(SYS.orbfig,'Name', ...
113            'SOLEIL Storage Ring Orbit Correction Interface (Online)');
114        set(SYS.modecolor,'BackGroundColor','r','String','Online');       
115    otherwise % Assume simulator mode
116        SYS.mode   = 'Simulator';
117        set(SYS.sim, 'Checked', 'On');
118        set(SYS.orbfig,'Name', ...
119            'SOLEIL Storage Ring Orbit Correction Interface (Simulator)');
120        set(SYS.modecolor,'BackGroundColor','g','String','Simulator');
121end
122
123%% Get phase advanced for machine state
124optics     = gettwiss(THERING,0.0);
125BPM(1).phi = optics.phix(BPM(1).ATindex);
126BPM(2).phi = optics.phix(BPM(2).ATindex);
127COR(1).phi = optics.phix(COR(1).ATindex);
128COR(2).phi = optics.phix(COR(2).ATindex);
129clear optics;
130%NOTE: expect response matrix in hardware units (mm/amp)
131
132%%begin hardware checkouts
133%% BPM checking
134
135disp('   Checking BPMs...');
136[BPM(1).status BPM(2).status] = soleilbpmcheck; %get status from TANGO or sim
137BPM(1).avail = BPM(1).status;    %if status o.k. default to available
138BPM(2).avail = BPM(2).status;
139BPM = SortBPMs(BPM,RSP);         %sort for avail, ifit
140
141% Measure actual orbit
142bpmgui('GetAct');   % mm for hardware, meters for physics
143
144%% Corrector checking
145disp('   Checking corrector magnets...');
146[COR(1).status COR(2).status] = soleilcorcheck;
147COR(1).avail = COR(1).status;     %if status o.k. default to available
148COR(2).avail = COR(2).status;
149COR          = sortcors(COR,RSP); %Get COR status, sort for avail, ifit
150
151%Measure actual correctors
152corgui('GetAct');              %amps for hardware, rad for physics
153COR(1).ref = COR(1).act;
154COR(2).ref = COR(2).act;
155
156%Updates data in workspace
157BPM = orderfields(BPM);
158COR = orderfields(COR);
159setappdata(0,'BPM',BPM);
160setappdata(0,'COR',COR);
161
162%% Plot initial BPM data
163disp('   Initializing Plots...');
164bpmgui('PlotRef_Init');                %...solid red/loaded in BPMInit
165bpmgui('PlotIcons_Init');              %...hot circles
166bpmgui('PlotDes_Init');                %...dashed red line
167bpmgui('PlotAct_Init');                %...initialize blue actual orbit plot
168bpmgui('PlotFit_Init');                %...initialize orbit fit plot
169bpmgui('PlotResp_Init');               %...initialize response matrix plot
170bpmgui('PlotEig_Init');                %...initialize eigenvector plot
171bpmgui('PlotRef');                     %...solid red/loaded in BPMInit
172bpmgui('PlotBPMs');                    %...hot circles/loaded in BPMInit
173bpmgui('PlotAct');                     %...blue line/loaded in BPMInit
174
175%Plot initial cor data
176corgui('PlotCor_Init');                %...initialize corrector patches
177
178%Plot initial SVD data
179respgui('PlotSVD_Init');               %...initialize bpm and corrector eigenvector plots
180
181%Set up program parameters: both planes
182SYS = orderfields(SYS);
183disp('   Setting up program parameters...');
184SYS.plane = 1;                           %start with horizontal plane
185for ip = 1:2
186    orbgui('Plane');                   %switch to vertical
187    corgui('SaveCors',ip);            %saves one plane only, all correctors
188    COR(ip).rst = COR(ip).act;         %default reset field for 'REMOVE' button
189    setappdata(0,'COR',COR);
190end
191
192for ip = 2:-1:1
193    SYS.plane=ip;
194    setappdata(0,'SYS',SYS);
195    corgui('HidePlots');
196end
197corgui('ShowPlots');
198%orbgui('RefreshOrbGUI');
199readwrite('ReadBPMReference','XZ','Golden');  %load golden orbit, calls RefreshOrbGUI
200
201orbgui('InitialSaveSet');              %load data for restore
202orbgui('LBox',' Finished loading Restore File');
203
204% Orbit in micron {default}
205orbgui('BPMChangeUnits','1000xHardware');
206% Corrector in Harware units {default}
207orbgui('CORChangeUnits','Hardware');
208
209%make figure visible
210set(orbfig,'Visible','On');  drawnow;
211% pause(1.0); set(orbfig,'Visible','On');  drawnow;   %why repeat??
212disp('   Finished initializing orbit program');
213set(findobj(0,'Tag','orbfig'),'Visible','On');
214
215%% Cleaning up
216clear ip vpath AO orbfig;
Note: See TracBrowser for help on using the repository browser.