1 | %============================ |
---|
2 | %Launch ASP Orbit Program |
---|
3 | %============================ |
---|
4 | |
---|
5 | disp(' Initializing orbit control panel...'); |
---|
6 | |
---|
7 | %Check to see AcceleratorObjects loaded |
---|
8 | global THERING |
---|
9 | if isempty(getao) | ~exist('THERING') |
---|
10 | disp('Warning: Load Accelerator Model and AcceleratorObjects first'); |
---|
11 | return |
---|
12 | end |
---|
13 | |
---|
14 | %Clear any previous ORBIT figure |
---|
15 | orbfig = findobj(0,'tag','orbfig'); %orbfig "global" |
---|
16 | if ~isempty(orbfig) delete(orbfig); end |
---|
17 | |
---|
18 | %goto orbit directory |
---|
19 | cd(getfamilydata('Directory','Orbit')); |
---|
20 | |
---|
21 | %Software operates in HW units |
---|
22 | switch2hw; |
---|
23 | |
---|
24 | %Clear global structures |
---|
25 | clear global SYS BL BPM COR RSP |
---|
26 | setappdata(0,'SYS',[]); |
---|
27 | setappdata(0,'BPM',[]); |
---|
28 | setappdata(0,'COR',[]); |
---|
29 | setappdata(0,'RSP',[]); |
---|
30 | setappdata(0,'BL' ,[]); |
---|
31 | |
---|
32 | %Declare global structures |
---|
33 | global SYS BL BPM COR RSP |
---|
34 | |
---|
35 | %Load element names via AcceleratorObjects |
---|
36 | BL=getblnames; %initialize BL names |
---|
37 | BPM=getbpmnames; %initialize BPM names |
---|
38 | COR=getcornames; %initialize COR names |
---|
39 | |
---|
40 | %Initialize Structures for Orbit Program (no control parameters) |
---|
41 | BL=blinit_orb(BL); %do this first |
---|
42 | BPM=bpminit_orb(BPM); |
---|
43 | COR=corinit_orb(COR); |
---|
44 | |
---|
45 | |
---|
46 | %SYS parameters required for initialization |
---|
47 | SYS.machine='ASP'; |
---|
48 | SYS.restorefile='asprestore.m'; |
---|
49 | SYS.mode='ONLINE'; |
---|
50 | SYS.bpmode='Liberia'; |
---|
51 | SYS.plane=1; |
---|
52 | SYS.cortype='HCM'; %consistent with SYS.plane=1 |
---|
53 | SYS.relative=2; |
---|
54 | SYS.curr=0; SYS.engy=0; SYS.lt=0; SYS.ahr=0; |
---|
55 | SYS.units='HW'; %default to hardware units |
---|
56 | |
---|
57 | %open system log file |
---|
58 | |
---|
59 | %Draw main figure |
---|
60 | orbgui('OrbFig'); %Figure with tag 'orbfig' |
---|
61 | SYS.handles.ahbpm=orbgui('Axes_1'); |
---|
62 | setappdata(0,'SYS',SYS); |
---|
63 | orbgui('BPMAxes'); %establish upper axes for BPMs, use ah_1 for BPMs |
---|
64 | orbgui('CorAxes'); %COR axes with tag 'SYS.ahbpm' |
---|
65 | orbgui('SVDAxes'); %SVD axes with tag 'SYS.ahbpm' |
---|
66 | orbgui('BPMbox'); %BPM information display box |
---|
67 | orbgui('CorBox'); %COR information display box |
---|
68 | orbgui('SVDBox'); %SVD information display box |
---|
69 | orbgui('LstBox'); %List Box to display program information |
---|
70 | orbgui('PlotMenu'); %Menu for plot options |
---|
71 | orbgui('BPMMenu'); %Menu for BPM options |
---|
72 | orbgui('CORMenu'); %Menu for COR options |
---|
73 | orbgui('BLMenu'); %Menu for Beam line options |
---|
74 | orbgui('SimMenu'); %Menu for Simulation options |
---|
75 | orbgui('RespMenu'); %Menu for Response Matrix options |
---|
76 | orbgui('UIControls'); %UIControls |
---|
77 | orbgui('MachineParameters'); %Text fields for system parameters, load initial values |
---|
78 | orbgui('ZoomAxes'); %Used to zoom absicca |
---|
79 | aspelementicons; %initialize element icons (append fields to THERING) |
---|
80 | [SYS.elhndl]=elementiconpatch(SYS.handles.ahpos,SYS.elemind,'ShowElem'); %draw initial element icons, return handles |
---|
81 | orbgui('ZoomPatches'); %Initialize icons before zoom patchs (patches on top layer) |
---|
82 | |
---|
83 | %Load Gain and offsets from Physdata |
---|
84 | [BPM,COR,BL]=orbgui('LoadASPPhysData',BPM,COR,BL); |
---|
85 | |
---|
86 | %Read reference orbit (initiates BPM.iref/.abs/.des/.ref) |
---|
87 | BPM=reforb2zero(BPM); |
---|
88 | |
---|
89 | %Restore user parameters, load response matrices, golden orbit |
---|
90 | orbdir=getfamilydata('Directory','Orbit'); |
---|
91 | [SYS BPM BL COR RSP]=restoreorbit(orbdir,SYS.restorefile,'auto',SYS,BPM,BL,COR,RSP); %no graphics commands |
---|
92 | |
---|
93 | |
---|
94 | if strcmpi(SYS.datamode,'REAL') %convert response matrix to 'real' units NOTE: expect response matrix in hardware units (mm/amp) |
---|
95 | set(SYS.handles.orbfig,'Name',[get(SYS.handles.orbfig,'Name') ': Data units Real']); |
---|
96 | for k=1:2 |
---|
97 | ib=RSP(k).ib; |
---|
98 | ic=RSP(k).ic; |
---|
99 | RSP(k).c(ib,ic)=diag(BPM(k).gain(ib))*RSP(k).c(ib,ic); |
---|
100 | end |
---|
101 | end |
---|
102 | |
---|
103 | %raw: no change in RSP(k).c |
---|
104 | |
---|
105 | Circumference=getfamilydata('Circumference'); |
---|
106 | BPM(1).phi=(15/Circumference)*BPM(1).z(:); %...phase advance |
---|
107 | BPM(2).phi= (6/Circumference)*BPM(2).z(:); |
---|
108 | COR(1).phi=(15/Circumference)*COR(1).z(:); |
---|
109 | COR(2).phi= (6/Circumference)*COR(2).z(:); |
---|
110 | |
---|
111 | %begin hardware checkouts |
---|
112 | disp(' Checking Beamlines...'); |
---|
113 | %BL(2).DevList=getlist('BLOpen',0); %...valid photon BPMs in middlelayer |
---|
114 | %BL(2).ElemList=dev2elem('BLOpen',BL(2).DevList); |
---|
115 | %BL(2).status=getfamilydata('BLOpen','Status'); |
---|
116 | %BL=SortBLs(BL,RSP); %sort for avail, ifit |
---|
117 | |
---|
118 | disp(' Checking BPMs...'); |
---|
119 | families={'BPMx'; 'BPMy'}; |
---|
120 | for k=1:2 |
---|
121 | family=families{k}; |
---|
122 | BPM(k).status=find(getfamilydata(family,'Status')); %middle layer status indices |
---|
123 | BPM(k).avail=BPM(k).status; %if status o.k. default to available |
---|
124 | end |
---|
125 | BPM=sortbpms(BPM,RSP); %sort for avail, ifit |
---|
126 | |
---|
127 | %Measure actual orbit |
---|
128 | bpmgui('GetAct'); %mm for hardware, meters for physics |
---|
129 | |
---|
130 | disp(' Checking Correctors...'); |
---|
131 | families={'HCM'; 'VCM'}; |
---|
132 | for k=1:2 |
---|
133 | family=families{k}; |
---|
134 | COR(k).status=find(getfamilydata(family,'Status')); %middle layer status indices |
---|
135 | COR(k).avail=COR(k).status; %if status o.k. default to available |
---|
136 | end |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | %corrector reference |
---|
141 | corgui('GetAct'); %amps for hardware, rad for physics |
---|
142 | % COR(1).act=0*COR(1).z; |
---|
143 | % COR(2).act=0*COR(2).z; |
---|
144 | COR(1).ref=COR(1).act; |
---|
145 | COR(2).ref=COR(2).act; |
---|
146 | COR=sortcors(COR,RSP); %Get COR status, sort for avail, ifit |
---|
147 | |
---|
148 | setappdata(0,'BPM',BPM); |
---|
149 | setappdata(0,'BL',BL); |
---|
150 | setappdata(0,'COR',COR); |
---|
151 | |
---|
152 | %Plot initial BPM data |
---|
153 | disp(' Initializing Plots...'); |
---|
154 | bpmgui('PlotRef_Init'); %...solid red/loaded in BPMInit |
---|
155 | bpmgui('PlotDes_Init'); %...dashed red line |
---|
156 | bpmgui('PlotIcons_Init'); %...hot circles |
---|
157 | bpmgui('PlotAct_Init'); %...initialize blue actual orbit plot |
---|
158 | bpmgui('PlotFit_Init'); %...initialize orbit fit plot |
---|
159 | bpmgui('PlotResp_Init'); %...initialize response matrix plot |
---|
160 | bpmgui('PlotEig_Init'); %...initialize eigenvector plot |
---|
161 | bpmgui('PlotRef'); %...solid red/loaded in BPMInit |
---|
162 | bpmgui('PlotBPMs'); %...hot circles/loaded in BPMInit |
---|
163 | bpmgui('PlotAct'); %...blue line/loaded in BPMInit |
---|
164 | |
---|
165 | %Plot initial cor data |
---|
166 | corgui('PlotCor_Init'); %...initialize corrector patches |
---|
167 | |
---|
168 | %Plot initial SVD data |
---|
169 | respgui('PlotSVD_Init'); %...initialize bpm and corrector eigenvector plots |
---|
170 | |
---|
171 | %Set up program parameters: both planes |
---|
172 | disp(' Setting up program parameters...'); |
---|
173 | SYS.plane=1; %start with horizontal plane |
---|
174 | for ip=1:2 |
---|
175 | %COR=getappdata(0,'COR'); |
---|
176 | orbgui('Plane'); %switch to vertical |
---|
177 | corgui('SaveCorrs',ip); %saves one plane only, all correctors |
---|
178 | COR(ip).rst=COR(ip).act; %default reset field for 'REMOVE' button |
---|
179 | setappdata(0,'COR',COR); |
---|
180 | |
---|
181 | orbgui('RescaleBPMAxis'); |
---|
182 | orbgui('RescaleCORAxis'); |
---|
183 | end |
---|
184 | |
---|
185 | for k=2:-1:1 |
---|
186 | SYS.plane=k; |
---|
187 | setappdata(0,'SYS',SYS); |
---|
188 | corgui('HidePlots'); |
---|
189 | end |
---|
190 | corgui('ShowPlots'); |
---|
191 | |
---|
192 | %load golden orbit |
---|
193 | readwrite('ReadBPMReference','B','Golden'); %load golden orbit, RefreshOrbGUI |
---|
194 | |
---|
195 | orbgui('LBox',' Finished loading Restore File'); |
---|
196 | |
---|
197 | |
---|
198 | set(orbfig,'Visible','On'); drawnow; %make figure visible |
---|
199 | disp(' Finished initializing orbit program'); |
---|
200 | |
---|
201 | clear k orbfig orbdir; |
---|
202 | |
---|