1 | function res = idSetCorCurSync(idName, curToSetCHE, curToSetCVE, curToSetCHS, curToSetCVS, curAbsTol) |
---|
2 | |
---|
3 | res = 0; |
---|
4 | DServName = ''; |
---|
5 | attr_name_list = {'', '', '', ''}; |
---|
6 | |
---|
7 | numLoopsWaitRes = 20; |
---|
8 | sleepTime = 1; %[s] |
---|
9 | |
---|
10 | %idDevServCor01 = ''; |
---|
11 | %idDevServCor02 = ''; |
---|
12 | %idDevServCor03 = ''; |
---|
13 | %idDevServCor04 = ''; |
---|
14 | curCh01 = 0; |
---|
15 | curCh02 = 0; |
---|
16 | curCh03 = 0; |
---|
17 | curCh04 = 0; |
---|
18 | |
---|
19 | [DServName, StandByStr] = idGetUndDServer(idName); |
---|
20 | |
---|
21 | if strncmp(idName, 'HU80', 4) || strncmp(idName, 'HU52', 4) || strncmp(idName, 'HU44', 4) || strncmp(idName, 'HU60', 4)|| strncmp(idName, 'HU36', 4)|| strncmp(idName, 'HU42', 4)|| strncmp(idName, 'HU64', 4) |
---|
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 | |
---|
45 | |
---|
46 | attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE; %curCh01; %curToSetCHE; |
---|
47 | attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE; %curCh02; %curToSetCVE; |
---|
48 | attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS; %curCh03; %curToSetCHS; |
---|
49 | attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS; %curCh04; %curToSetCVS; |
---|
50 | |
---|
51 | %if strcmp(idName, 'HU80_TEMPO') |
---|
52 | % DServName = 'ANS-C08/EI/M-HU80.2'; %Name of Level 2 DServer |
---|
53 | % attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE; |
---|
54 | % attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE; |
---|
55 | % attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS; |
---|
56 | % attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS; |
---|
57 | %elseif strcmp(idName, 'HU80_PLEIADES') |
---|
58 | % DServName = 'ANS-C04/EI/M-HU80.1'; %Name of Level 2 DServer |
---|
59 | % attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE; |
---|
60 | % attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE; |
---|
61 | % attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS; |
---|
62 | % attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS; |
---|
63 | %elseif strcmp(idName, 'HU80_CASSIOPEE') |
---|
64 | % DServName = 'ANS-C04/EI/M-HU80.1'; %Name of Level 2 DServer |
---|
65 | % attr_name_val_list(1).name = 'currentCHE'; attr_name_val_list(1).value = curToSetCHE; |
---|
66 | % attr_name_val_list(2).name = 'currentCVE'; attr_name_val_list(2).value = curToSetCVE; |
---|
67 | % attr_name_val_list(3).name = 'currentCHS'; attr_name_val_list(3).value = curToSetCHS; |
---|
68 | % attr_name_val_list(4).name = 'currentCVS'; attr_name_val_list(4).value = curToSetCVS; |
---|
69 | %end |
---|
70 | |
---|
71 | 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}; |
---|
72 | end |
---|
73 | |
---|
74 | %for i = 1:4 |
---|
75 | % attr_name_list(i) = attr_name_val_list(i).name; |
---|
76 | %end |
---|
77 | |
---|
78 | if strcmp(DServName, '') ~= 0 |
---|
79 | fprintf('Device Server name is not specified\n'); |
---|
80 | res = -1; |
---|
81 | return; |
---|
82 | end |
---|
83 | |
---|
84 | % tango_write_attributes(DServName, attr_name_val_list); |
---|
85 | for i=1:4 |
---|
86 | % i=1; |
---|
87 | FullAttribute=[DServName '/' attr_name_val_list(i).name]; |
---|
88 | Value=attr_name_val_list(i).value; |
---|
89 | writeattribute(FullAttribute,Value) |
---|
90 | pause(1.5); %% Modified on 05/03/2011 : without it, sepoint is got, but current dosen't move! FB & MV |
---|
91 | end |
---|
92 | |
---|
93 | if (tango_error == -1) %handle error |
---|
94 | tango_print_error_stack; return; |
---|
95 | end |
---|
96 | |
---|
97 | %Waiting until the current values are set |
---|
98 | for i = 1:numLoopsWaitRes |
---|
99 | attr_val_list = tango_read_attributes(DServName, attr_name_list); |
---|
100 | if (tango_error == -1) %handle error |
---|
101 | tango_print_error_stack; return; |
---|
102 | end |
---|
103 | |
---|
104 | canQuit = 1; |
---|
105 | for j = 1:4 |
---|
106 | valRequested = attr_name_val_list(j).value; |
---|
107 | valSet = attr_val_list(j).value(1); %check why (1) |
---|
108 | %if(abs(attr_name_val_list(j).value - attr_val_list(j)) > curAbsTol) |
---|
109 | if(abs(valRequested - valSet) > curAbsTol) |
---|
110 | canQuit = 0; break; |
---|
111 | end |
---|
112 | end |
---|
113 | |
---|
114 | if(canQuit == 1) |
---|
115 | return; %Normal exit |
---|
116 | end |
---|
117 | pause(sleepTime); |
---|
118 | end |
---|
119 | |
---|
120 | res = -1; |
---|
121 | fprintf('Failed to set requested current values\n'); |
---|