www.pudn.com > Closid30.rar > CLWIDGEN.M, change:1999-02-01,size:18088b


function clwidgen(option); 
% function clwidgen(option) 
% 
% Invokes the correct window for the 
% several closed-loop identification methods. 
% 
% option = chosen identification method.  
 
% functions called: clwcopmb,clmodest,clsetcol,clmodqs,clsigcon 
%                   clwyoimx,clwidcf 
 
% 28-04-1996 
% originally named: clidmeta/clidgenw 
% (c) Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 19-05-1998. 
%              13-09-1998: Improving check on open identification windows. 
%                          Introduced operating on working data. 
%              16-09-1998: 'F' , datc --> datre, datrv  
%                          + creating validation data. 
%              01-02-1999: minor correction on opening CF and DY-windows. 
% 
%******************************************************* 
% 
global CLIDscrz CLIDmeth CLIDmods 
 
% Check whether an identification window is open already; 
% If it is the chosen one: make it active; 
% If it is another one: give a message that only one identification 
% window can be open. 
% If no window is open: open the appropriate one. 
 
if option<1 | option>7 
  return 
end 
 
% If the chosen one is open already, make it active: 
if findobj('name',CLIDmeth{option}) 
  figure(findobj('name',CLIDmeth{option})) 
  return 
% If a different one is open already, give a message: 
else 
  v=[1:1:7]; 
  vt=find(v~=option); 
  for k=vt 
    if findobj('name',CLIDmeth{k}) 
	  errstring= [' Two identification methods can not be open '... 
      ' simultaneously: first close the current one']; 
      clerrdia(str2mat(errstring),1); 
% Set the identification method pull down menu back to the method already open: 
      set(findobj('tag','CLMAINPOPIDENT'),'value',k+1) 
      return 
	end 
  end 
end 
% 
 
%open=get(gco,'userdata'); 
% If the chosen one is open already, make it active: 
%if open & findobj('name',CLIDmeth{option}) 
%  figure(findobj('name',CLIDmeth{option})) 
%  return 
% If another one is open, give an error message: 
%elseif open 
%  errstring= [' Two identification methods can not be open '... 
%    ' simultaneously: first close the current one']; 
%  clerrdia(str2mat(errstring),1); 
%  return 
%end 
 
% If none is open, open the correct one: 
% 
%******************************************************************** 
% 
%     CHECK AVAILABILITY OF APPROPRIATE DATA/CONTROLLER INFORMATION 
% 
%******************************************************************** 
 
%   Check whether data is available 
%cm=[1:CLIDmods(1,1)]; 
%if isempty(find(CLIDmods(2,cm)==1))   % changed 13-09-1998 
 if isempty(CLIDmods(58,1)) 
  clerrdia('[ERROR: no working data set available]',1) 
  return 
% when data available, read it and check whether the right signals  
% are present: 
else 
  dat=clobjget('datw'); 
  if option==1|option==4|option==5|option==6|option==7 
	if sum(dat(:,2))==0 
	  clerrdia('[ERROR: no plant input signal present]',1) 
	  return 
	end 
  end 
end 
% 
% Check if no multiple controllers are selected: 
cm=[1:CLIDmods(1,4)]; 
if sum(CLIDmods(17,cm))>1 
  clerrdia('ERROR: only 1 controller can be selected',1) 
  return 
end 
% Check whether 1 controller is active for identification methods: 
% indirect, tailor, dual-youla, coprime-factor 
if (option==2|option==3|option==5|option==6) 
  if isempty(find(CLIDmods(17,cm)==1)) 
    clerrdia('ERROR: no active controller available',1) 
    return 
  end 
% two-step, IV  and nonparametric require either C or r1/r2: 
else 
  if isempty(find(CLIDmods(17,cm)==1)) & sum(dat(:,3:4))==0 
	clerrdia('ERROR: either a controller or a reference signal is required',1) 
	return 
  end 
end 
% 
% ************ Determine external excitation signal to be used: 
 
% Determine which external signals are used as input: 
% and write the estimation signals in the "filtered data board"  
[dat,title,info,p]=clobjget('datw'); 
[datv,titlev,infov,pv]=clobjget('datv');   %% Added 16-09-1998 
tsamp=p(2,1); 
y=dat(:,1);u=dat(:,2);r2=dat(:,3);r1=dat(:,4); 
yv=datv(:,1);uv=datv(:,2);r2v=datv(:,3);r1v=datv(:,4); %% Added 16-09-1998 
if ~isempty(find(CLIDmods(17,cm)==1))			 
  C=clobjget('C'); 
  [a,b,c,d]=clsplit(C); 
