source: MML/trunk/machine/THOMX/StorageRing/Ringcycling.m

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

ThomX MML version on the LAL server @ 17/12/2013

  • Property svn:executable set to *
File size: 37.2 KB
Line 
1function varargout = Ringcycling(varargin)
2% RINGCYCLING M-file for Ringcycling.fig
3%      RINGCYCLING, by itself, creates a new RINGCYCLING or raises the existing
4%      singleton*.
5%
6%      H = RINGCYCLING returns the handle to a new RINGCYCLING or the handle to
7%      the existing singleton*.
8%
9%      RINGCYCLING('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in RINGCYCLING.M with the given input arguments.
11%
12%      RINGCYCLING('Property','Value',...) creates a new RINGCYCLING or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before Ringcycling_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to Ringcycling_OpeningFcn via varargin.
17%
18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19%      instance to run (singleton)".
20%
21% See also: getcyclecurve, magnetcycle, LT1cycling, setcyclecurve, cyclingcommand
22
23% Edit the above text to modify the response to help Ringcycling
24
25% Last Modified by GUIDE v2.5 22-Oct-2013 11:25:57
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30                   'gui_Singleton',  gui_Singleton, ...
31                   'gui_OpeningFcn', @Ringcycling_OpeningFcn, ...
32                   'gui_OutputFcn',  @Ringcycling_OutputFcn, ...
33                   'gui_LayoutFcn',  [] , ...
34                   'gui_Callback',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46
47% --- Executes just before Ringcycling is made visible.
48function Ringcycling_OpeningFcn(hObject, eventdata, handles, varargin)
49% This function has no output args, see OutputFcn.
50% hObject    handle to figure
51% eventdata  reserved - to be defined in a future version of MATLAB
52% handles    structure with handles and user data (see GUIDATA)
53% varargin   command line arguments to Ringcycling (see VARARGIN)
54
55% Choose default command line output for Ringcycling
56handles.output = hObject;
57
58% A MODIFIER ULTERIEUREMENT : INACTIVATION DES FONCTIONS
59% CYCLAGE CORRECTEURS / ALL
60set(handles.checkbox_HCOR,'Value',0);
61set(handles.checkbox_VCOR,'Value',0);
62set(handles.checkbox_all,'Value',0);
63set(handles.checkbox_all,'Enable','On');
64
65%set([handles.checkbox_all,handles.checkbox_HCOR,handles.checkbox_VCOR],...
66%    'Enable','off');
67
68% par defaut type cyclage sur 'full'
69set(handles.popupmenu_type,'Value',2);
70
71% button group sur switch mode simulation ou online
72h = uibuttongroup('visible','off','Position',[0.56 0.46 .18 .10],...
73    'Title','','TitlePosition','centertop',...
74    'BackgroundColor',[0.696 1.0 0.924]);
75u1 = uicontrol('Style','Radio','String','premier element','Tag','radiobutton1',...
76    'pos',[10 25 120 25],'parent',h,'HandleVisibility','off',...
77    'BackgroundColor',[0.696 1.0 0.924]);
78u2 = uicontrol('Style','Radio','String','toute la famille','Tag','radiobutton2',...
79    'pos',[10 0.95 120 25],'parent',h,'HandleVisibility','off',...
80    'BackgroundColor',[0.696 1.0 0.924]);
81
82set(h,'SelectionChangeFcn',...
83    {@uibuttongroup_SelectionChangeFcn,handles});
84
85set(h,'SelectedObject',u1);  % No selection
86set(h,'Visible','on');
87
88% mode de plot
89handles.mode = '1element';
90handles.configmode = 'confignominal';
91
92% Update handles structure
93guidata(hObject, handles);
94
95% UIWAIT makes Ringcycling wait for user response (see UIRESUME)
96% uiwait(handles.figure1);
97list = {'Present', 'Golden', 'UserSelect'};
98set(handles.popupmenu_file,'String',list);
99
100list = {'Simple', 'Full', 'startup'};
101set(handles.popupmenu_type,'String',list);
102
103list = {'Load cycling curve','Start', 'StartOnly', 'Stop', 'Init', 'Pause', 'Resume'};
104set(handles.popupmenu_command,'String',list);
105
106% --- Outputs from this function are returned to the command line.
107function varargout = Ringcycling_OutputFcn(hObject, eventdata, handles)
108% varargout  cell array for returning output args (see VARARGOUT);
109% hObject    handle to figure
110% eventdata  reserved - to be defined in a future version of MATLAB
111% handles    structure with handles and user data (see GUIDATA)
112
113% Get default command line output from handles structure
114varargout{1} = handles.output;
115
116
117% --- Executes on button press in checkbox_none.
118function checkbox_none_Callback(hObject, eventdata, handles)
119% hObject    handle to checkbox_none (see GCBO)
120% eventdata  reserved - to be defined in a future version of MATLAB
121% handles    structure with handles and user data (see GUIDATA)
122
123% Hint: get(hObject,'Value') returns toggle state of checkbox_none
124val = get(hObject,'Value');
125
126if val
127    set(handles.checkbox_BEND,'Value',0);
128    set(handles.checkbox_HCOR,'Value',0);
129    set(handles.checkbox_VCOR,'Value',0);
130    %set(handles.checkbox_QT,'Value',0);
131   
132    % Quads   
133    for k =1:(length(findmemberof('QUAD'))-2),
134        Name = strcat('QP',num2str(k));
135        set(handles.(['checkbox_',Name]),'Value',0)
136    end
137    set(handles.(['checkbox_','QP31']),'Value',0)
138    set(handles.(['checkbox_','QP41']),'Value',0)
139   
140    % Sextu
141    set(handles.checkbox_SX1,'Value',0);
142    set(handles.checkbox_SX2,'Value',0);
143    set(handles.checkbox_SX3,'Value',0);
144 
145
146    set(handles.checkbox_all,'Value',0);
147    set(handles.checkbox_AllQuad,'Value',0);
148    set(handles.checkbox_AllSextu,'Value',0);
149    set(handles.checkbox_noneQuad,'Value',1);
150    set(handles.checkbox_NoneSextu,'Value',1);
151
152else
153    set(handles.checkbox_noneQuad,'Value',0);
154    set(handles.checkbox_NoneSextu,'Value',0);
155end
156
157% --- Executes on button press in checkbox_all.
158function checkbox_all_Callback(hObject, eventdata, handles)
159% hObject    handle to checkbox_all (see GCBO)
160% eventdata  reserved - to be defined in a future version of MATLAB
161% handles    structure with handles and user data (see GUIDATA)
162
163% Hint: get(hObject,'Value') returns toggle state of checkbox_all
164
165% not used
166%disp('checkbox_all_Callback: Not used');
167%return;
168val = get(hObject,'Value');
169
170if val
171    set(handles.checkbox_BEND,'Value',1);
172   
173    % Quad
174   
175    for k =1:4, %length(findmemberof('QUAD')),
176        Name = strcat('QP',num2str(k));
177        set(handles.(['checkbox_',Name]),'Value',1)
178    end
179     set(handles.(['checkbox_','QP31']),'Value',1)
180     set(handles.(['checkbox_','QP41']),'Value',1)
181     
182    % Sextu       
183    set(handles.checkbox_SX1,'Value',1);
184    set(handles.checkbox_SX2,'Value',1);
185    set(handles.checkbox_SX3,'Value',1);
186   
187    % Correctors
188    set(handles.checkbox_HCOR,'Value',1);
189    set(handles.checkbox_VCOR,'Value',1);
190
191    set(handles.checkbox_all,'Value',1);
192    set(handles.checkbox_AllQuad,'Value',1);
193    set(handles.checkbox_AllSextu,'Value',1);
194    set(handles.checkbox_noneQuad,'Value',0);
195    set(handles.checkbox_NoneSextu,'Value',0);
196    % none
197    set(handles.checkbox_none,'Value',0);
198else
199    set(handles.checkbox_BEND,'Value',0);
200   
201    % Quad
202   
203    for k =1:4, %length(findmemberof('QUAD')),
204        Name = strcat('QP',num2str(k));
205        set(handles.(['checkbox_',Name]),'Value',0)
206    end
207     set(handles.(['checkbox_','QP31']),'Value',0)
208     set(handles.(['checkbox_','QP41']),'Value',0)
209     
210    % Sextu       
211    set(handles.checkbox_SX1,'Value',0);
212    set(handles.checkbox_SX2,'Value',0);
213    set(handles.checkbox_SX3,'Value',0);
214   
215    % Correctors
216    set(handles.checkbox_HCOR,'Value',0);
217    set(handles.checkbox_VCOR,'Value',0);
218
219    set(handles.checkbox_all,'Value',0);
220    set(handles.checkbox_AllQuad,'Value',0);
221    set(handles.checkbox_AllSextu,'Value',0);
222    set(handles.checkbox_noneQuad,'Value',0);
223    set(handles.checkbox_NoneSextu,'Value',0);
224    % none
225    set(handles.checkbox_none,'Value',0);
226end
227
228
229% --- Executes on button press in checkbox_BEND.
230function checkbox_BEND_Callback(hObject, eventdata, handles)
231% hObject    handle to checkbox_BEND (see GCBO)
232% eventdata  reserved - to be defined in a future version of MATLAB
233% handles    structure with handles and user data (see GUIDATA)
234
235% Hint: get(hObject,'Value') returns toggle state of checkbox_BEND
236
237set(handles.checkbox_all,'Value',0);
238set(handles.checkbox_none,'Value',0);
239val = get(handles.checkbox_BEND,'Value');
240valQP1 = get(handles.checkbox_QP1,'Value');valQP2 = get(handles.checkbox_QP2,'Value');
241valQP3 = get(handles.checkbox_QP3,'Value');valQP4 = get(handles.checkbox_QP4,'Value');
242valQP31 = get(handles.checkbox_QP31,'Value');valQP41 = get(handles.checkbox_QP41,'Value');
243
244valQtous = get(handles.checkbox_AllQuad,'Value');
245valeurs = [valQP1 valQP2 valQP3 valQP4 valQP31 valQP41 valQtous];
246test = ones(7,1)'*0;
247
248if val   
249    if ~isequal(valeurs,test)
250        errordlg('conflit entre Quad et Dipole !','Erreur');
251        set(handles.checkbox_BEND,'Value',0);
252        return
253    end
254   
255    % Disable cycling quadrupole and sextupoles
256    for k = 1:4%length(findmemberof('QUAD'))
257        Name = strcat('QP',num2str(k));
258        set(handles.(['checkbox_',Name]),'Enable','off')
259    end
260   
261    set(handles.(['checkbox_','QP31']),'Enable','off');
262    set(handles.(['checkbox_','QP41']),'Enable','off');
263   
264    set(handles.checkbox_AllQuad,'Enable','off');
265
266    set(handles.checkbox_AllSextu,'Enable','off')
267    for k = 1:length(findmemberof('SEXT'))
268        Name = strcat('SX',num2str(k));
269        set(handles.(['checkbox_',Name]),'Enable','off')
270    end   
271
272else
273    val2 = get(handles.checkbox_AllQuad,'Value');
274    if val2==0
275       
276        % Enable cyling of quad and sextu
277        for k = 1:4%length(findmemberof('QUAD'))
278            Name = strcat('QP',num2str(k));
279            set(handles.(['checkbox_',Name]),'Enable','on')
280        end
281         set(handles.(['checkbox_','QP31']),'Enable','on');
282         set(handles.(['checkbox_','QP41']),'Enable','on');
283        set(handles.checkbox_AllQuad,'Enable','on');
284
285        set(handles.checkbox_AllSextu,'Enable','on')
286        for k = 1:length(findmemberof('SEXT'))
287            Name = strcat('SX',num2str(k));
288            set(handles.(['checkbox_',Name]),'Enable','on')
289        end
290
291    end
292end
293
294
295% --- Executes on button press in checkbox_QP1.
296function checkbox_QP1_Callback(hObject, eventdata, handles)
297% hObject    handle to checkbox_QP1 (see GCBO)
298% eventdata  reserved - to be defined in a future version of MATLAB
299% handles    structure with handles and user data (see GUIDATA)
300
301% Hint: get(hObject,'Value') returns toggle state of checkbox_QP1
302
303
304set(handles.checkbox_all,'Value',0);
305set(handles.checkbox_none,'Value',0);
306
307% --- Executes on button press in checkbox_HCOR.
308function checkbox_HCOR_Callback(hObject, eventdata, handles)
309% hObject    handle to checkbox_HCOR (see GCBO)
310% eventdata  reserved - to be defined in a future version of MATLAB
311% handles    structure with handles and user data (see GUIDATA)
312
313% Hint: get(hObject,'Value') returns toggle state of checkbox_HCOR
314
315set(handles.checkbox_all,'Value',0);
316set(handles.checkbox_none,'Value',0);
317
318% --- Executes on button press in checkbox_VCOR.
319function checkbox_VCOR_Callback(hObject, eventdata, handles)
320% hObject    handle to checkbox_VCOR (see GCBO)
321% eventdata  reserved - to be defined in a future version of MATLAB
322% handles    structure with handles and user data (see GUIDATA)
323
324% Hint: get(hObject,'Value') returns toggle state of checkbox_VCOR
325
326set(handles.checkbox_all,'Value',0);
327set(handles.checkbox_none,'Value',0);
328
329% --- Executes on button press in pushbutton_apply.
330function pushbutton_apply_Callback(hObject, eventdata, handles)
331% hObject    handle to pushbutton_apply (see GCBO)
332% eventdata  reserved - to be defined in a future version of MATLAB
333% handles    structure with handles and user data (see GUIDATA)
334
335contents = get(handles.popupmenu_command,'String');
336command = contents{get(handles.popupmenu_command,'Value')};
337
338switch command
339    case {'Load cycling curve','Start', 'StartOnly', 'Stop','Init','Pause','Resume'}
340        cyclemagnet_local(command,handles);
341    otherwise
342        error('Unknown command name: %s ', command);
343end
344
345
346%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348
349 function cyclemagnet_local(command,handles)
350
351%     [CycleIndex, CycleAO] = isfamily(CycleFamily);
352%
353%     rep = tango_group_command_inout2(CycleAO.GroupId,'State',1,0);
354
355Family={'BEND',...
356        'QP1','QP2','QP3','QP4','QP31','QP41'...
357        'SX1','SX2','SX3',...
358        'HCOR','VCOR'};   
359   
360Families = {};
361for k =1:length(Family)
362    if get(handles.(['checkbox_',Family{k}]),'Value')
363        Families = {Families{:}, Family{k}};
364    end
365end
366
367% Check if quad ie magnets with offsets used for FFWD on tunes
368quadFlag = 0;
369for k=1:length(Families),
370    if ismemberof(Families{k}, 'QUAD')
371        quadFlag = 1;
372    end
373end
374
375
376if quadFlag
377    % Disable undulator tune FFWD
378    % tango_write_attribute2('ans/ei/nuffwd', 'booleanResult', uint8(0))
379    % Should give back 0
380    % temp = tango_read_attribute2('ans/ei/nuffwd', 'booleanResult')
381%     FFWDFlag = readattribute('ans/ei/nuffwd/booleanResult');
382%     if FFWDFlag ~=0
383%         errordlg(sprintf('Tune FFWD still active\n Cycling aborted'));
384%         return;
385%     else
386%         Answer = questdlg('Forcing Offsets of quadrupoles to zero (no: cancel)', 'Confirmation box','Yes','No','No');
387%         if strcmpi(Answer, 'No')
388%             %
389%         else
390%             setquadoffset2zero
391%             pause(1);
392%         end
393%         % Check Offsets before any cycling
394%         % Set offsets to zero
395%         lineStr = sprintf('Offsets non zero\n\n');
396%         NonZeroOffsetFlag =0; Str1={'yes', 'no'};
397%         for k=1:length(Families),
398%             if ismemberof(Families{k}, 'QUAD')
399%                  % Check offset null
400%                  lineStr = [lineStr sprintf('Family % 4s  Offset null ? %s \n', Families{k}, ...
401%                      Str1{any(getpv(Families{k}, 'SumOffset') ~= 0)})];
402%                  NonZeroOffsetFlag =any(getpv(Families{k}, 'SumOffset') ~= 0) | NonZeroOffsetFlag;
403%             end
404%         end
405%         
406%         % Popup menu if nonzero offsets
407%         if NonZeroOffsetFlag
408%             lineStr = [lineStr sprintf('\n\n Continue ?\n');];
409%             Answer = questdlg(lineStr, 'Cycling','Yes','No','No');
410%             if strcmpi(Answer, 'No')
411%                 return;
412%             end
413%         end
414%         % ANS-C10/EI/C-U20_OFFF/nuffCorrectionOuputEnabled
415%     end
416end
417
418switch command
419    case {'Start'}
420        % get cycling file
421        contents = get(handles.popupmenu_file,'String');
422        file = contents{get(handles.popupmenu_file,'Value')};
423
424        % get cycling type
425        contents = get(handles.popupmenu_type,'String');
426        type = contents{get(handles.popupmenu_type,'Value')};
427
428        % cycle magnets
429        magnetcycle(type,file,Families,'NoDisplay','Config');
430       
431    case {'StartOnly'}
432        % get cycling file
433        contents = get(handles.popupmenu_file,'String');
434        file = contents{get(handles.popupmenu_file,'Value')};
435
436        % get cycling type
437        contents = get(handles.popupmenu_type,'String');
438        type = contents{get(handles.popupmenu_type,'Value')};
439
440        % Cycle magnet
441        magnetcycle(type,file,Families,'NoDisplay','NoConfig');
442
443    case {'Load cycling curve'}
444       
445        contents = get(handles.popupmenu_file,'String');
446        file = contents{get(handles.popupmenu_file,'Value')};
447
448        % get cycling file
449        contents = get(handles.popupmenu_type,'String');
450        type = contents{get(handles.popupmenu_type,'Value')};
451
452        % Config magnet
453        magnetcycle(type,file,Families,'NoDisplay','Config','NoApply');
454       
455       
456    case {'Stop','Init','Pause','Resume'}
457        for k =1:length(Families)
458            CycleFamily = ['Cycle' Families{k}];
459            cyclingcommand(CycleFamily,command);
460        end
461end
462
463% --- Executes on selection change in popupmenu_command.
464function popupmenu_command_Callback(hObject, eventdata, handles)
465% hObject    handle to popupmenu_command (see GCBO)
466% eventdata  reserved - to be defined in a future version of MATLAB
467% handles    structure with handles and user data (see GUIDATA)
468
469% Hints: contents = get(hObject,'String') returns popupmenu_command contents as cell array
470%        contents{get(hObject,'Value')} returns selected item from popupmenu_command
471
472% --- Executes during object creation, after setting all properties.
473function popupmenu_command_CreateFcn(hObject, eventdata, handles)
474% hObject    handle to popupmenu_command (see GCBO)
475% eventdata  reserved - to be defined in a future version of MATLAB
476% handles    empty - handles not created until after all CreateFcns called
477
478% Hint: popupmenu controls usually have a white background on Windows.
479%       See ISPC and COMPUTER.
480if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
481    set(hObject,'BackgroundColor','white');
482end
483
484
485% --- Executes on selection change in popupmenu_type.
486function popupmenu_type_Callback(hObject, eventdata, handles)
487% hObject    handle to popupmenu_type (see GCBO)
488% eventdata  reserved - to be defined in a future version of MATLAB
489% handles    structure with handles and user data (see GUIDATA)
490
491% Hints: contents = get(hObject,'String') returns popupmenu_type contents as cell array
492%        contents{get(hObject,'Value')} returns selected item from popupmenu_type
493
494
495% --- Executes during object creation, after setting all properties.
496function popupmenu_type_CreateFcn(hObject, eventdata, handles)
497% hObject    handle to popupmenu_type (see GCBO)
498% eventdata  reserved - to be defined in a future version of MATLAB
499% handles    empty - handles not created until after all CreateFcns called
500
501% Hint: popupmenu controls usually have a white background on Windows.
502%       See ISPC and COMPUTER.
503if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
504    set(hObject,'BackgroundColor','white');
505end
506
507
508% --- Executes on selection change in popupmenu_file.
509function popupmenu_file_Callback(hObject, eventdata, handles)
510% hObject    handle to popupmenu_file (see GCBO)
511% eventdata  reserved - to be defined in a future version of MATLAB
512% handles    structure with handles and user data (see GUIDATA)
513
514% Hints: contents = get(hObject,'String') returns popupmenu_file contents as cell array
515%        contents{get(hObject,'Value')} returns selected item from popupmenu_file
516
517
518% --- Executes during object creation, after setting all properties.
519function popupmenu_file_CreateFcn(hObject, eventdata, handles)
520% hObject    handle to popupmenu_file (see GCBO)
521% eventdata  reserved - to be defined in a future version of MATLAB
522% handles    empty - handles not created until after all CreateFcns called
523
524% Hint: popupmenu controls usually have a white background on Windows.
525%       See ISPC and COMPUTER.
526if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
527    set(hObject,'BackgroundColor','white');
528end
529
530
531% --- Executes on button press in checkbox_QP2.
532function checkbox_QP2_Callback(hObject, eventdata, handles)
533% hObject    handle to checkbox_QP2 (see GCBO)
534% eventdata  reserved - to be defined in a future version of MATLAB
535% handles    structure with handles and user data (see GUIDATA)
536
537% Hint: get(hObject,'Value') returns toggle state of checkbox_QP2
538
539
540set(handles.checkbox_all,'Value',0);
541set(handles.checkbox_none,'Value',0);
542
543
544% --- Executes on button press in checkbox_QP3.
545function checkbox_QP3_Callback(hObject, eventdata, handles)
546% hObject    handle to checkbox_QP3 (see GCBO)
547% eventdata  reserved - to be defined in a future version of MATLAB
548% handles    structure with handles and user data (see GUIDATA)
549
550% Hint: get(hObject,'Value') returns toggle state of checkbox_QP3
551set(handles.checkbox_all,'Value',0);
552set(handles.checkbox_none,'Value',0);
553
554
555% --- Executes on button press in checkbox_QP4.
556function checkbox_QP4_Callback(hObject, eventdata, handles)
557% hObject    handle to checkbox_QP4 (see GCBO)
558% eventdata  reserved - to be defined in a future version of MATLAB
559% handles    structure with handles and user data (see GUIDATA)
560
561% Hint: get(hObject,'Value') returns toggle state of checkbox_QP4
562
563set(handles.checkbox_all,'Value',0);
564set(handles.checkbox_none,'Value',0);
565
566% --- Executes on button press in checkbox_QP31.
567function checkbox_QP31_Callback(hObject, eventdata, handles)
568% hObject    handle to checkbox_QP31 (see GCBO)
569% eventdata  reserved - to be defined in a future version of MATLAB
570% handles    structure with handles and user data (see GUIDATA)
571
572% Hint: get(hObject,'Value') returns toggle state of checkbox_QP31
573set(handles.checkbox_all,'Value',0);
574set(handles.checkbox_none,'Value',0);
575
576
577% --- Executes on button press in checkbox_QP41.
578function checkbox_QP41_Callback(hObject, eventdata, handles)
579% hObject    handle to checkbox_QP41 (see GCBO)
580% eventdata  reserved - to be defined in a future version of MATLAB
581% handles    structure with handles and user data (see GUIDATA)
582
583% Hint: get(hObject,'Value') returns toggle state of checkbox_QP41
584set(handles.checkbox_all,'Value',0);
585set(handles.checkbox_none,'Value',0);
586
587
588% --- Executes on button press in checkbox_SX1.
589function checkbox_SX1_Callback(hObject, eventdata, handles)
590% hObject    handle to checkbox_SX1 (see GCBO)
591% eventdata  reserved - to be defined in a future version of MATLAB
592% handles    structure with handles and user data (see GUIDATA)
593
594% Hint: get(hObject,'Value') returns toggle state of checkbox_SX1
595
596
597set(handles.checkbox_all,'Value',0);
598set(handles.checkbox_none,'Value',0);
599
600
601% --- Executes on button press in checkbox_SX2.
602function checkbox_SX2_Callback(hObject, eventdata, handles)
603% hObject    handle to checkbox_SX2 (see GCBO)
604% eventdata  reserved - to be defined in a future version of MATLAB
605% handles    structure with handles and user data (see GUIDATA)
606
607% Hint: get(hObject,'Value') returns toggle state of checkbox_SX2
608
609set(handles.checkbox_all,'Value',0);
610set(handles.checkbox_none,'Value',0);
611
612
613% --- Executes on button press in checkbox_SX3.
614function checkbox_SX3_Callback(hObject, eventdata, handles)
615% hObject    handle to checkbox_SX3 (see GCBO)
616% eventdata  reserved - to be defined in a future version of MATLAB
617% handles    structure with handles and user data (see GUIDATA)
618
619% Hint: get(hObject,'Value') returns toggle state of checkbox_SX3
620
621set(handles.checkbox_all,'Value',0);
622set(handles.checkbox_none,'Value',0);
623
624% --- Executes on button press in checkbox_AllQuad.
625function checkbox_AllQuad_Callback(hObject, eventdata, handles)
626% hObject    handle to checkbox_AllQuad (see GCBO)
627% eventdata  reserved - to be defined in a future version of MATLAB
628% handles    structure with handles and user data (see GUIDATA)
629
630% Hint: get(hObject,'Value') returns toggle state of checkbox_AllQuad
631
632set(handles.checkbox_all,'Value',0);
633set(handles.checkbox_none,'Value',0);
634val = get(handles.checkbox_AllQuad,'Value');
635
636% Selection of number for families depending on the config
637switch handles.configmode
638    case 'confignominal'
639        kQmax = 6;
640        kSmax = 3; 
641end
642
643if val
644    set(handles.checkbox_noneQuad,'Value',0);     
645    for k = 1:(kQmax-2),
646        Name = strcat('QP',num2str(k));
647        set(handles.(['checkbox_',Name]),'Enable','on')
648        set(handles.(['checkbox_',Name]),'Value',1)
649    end
650        set(handles.(['checkbox_','QP31']),'Enable','on');
651        set(handles.(['checkbox_','QP31']),'Value',1);
652        set(handles.(['checkbox_','QP41']),'Enable','on');
653        set(handles.(['checkbox_','QP41']),'Value',1);
654       
655    % exclure la montee des dipoles et sextus
656    for k = 1:kSmax
657        Name = strcat('SX',num2str(k));
658        set(handles.(['checkbox_',Name]),'Enable','off')
659    end
660    set(handles.checkbox_AllSextu,'Enable','off');
661    set(handles.checkbox_BEND,'Enable','off');
662
663end
664
665% --- Executes on button press in checkbox_AllSextu.
666function checkbox_AllSextu_Callback(hObject, eventdata, handles)
667% hObject    handle to checkbox_AllSextu (see GCBO)
668% eventdata  reserved - to be defined in a future version of MATLAB
669% handles    structure with handles and user data (see GUIDATA)
670
671% Hint: get(hObject,'Value') returns toggle state of checkbox_AllSextu
672
673set(handles.checkbox_all,'Value',0);
674set(handles.checkbox_none,'Value',0);
675val = get(handles.checkbox_AllSextu,'Value');
676
677% Selection of number for families depending on the config
678switch handles.configmode
679    case 'confignominal'
680        kQmax = 6;
681        kSmax = 3;
682end
683
684if val
685    set(handles.checkbox_NoneSextu,'Value',0);   
686     
687    for k = 1:kSmax,
688        Name = strcat('SX',num2str(k));
689        set(handles.(['checkbox_',Name]),'Enable','off');
690        set(handles.(['checkbox_',Name]),'Value',1)
691    end
692    % Disable cycling on quad and dipole
693    for k = 1:(kQmax-2),
694        Name = strcat('QP',num2str(k));
695        set(handles.(['checkbox_',Name]),'Enable','off')
696    end
697    set(handles.(['checkbox_','QP31']),'Enable','off')
698    set(handles.(['checkbox_','QP41']),'Enable','off')
699   
700    set(handles.checkbox_AllQuad,'Enable','off');
701    set(handles.checkbox_BEND,'Enable','off');
702
703else
704   
705    for k = 1:kSmax,
706        Name = strcat('SX',num2str(k));
707        set(handles.(['checkbox_',Name]),'Enable','on')
708    end
709    % rendre possible la montee des dipoles et quad
710    for k = 1:(kQmax-2),
711        Name = strcat('QP',num2str(k));
712        set(handles.(['checkbox_',Name]),'Enable','on')
713    end
714    set(handles.(['checkbox_','QP31']),'Enable','on')
715    set(handles.(['checkbox_','QP41']),'Enable','on')
716    set(handles.checkbox_AllQuad,'Enable','on');
717    set(handles.checkbox_BEND,'Enable','on');
718end
719
720
721
722% --- Executes on button press in courbe_pushbutton.
723function courbe_pushbutton_Callback(hObject, eventdata, handles)
724% hObject    handle to courbe_pushbutton (see GCBO)
725% eventdata  reserved - to be defined in a future version of MATLAB
726% handles    structure with handles and user data (see GUIDATA)
727
728% valBEND = get(handles.checkbox_BEND,'Value');
729% valQ1 = get(handles.checkbox_QP1,'Value');valQ2 = get(handles.checkbox_QP2,'Value');
730% valQ3 = get(handles.checkbox_QP3,'Value');valQ4 = get(handles.checkbox_QP4,'Value');
731% valQ5 = get(handles.checkbox_QP31,'Value');valQ6 = get(handles.checkbox_QP41,'Value');
732% valQtous = get(handles.checkbox_AllQuad,'Value');
733% valS1 = get(handles.checkbox_SX1,'Value');valS2 = get(handles.checkbox_SX2,'Value');
734% valQ3 = get(handles.checkbox_SX3,'Value');valS4 = get(handles.checkbox_S4,'Value');
735% valStous = get(handles.checkbox_AllSextu,'Value');
736% %valeurs = [valQ1 valQ2 valQ3 valQ4 valQ5 valQ6 valQtous];
737% test = ones(7,1)'*0;
738
739%  for i = 1:10
740%       name = strcat('valQ',num2str(i))
741%        if eval(name)
742
743name=['axes' num2str(1)];
744axes(handles.(name));
745
746Family={'BEND', 'HCOR', 'VCOR',...
747    'QP1','QP2','QP3','QP4','QP31','QP41'...
748    'SX1','SX2','SX3'};   
749   
750hold off;
751
752for k =1:length(Family)
753    if get(handles.(['checkbox_',Family{k}]),'Value')
754        Name = strcat('Cycle',Family{k});
755        %Name = Family{k};
756
757        %vect = getfamilydata(Name,'DeviceName');
758        vect = family2tangodev(Name);
759        if ~iscell(vect)
760            vect = {vect};
761        end
762        if strcmp(handles.mode,'1element')
763            jend = 1;
764        elseif strcmp(handles.mode,'lafamille')
765            jend = length(vect);
766        end
767
768        % plot de la courbe de cyclage du premier element magnetique de la
769        % famille)
770        for j = 1:jend
771            curve = getcyclecurve(vect{j});
772
773            if iscell(curve)
774                for k=1:length(curve),
775                    n = size(curve{k}.Data,1);
776                    % time vector
777                    cums = cumsum(curve{k}.Data(:,2))';
778                    x = [cums; cums];
779                    x = reshape(x,1,2*n);
780                    x = [0 x(1:end-1)];
781
782                    % amplitude vector
783                    y = [curve{k}.Data(:,1),curve{k}.Data(:,1)]';
784                    y = reshape(y,1,2*n);
785                   
786                    plot(x,y,'b.-');
787                    xlabel('Temps (s)');
788                    ylabel('Courant [A]');
789                    ylim([min(y) max(y)*1.05]);
790                    title(['Cycling curve for ' curve{k}.DeviceName]);
791                    grid on
792                end
793            else
794                n = size(curve,1);
795                % time vector
796                cums = cumsum(curve(:,2))';
797                x = [cums; cums];
798                x = reshape(x,1,2*n);
799                x = [0 x(1:end-1)];
800
801                % amplitude vector
802                y = [curve(:,1),curve(:,1)]';
803                y = reshape(y,1,2*n);
804
805
806                plot(x,y,'b.-');
807                xlabel('Temps (s)');
808                ylabel('Courant [A]');
809                ylim([min(y)*1.1 max(y)*1.1]);
810                title('Courbe de cyclage');
811                grid on
812            end
813            hold on
814        end
815        hold on
816    end
817end
818
819% --- Executes on button press in pushbutton_singledevice.
820function pushbutton_singledevice_Callback(hObject, eventdata, handles)
821% hObject    handle to pushbutton_singledevice (see GCBO)
822% eventdata  reserved - to be defined in a future version of MATLAB
823% handles    structure with handles and user data (see GUIDATA)
824
825
826function uibuttongroup_SelectionChangeFcn(hObject,eventdata,handles)
827% hObject    handle to uipanel1 (see GCBO)
828% eventdata  reserved - to be defined in a future version of MATLAB
829% handles    structure with handles and user data (see GUIDATA)
830
831switch get(get(hObject,'SelectedObject'),'Tag')  % Get Tag of selected object
832    case 'radiobutton1'
833        % code piece when radiobutton1 is selected goes here
834        % 'Mode' = 'Simulation';
835        handles.mode = '1element';
836       
837    case 'radiobutton2'
838        % code piece when radiobutton_configS11 is selected goes here
839        % '.Mode' = 'Machine';
840        handles.mode = 'lafamille';
841end
842% Update handles structure
843guidata(hObject, handles);
844
845
846% --- Executes on button press in checkbox_noneQuad.
847function checkbox_noneQuad_Callback(hObject, eventdata, handles)
848% hObject    handle to checkbox_noneQuad (see GCBO)
849% eventdata  reserved - to be defined in a future version of MATLAB
850% handles    structure with handles and user data (see GUIDATA)
851
852% Hint: get(hObject,'Value') returns toggle state of checkbox_noneQuad
853
854set(handles.checkbox_all,'Value',0);
855set(handles.checkbox_none,'Value',0);
856val = get(handles.checkbox_noneQuad,'Value');
857
858if val
859    set(handles.checkbox_AllQuad,'Value',0);
860    for k = 1:(length(findmemberof('QUAD'))-2)
861        Name = strcat('QP',num2str(k));
862        set(handles.(['checkbox_',Name]),'Enable','on')
863        set(handles.(['checkbox_',Name]),'Value',0)
864    end
865       set(handles.(['checkbox_','QP31']),'Enable','on')
866        set(handles.(['checkbox_','QP31']),'Value',0)
867        set(handles.(['checkbox_','QP41']),'Enable','on')
868        set(handles.(['checkbox_','QP41']),'Value',0)
869   
870    % rendre possible la montee des dipoles et sextus
871    for k = 1:length(findmemberof('SEXT'))
872        Name = strcat('SX',num2str(k));
873        set(handles.(['checkbox_',Name]),'Enable','on')
874    end
875    set(handles.checkbox_AllSextu,'Enable','on');
876    set(handles.checkbox_BEND,'Enable','on');
877end
878
879
880% --- Executes on button press in checkbox_NoneSextu.
881function checkbox_NoneSextu_Callback(hObject, eventdata, handles)
882% hObject    handle to checkbox_NoneSextu (see GCBO)
883% eventdata  reserved - to be defined in a future version of MATLAB
884% handles    structure with handles and user data (see GUIDATA)
885
886% Hint: get(hObject,'Value') returns toggle state of checkbox_NoneSextu
887
888set(handles.checkbox_all,'Value',0);
889set(handles.checkbox_none,'Value',0);
890val = get(handles.checkbox_NoneSextu,'Value');
891
892if val
893    set(handles.checkbox_AllSextu,'Value',0);   
894    for k = 1:length(findmemberof('SEXT'))
895        Name = strcat('SX',num2str(k));
896        set(handles.(['checkbox_',Name]),'Enable','on')
897        set(handles.(['checkbox_',Name]),'Value',0)
898    end
899
900    % Enable cycling of quads abd dipole
901    for k = 1:(length(findmemberof('QUAD'))-2)
902        Name = strcat('QP',num2str(k));
903        set(handles.(['checkbox_',Name]),'Enable','on')
904    end
905    set(handles.(['checkbox_','QP31']),'Enable','on')
906    set(handles.(['checkbox_','QP41']),'Enable','on')
907   
908    set(handles.checkbox_AllQuad,'Enable','on');
909    set(handles.checkbox_BEND,'Enable','on');
910end
911
912% --- Executes on button press in pushbutton_CyclingStatus.
913function pushbutton_CyclingStatus_Callback(hObject, eventdata, handles)
914% hObject    handle to pushbutton_CyclingStatus (see GCBO)
915% eventdata  reserved - to be defined in a future version of MATLAB
916% handles    structure with handles and user data (see GUIDATA)
917
918Families={'BEND', 'HCOR', 'VCOR', ...
919    'QP1','QP2','QP3','QP4','QP31','QP41'...
920    'SX1','SX2','SX3'};   
921
922FamilyNumber = length(Families);
923
924totalProgression = zeros(1, FamilyNumber);
925
926for k1=1:FamilyNumber,
927    CycleFamily = ['Cycle' Families{k1}];
928    [CycleIndex, CycleAO] = isfamily(CycleFamily);   
929    totalProgression(k1) =  mean(tango_group_read_attribute2(CycleAO.GroupId,'totalProgression'));
930end
931%
932fprintf('\nCycling state, %s\n',datestr(now))
933for k1=1:FamilyNumber,
934    fprintf('Family %s, cycling state: %03.0f %%\t', Families{k1}, totalProgression(k1))
935    if k1~=1 && mod(k1+1,2) ,
936        fprintf('\n')
937    end
938end
939
940
941
942% --- Executes during object creation, after setting all properties.
943function popupmenu_singledevice_CreateFcn(hObject, eventdata, handles)
944% hObject    handle to popupmenu_singledevice (see GCBO)
945% eventdata  reserved - to be defined in a future version of MATLAB
946% handles    empty - handles not created until after all CreateFcns called
947
948% Hint: popupmenu controls usually have a white background on Windows.
949%       See ISPC and COMPUTER.
950if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
951    set(hObject,'BackgroundColor','white');
952end
953
954set(hObject, 'String', family2tangodev('Qall'));
955
956
957% --- Executes on button press in pushbutton_FFWD_ON.
958function pushbutton_FFWD_ON_Callback(hObject, eventdata, handles)
959% hObject    handle to pushbutton_FFWD_ON (see GCBO)
960% eventdata  reserved - to be defined in a future version of MATLAB
961% handles    structure with handles and user data (see GUIDATA)
962writeattribute('ans/ei/nuffwd/booleanResult', uint8(1));
963pushbutton_FFWDStatus_Callback(hObject, eventdata, handles);
964
965% --- Executes on button press in pushbutton_FFWD_OFF.
966function pushbutton_FFWD_OFF_Callback(hObject, eventdata, handles)
967% hObject    handle to pushbutton_FFWD_OFF (see GCBO)
968% eventdata  reserved - to be defined in a future version of MATLAB
969% handles    structure with handles and user data (see GUIDATA)
970writeattribute('ans/ei/nuffwd/booleanResult', uint8(0));
971pushbutton_FFWDStatus_Callback(hObject, eventdata, handles);
972
973% --- Executes on button press in pushbutton_FFWDStatus.
974function pushbutton_FFWDStatus_Callback(hObject, eventdata, handles)
975% hObject    handle to pushbutton_FFWDStatus (see GCBO)
976% eventdata  reserved - to be defined in a future version of MATLAB
977% handles    structure with handles and user data (see GUIDATA)
978set(handles.checkbox_FFWD_STATUS, 'Enable', 'Off');
979pause(3)
980FFWDFlag = readattribute('ans/ei/nuffwd/booleanResult');
981% any(getpv({'Q1','Q2', 'Q3', 'Q4', 'Q5', ...
982%     'Q6','Q7', 'Q8', 'Q9', 'Q10'}, 'SumOffset') ~= 0)
983set(handles.checkbox_FFWD_STATUS, 'Value', FFWDFlag);
984set(handles.checkbox_FFWD_STATUS, 'Enable', 'On');
985
986
987% --- Executes on button press in pushbutton_offset2zero.
988function pushbutton_offset2zero_Callback(hObject, eventdata, handles)
989% hObject    handle to pushbutton_offset2zero (see GCBO)
990% eventdata  reserved - to be defined in a future version of MATLAB
991% handles    structure with handles and user data (see GUIDATA)
992
993Answer = questdlg('Forcing Offsets of quadrupole magnets to zero (no: cancel)', 'Confirmation box','Yes','No','No');
994if strcmpi(Answer, 'No')
995    %
996else
997    setquadoffset2zero
998end
999       
1000% --- Executes on button press in pushbutton_plotoffset.
1001function pushbutton_plotoffset_Callback(hObject, eventdata, handles)
1002% hObject    handle to pushbutton_plotoffset (see GCBO)
1003% eventdata  reserved - to be defined in a future version of MATLAB
1004% handles    structure with handles and user data (see GUIDATA)
1005
1006plotquad('Offset1','NoMean')
1007
1008% --- Executes on button press in pushbutton_plotcurrentPM.
1009function pushbutton_plotcurrentPM_Callback(hObject, eventdata, handles)
1010% hObject    handle to pushbutton_plotcurrentPM (see GCBO)
1011% eventdata  reserved - to be defined in a future version of MATLAB
1012% handles    structure with handles and user data (see GUIDATA)
1013
1014plotquad('Setpoint','NoMean')
1015
1016
1017% --- Executes on button press in pushbutton_current.
1018function pushbutton_current_Callback(hObject, eventdata, handles)
1019% hObject    handle to pushbutton_current (see GCBO)
1020% eventdata  reserved - to be defined in a future version of MATLAB
1021% handles    structure with handles and user data (see GUIDATA)
1022
1023plotquad('Mean')
1024plotquad('NoMean')
1025
1026
1027% --- Executes when selected object is changed in uipanel_gestionConfig.
1028function uipanel_gestionConfig_SelectionChangeFcn(hObject, eventdata, handles)
1029% hObject    handle to the selected object in uipanel_gestionConfig
1030% eventdata  structure with the following fields (see UIBUTTONGROUP)
1031%       EventName: string 'SelectionChanged' (read only)
1032%       OldValue: handle of the previously selected object or empty if none was selected
1033%       NewValue: handle of the currently selected object
1034% handles    structure with handles and user data (see GUIDATA)
1035
1036switch get(hObject,'Tag')  % Get Tag of selected object
1037    case 'radiobutton_confignominal'
1038        % code piece when radiobutton1 is selected goes here
1039        handles.configmode = 'confignominal';
1040       
1041end
1042% Update handles structure
1043guidata(hObject, handles);
Note: See TracBrowser for help on using the repository browser.