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

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

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