end 
if ~isempty(find(CLIDmods(17,cm)==1))	& max(abs(eig(a))) < 0.9995 
  if sum(u)~=0 
    r_c=u+dlsim(a,b,c,d,y); 
	r_cv=uv+dlsim(a,b,c,d,yv); %% Added 16-09-1998 
    stringr='u + C y'; 
	sop=4; 
  elseif sum(r1)~=0 & sum(r2)~=0 
	r_c=r1+dlsim(a,b,c,d,r2); 
	r_cv=r1v+dlsim(a,b,c,d,r2v); %% Added 16-09-1998 
	stringr='r1 + C r2'; 
	sop=3; 
  end 
elseif sum(r1)~=0 
  r_c=r1; 
  r_cv=r1v;						%% Added 16-09-1998 
  stringr='r1'; 
  sop=1; 
elseif sum(r2)~=0 
  r_c=r2; 
  r_cv=r2v;						%% Added 16-09-1998 
  stringr='r2'; 
  sop=2; 
end 
% 
% Indirect identification: in case of data (r2,y) only, the controller 
% has to be causally invertible 
if option==2 & sop==2 
  C=clobjget('C'); 
  [a,b,c,d]=clsplit(C); 
  if d==0 
    clerrdia(['ERROR: indirect method with input signal r2 needs'... 
	           ' a causally invertible controller'],1) 
	return 
  end 
end 
% 
%******************************************************************** 
% 
%         START PREPARATIONS FOR OPENING IDENTIFICATION WINDOW 
%                  
%******************************************************************** 
 
%   Colors 
[frmcol,txtcol,edicol,pshcol,radcol,axscol,c7,c8,c9,c10,... 
   modcol,edtcol,pubcol,putcol,chbcol,chtcol,txbcol,pstcol]=clsetcol; 
 
%   Headers 
if option==1 
% Two-stage identification method 
  head1='CONSTRUCT AUXILIARY INPUT SIGNAL'; 
  head2='ESTIMATE PLANT'; 
  butt3='Copy plant model'; 
elseif option==2 
% Indirect identification method 
  head1='APPLIED SIGNALS'; 
  head2='ESTIMATE CLOSED LOOP TRANSFER FUNCTION'; 
  butt3='Calculate/copy plant model'; 
elseif option==3 
% Tailor-made identification method 
  head1='APPLIED SIGNALS'; 
  head2='ESTIMATE PLANT MODEL'; 
  butt3='Copy plant model'; 
elseif option==4 
% IV identification method 
  head1='APPLIED SIGNALS'; 
  head2='ESTIMATE PLANT MODEL'; 
  butt3='Copy plant model'; 
elseif option==5 
% Coprime factors identification method 
  head1='CONSTRUCT AUXILIARY INPUT SIGNAL'; 
  head2='ESTIMATE PLANT FACTORS'; 
  butt3='Calculate/copy plant model'; 
elseif option==6 
% Dual-Youla identification method 
  head1='CONSTRUCT AUXILARY I/O SIGNALS'; 
  head2='ESTIMATE DUAL-YOULA FACTOR'; 
  butt3='Copy plant model'; 
elseif option==7 
% Non-parametric identification method 
  head1='APPLIED SIGNALS'; 
  head2='ESTIMATE'; 
  butt3='Copy plant model'; 
else 
  error('not a valid option') 
end 
%******************************************************************** 
% 
%                        OPEN MAIN FRAME 
% 
%******************************************************************** 
% 
set(gco,'Userdata',1); 
%   Determine screen size and position and size of main ID-window: 
z=CLIDscrz; 
posfgm=[z(3)-380 z(4)-375 330 345]; 
% Open window 
clfggen=figure('Menubar','none','Color',frmcol,... 
  'Numbertitle','off','Name',CLIDmeth{option},... 
  'pos',posfgm,'Resize','on','tag','CLIDWINDOW'); 
 
%******************************************************************** 
% 
%      OPEN FRAME FOR FIRST STEP:  SIGNAL GENERATION 
% 
%******************************************************************** 
     
% Construct frame for signal construction step. 
frgen1x=0.01;frgen1y=0.65; 
frgen1pos=[frgen1x frgen1y 0.98 0.34; 
           frgen1x+0.04 frgen1y+0.27 0.90 0.06]; 
typgen1pos=[frgen1x+0.02 frgen1y+0.20 0.30 0.06; % Range 
            frgen1x+0.33 frgen1y+0.20 0.61 0.06; 
            frgen1x+0.02 frgen1y+0.13 0.30 0.06; % Import model/controller 
            frgen1x+0.2 frgen1y+0.13 0.61 0.06]; 
