source: MML/trunk/machine/SOLEIL/StorageRing/insertions/IDStarter/idSetCorCurSync.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: 4.1 KB
Line 
1function res = idSetCorCurSync(idName, curToSetCHE, curToSetCVE, curToSetCHS, curToSetCVS, curAbsTol)
2
3res = 0;
4DServName = '';
5attr_name_list = {'', '', '', ''};
6
7numLoopsWaitRes = 20;
8sleepTime = 1; %[s]
9
10%idDevServCor01 = '';
11%idDevServCor02 = '';
12%idDevServCor03 = '';
13%idDevServCor04 = '';
14curCh01 = 0;
15curCh02 = 0;
16curCh03 = 0;
17curCh04 = 0;
18
19[DServName, StandByStr] = idGetUndDServer(idName);
20
21if strncmp(idName, 'HU80', 3)
22   
23%First call after turning on the correctors should be: idSetCorCurSync('HU80_TEMPO', 0., 0.1, 0, 0.1, 0.001)
24
25%Names of Level 1 DServers of coils (no longer used)
26        %idDevServCor01 = 'ans-c08/ei/m-hu80.2_chan1';
27        %idDevServCor02 = 'ans-c08/ei/m-hu80.2_chan2';
28        %idDevServCor03 = 'ans-c08/ei/m-hu80.2_chan3';
29        %idDevServCor04 = 'ans-c08/ei/m-hu80.2_chan4';
30   
31%Formulae used for the Virtual Correctors:
32        curCh01 = 0.5*(-curToSetCVE - curToSetCHE);
33        curCh02 = 0.5*(-curToSetCVE + curToSetCHE);
34        curCh03 = 0.5*(-curToSetCVS - curToSetCHS);
35        curCh04 = 0.5*(-curToSetCVS + curToSetCHS);
36   
37    fprintf('Expected current values in primary channels: #1: %f, #2: %f, #3: %f, #4: %f\n', curCh01, curCh02, curCh03, curCh04);
38
39    attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE;
40    attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE;
41    attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS;
42    attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS;   
43   
44    %if strcmp(idName, 'HU80_TEMPO')
45    %    DServName = 'ANS-C08/EI/M-HU80.2'; %Name of Level 2 DServer
46    %    attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE;
47    %    attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE;
48    %    attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS;
49    %    attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS;
50    %elseif strcmp(idName, 'HU80_PLEIADES')
51    %    DServName = 'ANS-C04/EI/M-HU80.1'; %Name of Level 2 DServer
52    %    attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE;
53    %    attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE;
54    %    attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS;
55    %    attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS;
56    %elseif strcmp(idName, 'HU80_CASSIOPEE')
57    %    DServName = 'ANS-C04/EI/M-HU80.1'; %Name of Level 2 DServer
58    %    attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE;
59    %    attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE;
60    %    attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS;
61    %    attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS;       
62    %end
63   
64    attr_name_list = {attr_name_val_list(1).name, attr_name_val_list(2).name, attr_name_val_list(3).name, attr_name_val_list(4).name};
65end
66
67%for i = 1:4
68%    attr_name_list(i) = attr_name_val_list(i).name;
69%end
70
71if strcmp(DServName, '') ~= 0
72    fprintf('Device Server name is not specified\n');
73    res = -1;
74    return;
75end
76
77tango_write_attributes(DServName, attr_name_val_list);
78if (tango_error == -1) %handle error
79    tango_print_error_stack; return;
80end
81
82%Waiting until the current values are set
83for i = 1:numLoopsWaitRes
84    attr_val_list = tango_read_attributes(DServName, attr_name_list);
85    if (tango_error == -1) %handle error
86        tango_print_error_stack; return;
87    end
88
89    canQuit = 1;
90    for j = 1:4
91        valRequested = attr_name_val_list(j).value;
92        valSet = attr_val_list(j).value(1); %check why (1)
93        %if(abs(attr_name_val_list(j).value - attr_val_list(j)) > curAbsTol)
94        if(abs(valRequested - valSet) > curAbsTol)
95            canQuit = 0; break;
96        end
97    end
98   
99    if(canQuit == 1)
100        return; %Normal exit
101    end
102    pause(sleepTime);
103end
104
105res = -1;
106fprintf('Failed to set requested current values\n');
Note: See TracBrowser for help on using the repository browser.