PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/FlightSim/trustedApps/bpmcal/bpmcal.m

http://atf2flightsim.googlecode.com/
MATLAB | 894 lines | 530 code | 121 blank | 243 comment | 80 complexity | aad898dea9b27c41cf08005f56f66dde MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = bpmcal(varargin)
  2. % BPMCAL M-file for bpmcal.fig
  3. % BPMCAL, by itself, creates a new BPMCAL or raises the existing
  4. % singleton*.
  5. %
  6. % H = BPMCAL returns the handle to a new BPMCAL or the handle to
  7. % the existing singleton*.
  8. %
  9. % BPMCAL('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in BPMCAL.M with the given input arguments.
  11. %
  12. % BPMCAL('Property','Value',...) creates a new BPMCAL or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before bpmcal_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to bpmcal_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: GUIDE, GUIDATA, GUIHANDLES
  22. % Edit the above text to modify the response to help bpmcal
  23. % Last Modified by GUIDE v2.5 14-Nov-2010 11:57:10
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @bpmcal_OpeningFcn, ...
  29. 'gui_OutputFcn', @bpmcal_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before bpmcal is made visible.
  42. function bpmcal_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to bpmcal (see VARARGIN)
  48. global FL
  49. % Choose default command line output for bpmcal
  50. handles.output = handles;
  51. % Update handles structure
  52. guidata(hObject, handles);
  53. % Initialise cav cal routine
  54. mh=msgbox('Initialising Bump Routines...');
  55. nmCavCal('init');
  56. % Set BPM names
  57. [stat pars] = nmCavCal('GetPars');
  58. if stat{1}~=1; errordlg(stat{2},'Error getting pars'); return; end;
  59. set(handles.popupmenu1,'String',pars.bpmnames);
  60. set(handles.popupmenu1,'Value',1);
  61. popupmenu1_Callback(handles.popupmenu1,[],handles);
  62. % Setup and start update timer
  63. FL.t_bpmcal=timer('TimerFcn',['bpmcal(''pushbutton12_Callback'',',num2str(handles.pushbutton12,20),',[],',...
  64. '[])'],'ExecutionMode','fixedDelay','Period',1,'StartDelay',2);
  65. start(FL.t_bpmcal);
  66. if ishandle(mh); delete(mh); end;
  67. % --- Outputs from this function are returned to the command line.
  68. function varargout = bpmcal_OutputFcn(hObject, eventdata, handles) %#ok<*INUSL>
  69. % varargout cell array for returning output args (see VARARGOUT);
  70. % hObject handle to figure
  71. % eventdata reserved - to be defined in a future version of MATLAB
  72. % handles structure with handles and user data (see GUIDATA)
  73. % Get default command line output from handles structure
  74. varargout{1} = handles.output;
  75. % --- EXIT
  76. function pushbutton1_Callback(hObject, eventdata, handles)
  77. % hObject handle to pushbutton1 (see GCBO)
  78. % eventdata reserved - to be defined in a future version of MATLAB
  79. % handles structure with handles and user data (see GUIDATA)
  80. global FL
  81. stop(FL.t_bpmcal);
  82. guiCloseFn('bpmcal',handles);
  83. % --- Calibrate x
  84. function pushbutton2_Callback(hObject, eventdata, handles)
  85. % hObject handle to pushbutton2 (see GCBO)
  86. % eventdata reserved - to be defined in a future version of MATLAB
  87. % handles structure with handles and user data (see GUIDATA)
  88. if ~strcmp(questdlg('Start calibration procedure (x)?'),'Yes')
  89. return
  90. end
  91. bpmnames=get(handles.popupmenu1,'String');
  92. ibpm=get(handles.popupmenu1,'Value');
  93. bpmname=bpmnames{ibpm};
  94. stat = nmCavCal('CalibBump',bpmname,'x');
  95. if stat{1}~=1
  96. errordlg(stat{2},'Calibration error')
  97. end
  98. popupmenu1_Callback(handles.popupmenu1,[],handles);
  99. % --- Calibrate y
  100. function pushbutton3_Callback(hObject, eventdata, handles)
  101. % hObject handle to pushbutton3 (see GCBO)
  102. % eventdata reserved - to be defined in a future version of MATLAB
  103. % handles structure with handles and user data (see GUIDATA)
  104. global FL
  105. if ~strcmp(questdlg('Start calibration procedure (y)?'),'Yes')
  106. return
  107. end
  108. bpmnames=get(handles.popupmenu1,'String');
  109. ibpm=get(handles.popupmenu1,'Value');
  110. bpmname=bpmnames{ibpm};
  111. FL.Gui.bpmcal_msg=msgbox('Calibration in progress (y)...','Bump Calibration','modal');
  112. stat = nmCavCal('CalibBump',bpmname,'y');
  113. if stat{1}~=1
  114. errordlg(stat{2},'Calibration error')
  115. end
  116. if ishandle(FL.Gui.bpmcal_msg)
  117. delete(FL.Gui.bpmcal_msg)
  118. end
  119. popupmenu1_Callback(handles.popupmenu1,[],handles);
  120. % Restore all bumps
  121. function pushbutton4_Callback(hObject, eventdata, handles)
  122. % hObject handle to pushbutton4 (see GCBO)
  123. % eventdata reserved - to be defined in a future version of MATLAB
  124. % handles structure with handles and user data (see GUIDATA)
  125. if ~strcmp(questdlg('Restore all bumps to their zero position?'),'Yes')
  126. return
  127. end
  128. stat = nmCavCal('RestoreBumps');
  129. if stat{1}~=1
  130. errordlg(stat{2},'Bump Restore error')
  131. end
  132. popupmenu1_Callback(handles.popupmenu1,[],handles);
  133. % --- Reset all bumps
  134. function pushbutton5_Callback(hObject, eventdata, handles)
  135. % hObject handle to pushbutton5 (see GCBO)
  136. % eventdata reserved - to be defined in a future version of MATLAB
  137. % handles structure with handles and user data (see GUIDATA)
  138. if ~strcmp(questdlg('Reset zero position on all bumps?'),'Yes')
  139. return
  140. end
  141. stat = nmCavCal('ResetBumps');
  142. if stat{1}~=1
  143. errordlg(stat{2},'Bump Reset error')
  144. end
  145. popupmenu1_Callback(handles.popupmenu1,[],handles);
  146. % --- set x bump
  147. function pushbutton6_Callback(hObject, eventdata, handles)
  148. % hObject handle to pushbutton6 (see GCBO)
  149. % eventdata reserved - to be defined in a future version of MATLAB
  150. % handles structure with handles and user data (see GUIDATA)
  151. bpmnames=get(handles.popupmenu1,'String');
  152. ibpm=get(handles.popupmenu1,'Value');
  153. bpmname=bpmnames{ibpm};
  154. FlHwUpdate; % update setpt values
  155. stat = nmCavCal('SetBump',bpmname,'x',str2double(get(handles.edit1,'String'))*1e-3,...
  156. ~get(handles.checkbox1,'Value'));
  157. if stat{1}~=1
  158. errordlg(stat{2},'Bump Set Error')
  159. end
  160. [stat pars]=nmCavCal('GetPars');
  161. if stat{1}==1
  162. set(handles.text2,'String',num2str(pars.bumpknob.x{ibpm}.Value*1e3,5))
  163. end
  164. % --- Set y bump
  165. function pushbutton7_Callback(hObject, eventdata, handles) %#ok<*INUSD,*DEFNU>
  166. % hObject handle to pushbutton7 (see GCBO)
  167. % eventdata reserved - to be defined in a future version of MATLAB
  168. % handles structure with handles and user data (see GUIDATA)
  169. bpmnames=get(handles.popupmenu1,'String');
  170. ibpm=get(handles.popupmenu1,'Value');
  171. bpmname=bpmnames{ibpm};
  172. FlHwUpdate; % update setpt values
  173. stat = nmCavCal('SetBump',bpmname,'y',str2double(get(handles.edit2,'String'))*1e-3,...
  174. ~get(handles.checkbox1,'Value'));
  175. if stat{1}~=1
  176. errordlg(stat{2},'Bump Set Error')
  177. end
  178. [stat pars]=nmCavCal('GetPars');
  179. if stat{1}==1
  180. set(handles.text3,'String',num2str(pars.bumpknob.y{ibpm}.Value*1e3,5))
  181. end
  182. % --- BPM select
  183. function popupmenu1_Callback(hObject, eventdata, handles)
  184. % hObject handle to popupmenu1 (see GCBO)
  185. % eventdata reserved - to be defined in a future version of MATLAB
  186. % handles structure with handles and user data (see GUIDATA)
  187. ibpm=get(hObject,'Value');
  188. [stat, pars]=nmCavCal('GetPars');
  189. bpmname=pars.bpmnames{ibpm};
  190. if stat{1}~=1; errordlg(stat{2},'Error getting pars'); return; end;
  191. set(handles.text2,'String',num2str(pars.bumpknob.x{ibpm}.Value*1e3,3))
  192. set(handles.text3,'String',num2str(pars.bumpknob.y{ibpm}.Value*1e3,3))
  193. set(handles.text39,'String',num2str(pars.bumpknob.xp{ibpm}.Value*1e3,3))
  194. set(handles.text40,'String',num2str(pars.bumpknob.yp{ibpm}.Value*1e3,3))
  195. set(handles.edit1,'String',num2str(pars.bumpknob.x{ibpm}.Value*1e3,3))
  196. set(handles.edit2,'String',num2str(pars.bumpknob.y{ibpm}.Value*1e3,3))
  197. set(handles.edit6,'String',num2str(pars.bumpknob.xp{ibpm}.Value*1e3,3))
  198. set(handles.edit7,'String',num2str(pars.bumpknob.yp{ibpm}.Value*1e3,3))
  199. set(handles.pushbutton8,'Visible','off')
  200. set(handles.pushbutton9,'Visible','off')
  201. set(handles.pushbutton10,'Visible','off')
  202. set(handles.pushbutton11,'Visible','off')
  203. if isfield(pars.bumpcalib,bpmname) && isfield(pars.bumpcalib.(bpmname),'xdate')
  204. set(handles.text4,'String',datestr(pars.bumpcalib.(bpmname).xdate))
  205. else
  206. set(handles.text4,'String','None')
  207. end
  208. if isfield(pars.bumpcalib,bpmname) && isfield(pars.bumpcalib.(bpmname),'ydate')
  209. set(handles.text5,'String',datestr(pars.bumpcalib.(bpmname).ydate))
  210. else
  211. set(handles.text5,'String','None')
  212. end
  213. set(handles.edit3,'String',num2str(pars.bumpcalib.size*1e3,5))
  214. set(handles.edit4,'String',num2str(pars.bumpcalib.nstep))
  215. set(handles.edit5,'String',num2str(pars.bumpcalib.nbpm))
  216. uiresume(handles.figure1)
  217. if get(handles.radiobutton5,'Value')
  218. wx='x';
  219. elseif get(handles.radiobutton8,'Value')
  220. wx='xp';
  221. elseif get(handles.radiobutton6,'Value')
  222. wx='y';
  223. elseif get(handles.radiobutton9,'Value')
  224. wx='yp';
  225. end
  226. set(handles.text7,'String',pars.cornames.(wx(1)){ibpm}{1});
  227. set(handles.text8,'String',pars.cornames.(wx(1)){ibpm}{2});
  228. set(handles.text9,'String',pars.cornames.(wx(1)){ibpm}{3});
  229. if length(pars.cornames.(wx(1)){ibpm})==4
  230. set(handles.text10,'String',pars.cornames.(wx(1)){ibpm}{4});
  231. else
  232. set(handles.text10,'String','---')
  233. end
  234. drawnow('expose');
  235. % Calibration dates
  236. if strcmp(pars.bpmtype(ibpm),'stripline')
  237. try
  238. [data ts]=lcaGet([bpmname ':SCALE_X']);
  239. set(handles.text37,datestr(epicsts2mat(ts)))
  240. catch
  241. set(handles.text37,'String','---')
  242. end
  243. try
  244. [data ts]=lcaGet([bpmname ':SCALE_Y']);
  245. set(handles.text38,datestr(epicsts2mat(ts)))
  246. catch
  247. set(handles.text38,'String','---')
  248. end
  249. else
  250. set(handles.text37,'String','---')
  251. set(handles.text38,'String','---')
  252. end
  253. % --- Executes during object creation, after setting all properties.
  254. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  255. % hObject handle to popupmenu1 (see GCBO)
  256. % eventdata reserved - to be defined in a future version of MATLAB
  257. % handles empty - handles not created until after all CreateFcns called
  258. % Hint: popupmenu controls usually have a white background on Windows.
  259. % See ISPC and COMPUTER.
  260. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  261. set(hObject,'BackgroundColor','white');
  262. end
  263. function edit1_Callback(hObject, eventdata, handles)
  264. % hObject handle to edit1 (see GCBO)
  265. % eventdata reserved - to be defined in a future version of MATLAB
  266. % handles structure with handles and user data (see GUIDATA)
  267. set(handles.radiobutton5,'Value',1)
  268. set(handles.radiobutton8,'Value',0)
  269. set(handles.radiobutton6,'Value',0)
  270. set(handles.radiobutton9,'Value',0)
  271. % --- Executes during object creation, after setting all properties.
  272. function edit1_CreateFcn(hObject, eventdata, handles)
  273. % hObject handle to edit1 (see GCBO)
  274. % eventdata reserved - to be defined in a future version of MATLAB
  275. % handles empty - handles not created until after all CreateFcns called
  276. % Hint: edit controls usually have a white background on Windows.
  277. % See ISPC and COMPUTER.
  278. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  279. set(hObject,'BackgroundColor','white');
  280. end
  281. function edit2_Callback(hObject, eventdata, handles)
  282. % hObject handle to edit2 (see GCBO)
  283. % eventdata reserved - to be defined in a future version of MATLAB
  284. % handles structure with handles and user data (see GUIDATA)
  285. set(handles.radiobutton5,'Value',0)
  286. set(handles.radiobutton8,'Value',0)
  287. set(handles.radiobutton6,'Value',1)
  288. set(handles.radiobutton9,'Value',0)
  289. % --- Executes during object creation, after setting all properties.
  290. function edit2_CreateFcn(hObject, eventdata, handles)
  291. % hObject handle to edit2 (see GCBO)
  292. % eventdata reserved - to be defined in a future version of MATLAB
  293. % handles empty - handles not created until after all CreateFcns called
  294. % Hint: edit controls usually have a white background on Windows.
  295. % See ISPC and COMPUTER.
  296. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  297. set(hObject,'BackgroundColor','white');
  298. end
  299. % --- Executes on button press in pushbutton8.
  300. function pushbutton8_Callback(hObject, eventdata, handles)
  301. % hObject handle to pushbutton8 (see GCBO)
  302. % eventdata reserved - to be defined in a future version of MATLAB
  303. % handles structure with handles and user data (see GUIDATA)
  304. uiresume(handles.figure1)
  305. popupmenu1_Callback(handles.popupmenu1,[],handles);
  306. % --- Executes on button press in pushbutton9.
  307. function pushbutton9_Callback(hObject, eventdata, handles)
  308. % hObject handle to pushbutton9 (see GCBO)
  309. % eventdata reserved - to be defined in a future version of MATLAB
  310. % handles structure with handles and user data (see GUIDATA)
  311. uiresume(handles.figure1)
  312. popupmenu1_Callback(handles.popupmenu1,[],handles);
  313. % --- Executes on button press in pushbutton10.
  314. function pushbutton10_Callback(hObject, eventdata, handles)
  315. % hObject handle to pushbutton10 (see GCBO)
  316. % eventdata reserved - to be defined in a future version of MATLAB
  317. % handles structure with handles and user data (see GUIDATA)
  318. uiresume(handles.figure1)
  319. popupmenu1_Callback(handles.popupmenu1,[],handles);
  320. % --- Executes on button press in pushbutton11.
  321. function pushbutton11_Callback(hObject, eventdata, handles)
  322. % hObject handle to pushbutton11 (see GCBO)
  323. % eventdata reserved - to be defined in a future version of MATLAB
  324. % handles structure with handles and user data (see GUIDATA)
  325. uiresume(handles.figure1)
  326. popupmenu1_Callback(handles.popupmenu1,[],handles);
  327. % bump range
  328. function edit3_Callback(hObject, eventdata, handles)
  329. % hObject handle to edit3 (see GCBO)
  330. % eventdata reserved - to be defined in a future version of MATLAB
  331. % handles structure with handles and user data (see GUIDATA)
  332. newpars.bumpcalib.size=str2double(get(hObject,'String'))*1e-3;
  333. nmCavCal('SetPars',newpars);
  334. [stat pars]=nmCavCal('GetPars');
  335. set(hObject,'String',num2str(pars.bumpcalib.size*1e3,4));
  336. % --- Executes during object creation, after setting all properties.
  337. function edit3_CreateFcn(hObject, eventdata, handles)
  338. % hObject handle to edit3 (see GCBO)
  339. % eventdata reserved - to be defined in a future version of MATLAB
  340. % handles empty - handles not created until after all CreateFcns called
  341. % Hint: edit controls usually have a white background on Windows.
  342. % See ISPC and COMPUTER.
  343. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  344. set(hObject,'BackgroundColor','white');
  345. end
  346. % nsteps for bump calib
  347. function edit4_Callback(hObject, eventdata, handles)
  348. % hObject handle to edit4 (see GCBO)
  349. % eventdata reserved - to be defined in a future version of MATLAB
  350. % handles structure with handles and user data (see GUIDATA)
  351. newpars.bumpcalib.nstep=str2double(get(hObject,'String'));
  352. nmCavCal('SetPars',newpars);
  353. [stat pars]=nmCavCal('GetPars');
  354. set(hObject,'String',num2str(pars.bumpcalib.nstep));
  355. % --- Executes during object creation, after setting all properties.
  356. function edit4_CreateFcn(hObject, eventdata, handles)
  357. % hObject handle to edit4 (see GCBO)
  358. % eventdata reserved - to be defined in a future version of MATLAB
  359. % handles empty - handles not created until after all CreateFcns called
  360. % Hint: edit controls usually have a white background on Windows.
  361. % See ISPC and COMPUTER.
  362. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  363. set(hObject,'BackgroundColor','white');
  364. end
  365. % --- Executes on button press in checkbox1.
  366. function checkbox1_Callback(hObject, eventdata, handles)
  367. % hObject handle to checkbox1 (see GCBO)
  368. % eventdata reserved - to be defined in a future version of MATLAB
  369. % handles structure with handles and user data (see GUIDATA)
  370. % Hint: get(hObject,'Value') returns toggle state of checkbox1
  371. % --- Executes when user attempts to close figure1.
  372. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  373. % hObject handle to figure1 (see GCBO)
  374. % eventdata reserved - to be defined in a future version of MATLAB
  375. % handles structure with handles and user data (see GUIDATA)
  376. global FL
  377. stop(FL.t_bpmcal);
  378. guiCloseFn('bpmcal',handles);
  379. % Nave
  380. function edit5_Callback(hObject, eventdata, handles)
  381. % hObject handle to edit5 (see GCBO)
  382. % eventdata reserved - to be defined in a future version of MATLAB
  383. % handles structure with handles and user data (see GUIDATA)
  384. newpars.bumpcalib.nbpm=str2double(get(hObject,'String'));
  385. nmCavCal('SetPars',newpars);
  386. % --- Executes during object creation, after setting all properties.
  387. function edit5_CreateFcn(hObject, eventdata, handles)
  388. % hObject handle to edit5 (see GCBO)
  389. % eventdata reserved - to be defined in a future version of MATLAB
  390. % handles empty - handles not created until after all CreateFcns called
  391. % Hint: edit controls usually have a white background on Windows.
  392. % See ISPC and COMPUTER.
  393. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  394. set(hObject,'BackgroundColor','white');
  395. end
  396. % --- FS values
  397. function radiobutton3_Callback(hObject, eventdata, handles)
  398. % hObject handle to radiobutton3 (see GCBO)
  399. % eventdata reserved - to be defined in a future version of MATLAB
  400. % handles structure with handles and user data (see GUIDATA)
  401. if get(hObject,'Value')
  402. set(handles.radiobutton4,'Value',0)
  403. end
  404. % --- CS values
  405. function radiobutton4_Callback(hObject, eventdata, handles)
  406. % hObject handle to radiobutton4 (see GCBO)
  407. % eventdata reserved - to be defined in a future version of MATLAB
  408. % handles structure with handles and user data (see GUIDATA)
  409. if get(hObject,'Value')
  410. set(handles.radiobutton3,'Value',0)
  411. end
  412. % --- Horizontal bump readbacks
  413. function radiobutton5_Callback(hObject, eventdata, handles)
  414. % hObject handle to radiobutton5 (see GCBO)
  415. % eventdata reserved - to be defined in a future version of MATLAB
  416. % handles structure with handles and user data (see GUIDATA)
  417. if get(hObject,'Value')
  418. set(handles.radiobutton8,'Value',0)
  419. set(handles.radiobutton9,'Value',0)
  420. set(handles.radiobutton6,'Value',0)
  421. popupmenu1_Callback(handles.popupmenu1,[],handles);
  422. else
  423. set(hObject,'Value',1)
  424. end
  425. % --- Vertical bump readbacks
  426. function radiobutton6_Callback(hObject, eventdata, handles)
  427. % hObject handle to radiobutton6 (see GCBO)
  428. % eventdata reserved - to be defined in a future version of MATLAB
  429. % handles structure with handles and user data (see GUIDATA)
  430. if get(hObject,'Value')
  431. set(handles.radiobutton8,'Value',0)
  432. set(handles.radiobutton9,'Value',0)
  433. set(handles.radiobutton5,'Value',0)
  434. popupmenu1_Callback(handles.popupmenu1,[],handles);
  435. else
  436. set(hObject,'Value',1)
  437. end
  438. % --- Update script
  439. function pushbutton12_Callback(hObject, eventdata, handles)
  440. % hObject handle to pushbutton12 (see GCBO)
  441. % eventdata reserved - to be defined in a future version of MATLAB
  442. % handles structure with handles and user data (see GUIDATA)
  443. global FL BEAMLINE PS GIRDER %#ok<NUSED>
  444. if ~isfield(FL.Gui,'bpmcal')
  445. return
  446. end
  447. handles=FL.Gui.bpmcal;
  448. try
  449. [stat pars]=nmCavCal('GetPars');
  450. switch find([get(handles.radiobutton5,'Value') get(handles.radiobutton8,'Value') get(handles.radiobutton6,'Value') get(handles.radiobutton9,'Value') ])
  451. case 1
  452. plane='x';
  453. case 2
  454. plane='xp';
  455. case 3
  456. plane='y';
  457. case 4
  458. plane='yp';
  459. end
  460. % Get readback values
  461. ibpm=get(handles.popupmenu1,'Value');
  462. pl={'x' 'y' 'xp' 'yp'};
  463. % Init channel text with blanks
  464. for ihan=11:18
  465. set(handles.(['text',num2str(ihan)]),'String','---')
  466. end
  467. % Display corrector strengths
  468. sethans=[1 2 6 7];
  469. bumpsethans=[2 3 39 40];
  470. for iplane=1:4
  471. for ichan=1:min([length(pars.bumpknob.(pl{iplane}){ibpm}.Channel) 4])
  472. actparam=regexprep(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Parameter,'\.SetPt','\.Ampl');
  473. actparam=regexprep(actparam,'\.MoverSetPt','\.MoverPos');
  474. evalc(['crdes=' pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Parameter]);
  475. evalc(['cract=' actparam]);
  476. % adjust for new required move if not made yet
  477. if str2double(get(handles.(['edit' num2str(sethans(iplane))]),'String')) ~= str2double(get(handles.(['text' num2str(bumpsethans(iplane))]),'String'))
  478. crdes=crdes+1e-3*pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Coefficient*(str2double(get(handles.(['edit',num2str(sethans(iplane))]),'String'))-...
  479. str2double(get(handles.(['text',num2str(bumpsethans(iplane))]),'String')));
  480. end
  481. % Get bump readback
  482. if iplane==1
  483. bumprbk_x(ichan)=(cract-pars.bumpcomp.x{ibpm}(ichan))/pars.bumpknob.x{ibpm}.Channel(ichan).Coefficient;
  484. elseif iplane==2
  485. bumprbk_y(ichan)=(cract-pars.bumpcomp.y{ibpm}(ichan))/pars.bumpknob.y{ibpm}.Channel(ichan).Coefficient;
  486. elseif iplane==3
  487. bumprbk_xp(ichan)=(cract-pars.bumpcomp.xp{ibpm}(ichan))/pars.bumpknob.xp{ibpm}.Channel(ichan).Coefficient;
  488. else
  489. bumprbk_yp(ichan)=(cract-pars.bumpcomp.yp{ibpm}(ichan))/pars.bumpknob.yp{ibpm}.Channel(ichan).Coefficient;
  490. end
  491. % FS or control system values to display
  492. tval=1e-6; cdim=[1 2 1 2];
  493. if get(handles.radiobutton4,'Value')
  494. if ~isempty(strfind(actparam,'MoverPos'))
  495. tval=1e-6;
  496. crdes=crdes/...
  497. FL.HwInfo.GIRDER(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Unit).conv(cdim(iplane));
  498. cract=cract/...
  499. FL.HwInfo.GIRDER(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Unit).conv(cdim(iplane));
  500. else
  501. tval=0.01;
  502. conv=FL.HwInfo.PS(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Unit).conv;
  503. if length(conv)>1
  504. pvname=FL.HwInfo.PS(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Unit).pvname;
  505. if length(pvname{2})==2
  506. mainI=abs(lcaGet(pvname{1}{1},1));
  507. thetaMain=interp1(conv(1,:),conv(2,:),mainI,'linear');
  508. iMainPlusTrim=interp1(conv(2,:),conv(1,:),thetaMain+crdes,'linear');
  509. crdes=(iMainPlusTrim-mainI)/FL.HwInfo.PS(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Unit).nt_ratio;
  510. iMainPlusTrim=interp1(conv(2,:),conv(1,:),thetaMain+cract,'linear');
  511. cract=(iMainPlusTrim-mainI)/FL.HwInfo.PS(pars.bumpknob.(pl{iplane}){ibpm}.Channel(ichan).Unit).nt_ratio;
  512. else
  513. crdes=interp1(conv(2,:),conv(1,:),crdes,'linear');
  514. cract=interp1(conv(2,:),conv(1,:),cract,'linear');
  515. end
  516. else
  517. crdes=crdes/conv;
  518. cract=cract/conv;
  519. end
  520. end
  521. end
  522. if pl{iplane}==plane
  523. set(handles.(['text',num2str(10+ichan)]),'String',num2str(crdes,3))
  524. set(handles.(['text',num2str(14+ichan)]),'String',num2str(cract,3))
  525. if abs(abs(crdes-cract)/crdes) > 0.1 && cract > tval
  526. set(handles.(['text',num2str(14+ichan)]),'ForegroundColor','red')
  527. else
  528. set(handles.(['text',num2str(14+ichan)]),'ForegroundColor','black')
  529. end
  530. end
  531. end
  532. end
  533. if length(pars.bumpknob.(plane){ibpm}.Channel)==3
  534. set(handles.text14,'String','---')
  535. set(handles.text18,'String','---')
  536. end
  537. % Set bump readback
  538. set(handles.text2,'String',num2str(pars.bumpknob.x{ibpm}.Value*1e3,5))
  539. set(handles.text3,'String',num2str(pars.bumpknob.y{ibpm}.Value*1e3,5))
  540. set(handles.text39,'String',num2str(pars.bumpknob.xp{ibpm}.Value*1e3,5))
  541. set(handles.text40,'String',num2str(pars.bumpknob.yp{ibpm}.Value*1e3,5))
  542. set(handles.text33,'String',num2str(mean(bumprbk_x)*1e3,5))
  543. if abs(abs(str2double(get(handles.text2,'String'))-str2double(get(handles.text33,'String')))/str2double(get(handles.text2,'String'))) > 0.1 && ...
  544. abs(str2double(get(handles.text33,'String')))>0.001
  545. set(handles.text33,'ForegroundColor','red')
  546. else
  547. set(handles.text33,'ForegroundColor','black')
  548. end
  549. set(handles.text34,'String',num2str(mean(bumprbk_y)*1e3,5))
  550. if abs(abs(str2double(get(handles.text3,'String'))-str2double(get(handles.text34,'String')))/str2double(get(handles.text3,'String'))) > 0.1 && ...
  551. abs(str2double(get(handles.text34,'String')))>0.001
  552. set(handles.text34,'ForegroundColor','red')
  553. else
  554. set(handles.text34,'ForegroundColor','black')
  555. end
  556. set(handles.text41,'String',num2str(mean(bumprbk_xp)*1e3,5))
  557. if abs(abs(str2double(get(handles.text39,'String'))-str2double(get(handles.text41,'String')))/str2double(get(handles.text39,'String'))) > 0.1 && ...
  558. abs(str2double(get(handles.text41,'String')))>0.001
  559. set(handles.text41,'ForegroundColor','red')
  560. else
  561. set(handles.text41,'ForegroundColor','black')
  562. end
  563. set(handles.text42,'String',num2str(mean(bumprbk_yp)*1e3,5))
  564. if abs(abs(str2double(get(handles.text40,'String'))-str2double(get(handles.text42,'String')))/str2double(get(handles.text40,'String'))) > 0.1 && ...
  565. abs(str2double(get(handles.text42,'String')))>0.001
  566. set(handles.text42,'ForegroundColor','red')
  567. else
  568. set(handles.text42,'ForegroundColor','black')
  569. end
  570. drawnow('expose');
  571. catch
  572. warning('Lucretia:Floodland:bpmcalgui',['bpmcal gui error: ',lasterr])
  573. end
  574. % --- Restore bump
  575. function pushbutton13_Callback(hObject, eventdata, handles)
  576. % hObject handle to pushbutton13 (see GCBO)
  577. % eventdata reserved - to be defined in a future version of MATLAB
  578. % handles structure with handles and user data (see GUIDATA)
  579. bpmnames=get(handles.popupmenu1,'String');
  580. ibpm=get(handles.popupmenu1,'Value');
  581. if get(handles.radiobutton5,'Value')
  582. stat = nmCavCal('RestoreBumps',bpmnames{ibpm},'x');
  583. else
  584. stat = nmCavCal('RestoreBumps',bpmnames{ibpm},'y');
  585. end
  586. if stat{1}~=1
  587. errordlg(stat{2},'Bump Restore error')
  588. end
  589. popupmenu1_Callback(handles.popupmenu1,[],handles);
  590. % --- Reset bump
  591. function pushbutton14_Callback(hObject, eventdata, handles)
  592. % hObject handle to pushbutton14 (see GCBO)
  593. % eventdata reserved - to be defined in a future version of MATLAB
  594. % handles structure with handles and user data (see GUIDATA)
  595. bpmnames=get(handles.popupmenu1,'String');
  596. ibpm=get(handles.popupmenu1,'Value');
  597. if get(handles.radiobutton5,'Value')
  598. stat = nmCavCal('ResetBumps',bpmnames{ibpm},'x');
  599. else
  600. stat = nmCavCal('ResetBumps',bpmnames{ibpm},'y');
  601. end
  602. if stat{1}~=1
  603. errordlg(stat{2},'Bump Reset error')
  604. end
  605. popupmenu1_Callback(handles.popupmenu1,[],handles);
  606. % --- Executes on button press in checkbox2.
  607. function checkbox2_Callback(hObject, eventdata, handles)
  608. % hObject handle to checkbox2 (see GCBO)
  609. % eventdata reserved - to be defined in a future version of MATLAB
  610. % handles structure with handles and user data (see GUIDATA)
  611. % Hint: get(hObject,'Value') returns toggle state of checkbox2
  612. % --- Launch X calibration panel
  613. function pushbutton16_Callback(hObject, eventdata, handles)
  614. % hObject handle to pushbutton16 (see GCBO)
  615. % eventdata reserved - to be defined in a future version of MATLAB
  616. % handles structure with handles and user data (see GUIDATA)
  617. global FL
  618. ibpm=get(handles.popupmenu1,'Value');
  619. [stat, pars]=nmCavCal('GetPars');
  620. bpmname=pars.bpmnames{ibpm};
  621. if bpmname(end)=='X'
  622. caldata{1}=1; caldata{2}=bpmname;
  623. FL.Gui.bpmcal_calFig=bpmcal_calFig('UserData',caldata);
  624. else
  625. errordlg('Only calibration of Extraction Line BPMs through this interface','Cal Error');
  626. return
  627. end
  628. % --- Launch Y calibration panel
  629. function pushbutton17_Callback(hObject, eventdata, handles)
  630. % hObject handle to pushbutton17 (see GCBO)
  631. % eventdata reserved - to be defined in a future version of MATLAB
  632. % handles structure with handles and user data (see GUIDATA)
  633. global FL
  634. ibpm=get(handles.popupmenu1,'Value');
  635. [stat, pars]=nmCavCal('GetPars');
  636. bpmname=pars.bpmnames{ibpm};
  637. if bpmname(end)=='X'
  638. caldata{1}=2; caldata{2}=bpmname;
  639. FL.Gui.bpmcal_calFig=bpmcal_calFig('UserData',caldata);
  640. else
  641. errordlg('Only calibration of Extraction Line BPMs through this interface','Cal Error');
  642. return
  643. end
  644. % --- Executes on button press in pushbutton18.
  645. function pushbutton18_Callback(hObject, eventdata, handles)
  646. % hObject handle to pushbutton18 (see GCBO)
  647. % eventdata reserved - to be defined in a future version of MATLAB
  648. % handles structure with handles and user data (see GUIDATA)
  649. if ~strcmp(questdlg('Start calibration procedure (x'')?'),'Yes')
  650. return
  651. end
  652. bpmnames=get(handles.popupmenu1,'String');
  653. ibpm=get(handles.popupmenu1,'Value');
  654. bpmname=bpmnames{ibpm};
  655. stat = nmCavCal('CalibBump',bpmname,'xp');
  656. if stat{1}~=1
  657. errordlg(stat{2},'Calibration error')
  658. end
  659. popupmenu1_Callback(handles.popupmenu1,[],handles);
  660. % --- Executes on button press in pushbutton19.
  661. function pushbutton19_Callback(hObject, eventdata, handles)
  662. % hObject handle to pushbutton19 (see GCBO)
  663. % eventdata reserved - to be defined in a future version of MATLAB
  664. % handles structure with handles and user data (see GUIDATA)
  665. if ~strcmp(questdlg('Start calibration procedure (y'')?'),'Yes')
  666. return
  667. end
  668. bpmnames=get(handles.popupmenu1,'String');
  669. ibpm=get(handles.popupmenu1,'Value');
  670. bpmname=bpmnames{ibpm};
  671. stat = nmCavCal('CalibBump',bpmname,'yp');
  672. if stat{1}~=1
  673. errordlg(stat{2},'Calibration error')
  674. end
  675. popupmenu1_Callback(handles.popupmenu1,[],handles);
  676. % --- Executes on button press in pushbutton20.
  677. function pushbutton20_Callback(hObject, eventdata, handles)
  678. % hObject handle to pushbutton20 (see GCBO)
  679. % eventdata reserved - to be defined in a future version of MATLAB
  680. % handles structure with handles and user data (see GUIDATA)
  681. bpmnames=get(handles.popupmenu1,'String');
  682. ibpm=get(handles.popupmenu1,'Value');
  683. bpmname=bpmnames{ibpm};
  684. FlHwUpdate; % update setpt values
  685. stat = nmCavCal('SetBump',bpmname,'xp',str2double(get(handles.edit6,'String'))*1e-3,...
  686. ~get(handles.checkbox1,'Value'));
  687. if stat{1}~=1
  688. errordlg(stat{2},'Bump Set Error')
  689. end
  690. [stat pars]=nmCavCal('GetPars');
  691. if stat{1}==1
  692. set(handles.text39,'String',num2str(pars.bumpknob.xp{ibpm}.Value*1e3,5))
  693. end
  694. % --- Executes on button press in pushbutton21.
  695. function pushbutton21_Callback(hObject, eventdata, handles)
  696. % hObject handle to pushbutton21 (see GCBO)
  697. % eventdata reserved - to be defined in a future version of MATLAB
  698. % handles structure with handles and user data (see GUIDATA)
  699. bpmnames=get(handles.popupmenu1,'String');
  700. ibpm=get(handles.popupmenu1,'Value');
  701. bpmname=bpmnames{ibpm};
  702. FlHwUpdate; % update setpt values
  703. stat = nmCavCal('SetBump',bpmname,'yp',str2double(get(handles.edit7,'String'))*1e-3,...
  704. ~get(handles.checkbox1,'Value'));
  705. if stat{1}~=1
  706. errordlg(stat{2},'Bump Set Error')
  707. end
  708. [stat pars]=nmCavCal('GetPars');
  709. if stat{1}==1
  710. set(handles.text40,'String',num2str(pars.bumpknob.yp{ibpm}.Value*1e3,5))
  711. end
  712. function edit6_Callback(hObject, eventdata, handles)
  713. % hObject handle to edit6 (see GCBO)
  714. % eventdata reserved - to be defined in a future version of MATLAB
  715. % handles structure with handles and user data (see GUIDATA)
  716. set(handles.radiobutton5,'Value',0)
  717. set(handles.radiobutton8,'Value',1)
  718. set(handles.radiobutton6,'Value',0)
  719. set(handles.radiobutton9,'Value',0)
  720. % --- Executes during object creation, after setting all properties.
  721. function edit6_CreateFcn(hObject, eventdata, handles)
  722. % hObject handle to edit6 (see GCBO)
  723. % eventdata reserved - to be defined in a future version of MATLAB
  724. % handles empty - handles not created until after all CreateFcns called
  725. % Hint: edit controls usually have a white background on Windows.
  726. % See ISPC and COMPUTER.
  727. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  728. set(hObject,'BackgroundColor','white');
  729. end
  730. function edit7_Callback(hObject, eventdata, handles)
  731. % hObject handle to edit7 (see GCBO)
  732. % eventdata reserved - to be defined in a future version of MATLAB
  733. % handles structure with handles and user data (see GUIDATA)
  734. set(handles.radiobutton5,'Value',0)
  735. set(handles.radiobutton8,'Value',0)
  736. set(handles.radiobutton6,'Value',0)
  737. set(handles.radiobutton9,'Value',1)
  738. % --- Executes during object creation, after setting all properties.
  739. function edit7_CreateFcn(hObject, eventdata, handles)
  740. % hObject handle to edit7 (see GCBO)
  741. % eventdata reserved - to be defined in a future version of MATLAB
  742. % handles empty - handles not created until after all CreateFcns called
  743. % Hint: edit controls usually have a white background on Windows.
  744. % See ISPC and COMPUTER.
  745. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  746. set(hObject,'BackgroundColor','white');
  747. end
  748. % --- Executes on button press in radiobutton8.
  749. function radiobutton8_Callback(hObject, eventdata, handles)
  750. % hObject handle to radiobutton8 (see GCBO)
  751. % eventdata reserved - to be defined in a future version of MATLAB
  752. % handles structure with handles and user data (see GUIDATA)
  753. if get(hObject,'Value')
  754. set(handles.radiobutton5,'Value',0)
  755. set(handles.radiobutton9,'Value',0)
  756. set(handles.radiobutton6,'Value',0)
  757. popupmenu1_Callback(handles.popupmenu1,[],handles);
  758. else
  759. set(hObject,'Value',1)
  760. end
  761. % --- Executes on button press in radiobutton9.
  762. function radiobutton9_Callback(hObject, eventdata, handles)
  763. % hObject handle to radiobutton9 (see GCBO)
  764. % eventdata reserved - to be defined in a future version of MATLAB
  765. % handles structure with handles and user data (see GUIDATA)
  766. if get(hObject,'Value')
  767. set(handles.radiobutton8,'Value',0)
  768. set(handles.radiobutton5,'Value',0)
  769. set(handles.radiobutton6,'Value',0)
  770. popupmenu1_Callback(handles.popupmenu1,[],handles);
  771. else
  772. set(hObject,'Value',1)
  773. end