frgen1=zeros(13,1); 
% 
% Frame: 
frgen1(1)=uicontrol(clfggen,'style','frame','uni','nor',... 
  'pos',frgen1pos(1,:),'Back',frmcol,'Fore',txtcol,'tag','DERIVEFRAME'); 
% 
%   Header-text 
frgen1(2)=uicontrol(clfggen,'style','text','uni','nor',... 
   'pos',frgen1pos(2,:),'Back',txbcol,'Fore',txtcol,... 
   'String',head1,'tag','CLINPUTSIGNAL'); 
% 
%   For methods that do not need a signal construction step: 
if option==2|option==3|option==4|option==7 
  set(frgen1(1),'Fore',edtcol);   %Set foregroundcolor off 
% Write the standard choices for the signals: 
  frgen1(3)=uicontrol(clfggen,'style','text','uni','nor',... 
      'pos',[frgen1x+0.05 frgen1y+0.20 0.40 0.06],... 
      'Back',txbcol,'Fore',txtcol,... 
      'hori','left'); 
  frgen1(4)=uicontrol(clfggen,'style','text','uni','nor',... 
      'pos',[frgen1x+0.05 frgen1y+0.10 0.40 0.06],... 
      'Back',txbcol,'Fore',txtcol,... 
      'hori','left','String','ID-output: z = y','Value',0,'vis','on'); 
  frgen1(5)=uicontrol(clfggen,'style','text','uni','nor',... 
      'pos',[frgen1x+0.45 frgen1y+0.20 0.45 0.06],... 
      'Back',txbcol,'Fore',txtcol,... 
      'hori','left','Value',0,'vis','off'); 
% 
% For other methods: create pop-up menu with options for  
% signal construction: 
else 
  frgen1(6)=uicontrol(clfggen,'style','popup','uni','nor',... 
    'Back',pubcol,'Fore',putcol,'pos',typgen1pos(4,:),'string',' ',... 
	'tag','CLIDSTEP1'); 
  if option==1    %Two-step 
    set(frgen1(6),'String',... 
       'Construct auxiliary signal|quick-start|import S'); 
  elseif option==5  %Coprime-factor 
     set(frgen1(6),'String',... 
       'Construct auxiliary signal|quick-start|import Gx'); 
  elseif option==6    %Dual-Youla 
     set(frgen1(6),'String',... 
        'Construct auxiliary signals|quick-start|import Gx and C'); 
  end       
end 
% 
if option==2 | option==3 | option==7 
  set(frgen1(3),'string',['ID-input: x = ' stringr]); 
  if option==7 
    set(frgen1(4),'string','ID-output: z = [y u]'); 
  end 
elseif option==4 
  set(frgen1(3),'string',['ID-input: x = u']); 
  set(frgen1(5),'string',['ID-instrument: ' stringr],'vis','on'); 
end 
% Store the signals in (invisible) data boards: 
% For identification methods that require a first step, only the 
% excitation signal is stored in 'datre'. For the other methods 
% the data to be used for final estimation is stored in 'datfe'. 
if option==2 | option==3 
  clobjins([y r_c],'datfe',title,info,p); 
  clobjins([yv r_cv],'datfv',titlev,infov,pv); %% Added 16-09-1998 
elseif option==4 | option==7 
  clobjins([y u r_c],'datfe',title,info,p); 
  clobjins([yv uv r_cv],'datfv',titlev,infov,pv); %% Added 16-09-1998 
else 
  clobjins(r_c,'datre',title,info,p); 
  clobjins(r_cv,'datrv',titlev,infov,pv); 
end 
set(frgen1(2),'userdata',sop); 
% 
% Reset the pop-up menu for the two-step method when r2 is used: 
if option==1 & get(findobj('tag','CLINPUTSIGNAL'),'userdata')==2 
  set(frgen1(6),'String',... 
       'Construct auxiliary signal|quick-start|import CS'); 
end 
% 
%******************** Callbacks for first step (signal Construction): 
%   
if option==1|option==5|option==6 
  if option==1 
    genimpa=['if get(gco,''value'')==2, clmodqs(1); clsigcon(1);',... 
     'set(findobj(''tag'',''CLIDSTEP1''),''value'',1);',... 
     'elseif get(gco,''value'')==3, clw2simp;',... 
      'end;']; 
  elseif option==5 
    genimpa=['if get(gco,''value'')==2, clmodqs(2); clsigcon(2);',... 
      'set(findobj(''tag'',''CLIDSTEP1''),''value'',1);',... 
      'elseif get(gco,''value'')==3, clwcfimx;',... 
      'end;']; 
  elseif option==6 
    genimpa=['if get(gco,''value'')==2, clmodqs(3); clsigcon(3);',... 
      'set(findobj(''tag'',''CLIDSTEP1''),''value'',1);',... 
	  'elseif get(gco,''value'')==3, clwyoimp;',... 
      'end;']; 
  end 
  set(frgen1(6),'callb',genimpa);          
