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