end 
 
%******************************************************************** 
% 
%      OPEN FRAME FOR SECOND STEP:  ESTIMATION 
% 
%******************************************************************** 
 
% Construct frame for estimation step. 
frgen2x=0.01;frgen2y=0.30; 
frgen2pos=[frgen2x frgen2y 0.98 0.34; 
           frgen2x+0.04 frgen2y+0.27 0.90 0.06]; 
typgen2pos=[frgen2x+0.02 frgen2y+0.20 0.30 0.06;   % Data range 
            frgen2x+0.33 frgen2y+0.20 0.61 0.06; 
            frgen2x+0.02 frgen2y+0.13 0.30 0.06;   % Data prefilter 
	        frgen2x+0.33 frgen2y+0.13 0.61 0.06; 
            frgen2x+0.20 frgen2y+0.13 0.60 0.06];  % Estimate 
frgen2=zeros(8,1); 
 
% Frame: 
frgen2(1)=uicontrol(clfggen,'style','frame','uni','nor',... 
  'pos',frgen2pos(1,:),'Back',frmcol,'Fore',edtcol,'tag','ESTIMATEFRAME'); 
%   
% Header-text: 
frgen2(2)=uicontrol(clfggen,'style','text','uni','nor',... 
  'pos',frgen2pos(2,:),'Back',txbcol,'Fore',txtcol,'String',head2); 
 
% For methods for which the first step is trivial: color frame 2nd step: 
if option==2|option==3|option==4|option==7 
  set(frgen2(1),'fore',txtcol); 
end 
 
% Handling estimate; first the special cases: 
 
if option==3|option==4    % Tailor-made and IV  identification 
  frgen2(3)=uicontrol(clfggen,'style','text','uni','nor',... 
   'pos',[frgen2x+0.1 frgen2y+0.20 0.30 0.06],... 
   'Back',txbcol,'Fore',txtcol,'String','Model order ','Value',0); 
  frgen2(4)=uicontrol(clfggen,'style','edit','uni','nor',... 
   'pos',[frgen2x+0.45 frgen2y+0.20 0.3 0.06],... 
   'Back',edicol,'Fore',edtcol,'String','[4 4 1]'); 
  frgen2(7)=uicontrol(clfggen,'style','push','uni','nor',... 
   'Back',pshcol,'Fore',pstcol,'String','Estimate',... 
   'pos',[frgen2x+0.20 frgen2y+0.05 0.60 0.07]); 
  if option==3 
    set(frgen2(4),'tag','TAILORORDER'); 
  elseif option==4 
     set(frgen2(4),'tag','IVORDER'); 
  end 
% 
elseif option==7      % Non-parametric 
  frgen2(3)=uicontrol(clfggen,'style','text','uni','nor',... 
   'pos',[frgen2x+0.12 frgen2y+0.18 0.30 0.08],... 
   'Back',txbcol,'Fore',txtcol,... 
   'String','Window length','Value',0); 
  frgen2(4)=uicontrol(clfggen,'style','edit','uni','nor',... 
   'pos',[frgen2x+0.45 frgen2y+0.20 0.3 0.06],... 
   'Back',edicol,'Fore',edtcol,... 
   'String',num2str(64),'tag','WINDOWLENGTH'); 
  frgen2(7)=uicontrol(clfggen,'style','push','uni','nor',... 
   'Back',pshcol,'Fore',pstcol,'String','Estimate',... 
   'pos',[frgen2x+0.20 frgen2y+0.05 0.60 0.07]); 
% 
elseif option==5    % Coprime factor method 
  frgen2(7)=uicontrol(clfggen,'style','popup','uni','nor',... 
    'Back',pubcol,'Fore',putcol,... 
	'String','Estimate|OE(Common denom.form)|Ident',... 
    'pos',typgen2pos(5,:),'value',1); 
else                % All other methods 
  frgen2(7)=uicontrol(clfggen,'style','push','uni','nor',... 
    'Back',pshcol,'Fore',pstcol,'String','Estimate',... 
    'pos',typgen2pos(5,:)); 
end 
set(frgen2(7),'tag','CLIDENT'); 
% 
%***************** Callbacks second step *************************** 
% 
% Construction and estimation 
if option==5,  
  strgcons=['opt=get(findobj(''tag'',''CLMAINPOPIDENT''),''value'');'... 
            'if get(gco,''value'')==3, clmodest(opt-1);'... 
			'elseif get(gco,''value'')==2, clwidcf; end; clear opt;']; 
else 
  strgcons=['opt=get(findobj(''tag'',''CLMAINPOPIDENT''),''value'');'... 
            'clmodest(opt-1); clear opt']; 
end 
set(frgen2(7),'callb',strgcons); 
% 
% 
%******************************************************************** 
% 
% OPEN FRAME FOR THIRD STEP:  MODEL CONVERSION / COPY TO MODEL BOARD 
% 
%******************************************************************** 
 
% Construct frame for model export. 
frgen3x=0.01;frgen3y=0.12; 
frgen3pos=[frgen3x frgen3y 0.98 0.17; 
           frgen3x+0.04 frgen3y+0.10 0.90 0.06]; 
typgen3pos=[frgen3x+0.20 frgen3y+0.02 0.60 0.07]; % butt3 
frgen3=zeros(3,1); 
frgen3(1)=uicontrol(clfggen,'style','frame','uni','nor',... 
  'pos',frgen3pos(1,:),'Back',frmcol,'Fore',edtcol,'tag','COPYFRAME'); 
frgen3(2)=uicontrol(clfggen,'style','text','uni','nor',... 
  'pos',frgen3pos(2,:),'Back',txbcol,'Fore',txtcol,... 
  'String','COPY TO MODEL BOARD'); 
frgen3(3)=uicontrol(clfggen,'style','push','uni','nor',... 
  'pos',typgen3pos(1,:),'Back',pshcol,'Fore',pstcol,... 
  'String',butt3); 
% 
% ******** Callbacks for third step  ******************************** 
% 
%   Copy to model board 
strgcopy=['opt=get(findobj(''tag'',''CLMAINPOPIDENT''),''value'');'... 
     'clwcopmb(opt-1); clear opt']; 
set(frgen3(3),'callb',strgcopy); 
% 
%******************************************************************** 
% 
%                      OPEN FRAME PUSH BUTTONS 
% 
%******************************************************************** 
     
% Construct frame for buttons 
frgen4x=0.01;frgen4y=0.01; 
frgen4pos=[frgen4x frgen4y 0.98 0.10]; 
typgen4pos=[frgen4x+0.02 frgen4y+0.02 0.45 0.06; 
            frgen4x+0.49 frgen4y+0.02 0.45 0.06]; 
 
frgen4=zeros(3,1); 
frgen4(1)=uicontrol(clfggen,'style','frame','uni','nor',... 
  'pos',frgen4pos,'Back',frmcol,'Fore',edtcol); 
frgen4(2)=uicontrol(clfggen,'style','push','uni','nor',... 
  'pos',typgen4pos(1,:),'Back',pshcol,'Fore',pstcol,... 
  'String','HELP','Value',0); 
frgen4(3)=uicontrol(clfggen,'style','push','uni','nor',... 
  'pos',typgen4pos(2,:),'Back',pshcol,'Fore',pstcol,... 
  'String','CLOSE','Value',0); 
% 
%        Callback: 
%   Close: 
strclose=['close(gcf);myhandle=findobj(''TAG'',''CLMAINPOPIDENT'');'... 
   'set(myhandle,''Userdata'',0);set(myhandle,''Value'',1);clear myhandle']; 
set(frgen4(3),'callb',strclose); 
% 
%   Help: 
if option==1 
  set(frgen4(2),'callb','hthelp(''cltwostp.htm'')'); 
elseif option==2 
  set(frgen4(2),'callb','hthelp(''clindir.htm'')'); 
elseif option==3 
  set(frgen4(2),'callb','hthelp(''cltailm.htm'')'); 
elseif option==4 
  set(frgen4(2),'callb','hthelp(''clivmeth.htm'')'); 
elseif option==5 
  set(frgen4(2),'callb','hthelp(''clcopfac.htm'')'); 
elseif option==6 
  set(frgen4(2),'callb','hthelp(''clyoula.htm'')'); 
elseif option==7 
  set(frgen4(2),'callb','hthelp(''clnonpar.htm'')'); 
end 
 
%*********************************************************** 
% 
%          STORE HANDLES IN USERDATA 
% 
%*********************************************************** 
 
% Put handles in userdata of figure 
r=length(frgen1); 
us=zeros(r,4); 
us(:,1)=frgen1; 
us(1:length(frgen2),2)=frgen2; 
us(1:length(frgen3),3)=frgen3; 
us(1:length(frgen4),4)=frgen4; 
set(clfggen,'Userdata',us);