⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys_design.m

📁 很优良的PID控制器设计仿真程序与模型,经过严格检验
💻 M
📖 第 1 页 / 共 3 页
字号:
         'Units','normalized','Position',[0.08,0.26,0.4,0.07],...
         'HorizontalAlignment','left','BackgroundColor',[1,1,1]);
      bWMats(4)=uicontrol('Style','PushButton','String','Design',...
         'Units','normalized','Position',[0.52,0.85,0.15,0.09],'CallBack','sys_design(7,1);');
      bWMats(5)=uicontrol('Style','PushButton','String','Cancel',...
         'Units','normalized','Position',[0.68,0.85,0.15,0.09],'CallBack','delete(gcf);');
      bWMats(6)=uicontrol('Style','PushButton','String','Help',...
         'Units','normalized','Position',[0.84,0.85,0.15,0.09],'CallBack','clab_help(18);');
      [xL,cWMats(1)]=display_str(0.03,0.85,'Order of Standard Model:',[0,0,0],'off',9);
      [xL,cWMats(9)]=display_str(0.03,0.75,'Expected Natrual Freq \omega_n',[0,0,0],'off',9);
      cWMats(2)=uicontrol('Style','Edit','String','3','Visible','off',...
         'Units','normalized','Position',[0.37,0.81,0.10,0.07],...
         'HorizontalAlignment','left','BackgroundColor',[1,1,1]);
      [v,d]=version; v1=eval(v(1)); v2=eval(v(3)); v3=eval(v(5));
      if v2==2 & v3==0, strRadio='ToggleButton'; else, strRadio='RadioButton'; end 
      cWMats(3)=uicontrol('Style',strRadio,'String','ITAE Type I','Visible','off','Value',1,...
         'Units','normalized','Position',[0.05,0.49,0.30,0.06],...
         'HorizontalAlignment','left','BackgroundColor',0.8*[1,1,1],...
         'CallBack','extra_funs(4,3,''Value'',3,4:5);');
      cWMats(4)=uicontrol('Style',strRadio,'String','ITAE Type II','Value',0,'Visible','off',...
         'Units','normalized','Position',[0.05,0.39,0.30,0.06],...
         'HorizontalAlignment','left','BackgroundColor',0.8*[1,1,1],'CallBack','sys_design(7,3);');
      cWMats(5)=uicontrol('Style',strRadio,'String','Butterworth Model','Value',0,'Visible','off',...
         'Units','normalized','Position',[0.05,0.29,0.35,0.06],...
         'HorizontalAlignment','left','BackgroundColor',0.8*[1,1,1],...
         'CallBack','extra_funs(4,3,''Value'',5,3:4);');
      cWMats(6)=uicontrol('Style','Edit','String','10','Visible','off',...
         'Units','normalized','Position',[0.37,0.70,0.10,0.07],...
         'HorizontalAlignment','left','BackgroundColor',[1,1,1]);
      cWMats(7)=extra_funs(10,[0.04,0.26],[0.5,0.62],'off');
      cWMats(8)=uicontrol('Style','Text','String',' Standard Model Selection',...
         'Units','normalized','Position',[0.06,0.59,0.38,0.06],...
         'HorizontalAlignment','left','BackgroundColor',0.8*[1,1,1],'Visible','off');
      if nTask==10
         [xL,bWMats(10)]=display_str(0.05,0.10,'Frequency Vector',[0,0,0],'on',9);
         aWMats(7)=uicontrol('Style','Edit','String','logspace(-1,1)',...
            'Units','normalized','Position',[0.08 0.10 0.6 0.07],...
            'HorizontalAlignment','left','BackgroundColor',[1,1,1]);
      end
      bWMats(10)=extra_funs(10,[0.05,0.03],[0.82,0.18]);
      bWMats(11)=uicontrol('Style','Text','String','Show Magnitude Plots',...
         'Units','normalized','Position',[0.28,0.16,0.37,0.06],...
         'HorizontalAlignment','left','BackgroundColor',0.8*[1,1,1]);
      bWMats(7)=uicontrol('Style','PushButton','String','W1(s)','Tag','1',...
         'Units','normalized','Position',[0.10,0.05,0.2,0.09],'CallBack','sys_design(7,5,1);');
      bWMats(8)=uicontrol('Style','PushButton','String','W2(s)','Tag','2',...
         'Units','normalized','Position',[0.33,0.05,0.2,0.09],'CallBack','sys_design(7,5,2);');
      bWMats(9)=uicontrol('Style','PushButton','String','W3(s)','Tag','3',...
         'Units','normalized','Position',[0.56,0.05,0.2,0.09],'CallBack','sys_design(7,5,3);');
      bWMats(12)=extra_funs(10,[0.54,0.495],[0.97,0.74]);
      bWMats(13)=uicontrol('Style','Text','String','Problem Specifications',...
         'Units','normalized','Position',[0.56,0.71,0.35,0.06],'BackgroundColor',0.8*[1,1,1]);
      bWMats(14)=uicontrol('Style',strRadio,'String','Sensitivity','Value',0,...
         'Units','normalized','Position',[0.57,0.63,0.25,0.06],...
         'BackgroundColor',0.8*[1,1,1],'CallBack','sys_design(7,6);');
      bWMats(15)=uicontrol('Style',strRadio,'String','Mixed-sensitivity','Value',1,...
         'Units','normalized','Position',[0.57,0.54,0.31,0.06],...
         'BackgroundColor',0.8*[1,1,1],'CallBack','sys_design(7,7);');
      bWMats(18)=extra_funs(10,[0.54,0.495],[0.97,0.25]);
      bWMats(16)=uicontrol('Style',strRadio,'String','Regulator Problem','Value',1,...
         'Units','normalized','Position',[0.57,0.40,0.30,0.06],...
         'BackgroundColor',0.8*[1,1,1],'CallBack','extra_funs(4,2,''Value'',16,17);');
      bWMats(17)=uicontrol('Style',strRadio,'String','Control Problem','Value',0,...
         'Units','normalized','Position',[0.57,0.30,0.31,0.06],...
         'BackgroundColor',0.8*[1,1,1],'CallBack','extra_funs(4,2,''Value'',17,16);');
      set(g_hinf,'UserData',{aWMats,bWMats,cWMats,nTask});
   else, figure(g_hinf); end
case 2
   u_c=get(gcf,'UserData');
   if length(u_c)==10, nTask=u_c(10); bRegulate=get(u_c(8),'Value');
   else, nTask=u_c{4}; bRegulate=get(u_c{2}(16),'Value'); end
   switch arg1
   case 1
      if Td>0, [nP,dP]=pade(Td,nPade); tf_G=G_Sys*tf(nP,dP);  end   
      [Ax,Bx,Cx,Dx]=ssdata(G_Sys); 
      if any([7:10]==nTask)
         if get(u_c{2}(14),'Value')==1
            n=eval(get(u_c{3}(2),'String')); wn=eval(get(u_c{3}(6),'String'));
            bStdModel=extra_funs(5,3,'Value',3:5); 
            [nn,dd]=std_tf(bStdModel,wn,n); w1_num=dd; 
            w1_den=dd-[zeros(1,length(dd)-length(nn)),nn]; w1_den(end)=1e-5;
            w2_num=1e-5; w2_den=1; w3_num=[]; w3_den=[];
         else
            wtmp_Sys=get_tf(1); [w1_num,w1_den]=tfdata(wtmp_Sys,'v')
            wtmp_Sys=get_tf(2); [w2_num,w2_den]=tfdata(wtmp_Sys,'v')
            wtmp_Sys=get_tf(3); [w3_num,w3_den]=tfdata(wtmp_Sys,'v')
            if nTask==9, w_vec=eval(get(aWMats(7),'String')); end
         end
      else
         Qmat=eval(get(u_c(2),'String')); Xi=eval(get(u_c(3),'String'));
         Theta=eval(get(u_c(7),'String')); nA=size(Ax); nQ=size(Qmat); 
         if sum(nA==nQ)<2 
            warndlg('Matrices not match, try again!','Warning: Design failed!');
         end
      end
      bBiLin=0; [z,p,k]=zpkdata(G_Sys,'v');
      if any(abs(real(p))<1e-8), Ax=Ax+0.1*eye(size(Ax)); bBiLin=1; end
      Sys=mksys(Ax,Bx,Cx,Dx);
      switch nTask
      case 5
         W=diagmx(Qmat,1); V=diagmx(Xi*Bx*Bx',Theta); ss_f=lqg(Sys,W,V);
      case 6
         w=logspace(-2,2); q_vec=eval(get(u_c(1),'String')); 
         Kc=lqr2(Ax,Bx,Qmat,1); gg=gcf;  graf_tool(2); 
         bHold=0; if ishold, bHold=1; end, hold on
         ss_f=ltru(Sys,Kc,Xi,Theta,q_vec,w);
         if bHold==0, hold off; end
         figure(gg);
      case {7,8,9,10}
         w1=[zeros(1,length(w1_den)-length(w1_num)) w1_num;
             zeros(1,length(w1_num)-length(w1_den)) w1_den];
         w2=[zeros(1,length(w2_den)-length(w2_num)) w2_num;
             zeros(1,length(w2_num)-length(w2_den)) w2_den];
         w3=[zeros(1,length(w3_den)-length(w3_num)) w3_num;
             zeros(1,length(w3_num)-length(w3_den)) w3_den];
         extra_funs(12,'Please wait for controller design...'); pause(0.0001)
         Tss_=augtf(Sys,w1,w2,w3); 
         switch nTask
         case 7, ss_f=h2lqg(Tss_);
         case 8, ss_f=hinf(Tss_);
         case 9, [rho_opt,ss_f]=hinfopt(Tss_,1);
         case 10, ss_f=musyn(Tss_,w_vec);
         end
      end
      [Af,Bf,Cf,Df]=branch(ss_f);
      if bBiLin==1, Af=Af-0.1*eye(size(Af)); end
      if any([7:10]==nTask), close(gcf); end
      if bRegulate==1
         Gc_Sys=ss(Af,Bf,Cf,Df); shw_controller(Gc_Sys);
      else      
         if nTask>=7,
            [A,B,C,D]=branch(Tss_); C=C'; D=D(1,1);
         else, [A,B,C,D]=ssdata(ss_G); end   
         Gc_Sys=ss(Af,B,-Cf,1);
         H_Sys=ss(Af,Bf,Cf,0); shw_controller(Gc_Sys,H_Sys);
      end
      if nTask==9
         display_str(0.1,0.35,['\rho','_{optimal} =',display_str(rho_opt)]);
      end
   case 3
      extra_funs(4,3,'Value',4,[3,5]); nn=eval(get(u_c{3}(2),'String'));
      if n_ord>nn-1,
         set(u_c{3}(2),'String',int2str(n_ord+1));
      end
   case 5, wtmp_Sys=get_tf(arg2);
   case 6
      extra_funs(4,2,'Value',14,15); set(u_c{2}([1:3,8:9]),'Visible','off');
      set(u_c{1}(1:6),'Visible','off'); set(u_c{3}(1:9),'Visible','on');
   case 7   
      extra_funs(4,2,'Value',15,14); set(u_c{2}([1:3,8:9]),'Visible','on');
      set(u_c{1}(1:6),'Visible','on'); set(u_c{3}(1:9),'Visible','off');
   end
case 3,
   aWMats=get(gcf,'UserData');
   key=eval(get(gco,'Tag'));
   num=eval(get(aWMats{1}(2*key-1),'String')); den=eval(get(aWMats{1}(2*key),'String')); 
   G_W=tf(num,den); graf_tool(1); sys_analysis(1,G_W,[]);
end
      
%-----------------------------------------------------
%std_tf is used to find the standard transfer function
%-----------------------------------------------------
function [nn,dd]=std_tf(id,wn,n)
Dat_Tab{1}=[1,1,0,0,0,0,0; 1,1.41,1,0,0,0,0; 
            1,1.75,2.15,1,0,0,0; 1,2.1,3.4,2.7,1,0,0; 
            1,2.8,5.0,5.5,3.4,1,0; 1,3.25,6.6,8.6,7.45,3.95,1];
Dat_Tab{2}=[1,3.2,1,0,0,0,0; 1,1.75,3.25,1,0,0,0; 
            1,2.41,4.93,5.14,1,0,0; 1,2.19,6.5,6.3,5.24,1,0; 
            1,6.12,13.42,17.16,14.14,6.76,1];
Dat_Tab{3}=[1,1,0,0,0,0,0; 1,1.4,1,0,0,0,0; 1,2,2,1,0,0,0;
            1,2.6,3.4,2.6,1,0,0; 1,3.24,5.24,5.24,3.24,1,0; 
            1,3.86,7.46,9.13,7.46,3.86,1];

if n>6, warndlg('The selected order is too high!','Warning: Design failed!');
else   
   dd=Dat_Tab{id}(n,1:n+1).*(wn*ones(1,n+1)).^[0:n]; nn=dd(n+1); 
   if id==2, nn=dd(n:n+1); end
end
   
%-------------------------------------------------------------------------
%get_tf is used to find the transfer function from the given numerator and 
%denominator strings
%
%   G1=get_tf(keyMod)
%where
%  keyMod=1,2,3 for W1(s), W2(s), W3(s), respectively
%  G1 -- the weighting function entered
%-------------------------------------------------------------------------
function W_Sys=get_tf(keyMod)
aWMats=get(gcf,'UserData'); key=0; 
if isa(aWMats,'cell'), aWMats=aWMats{1}; key=1; end
vec1=get(aWMats(2*(keyMod-1)+1),'String'); vec2=get(aWMats(2*keyMod),'String'); 
W_Sys=proc_model(2,vec1,vec2); 

%---------------------------------------------------------------------------
%shw_controller set the controller to the system and display the results in 
%information window
%
%  shw_controller(Gc_Sys,H_Sys)
%where
%  Gc_Sys and H_Sys are controller and feedback model,  respectively.  
%---------------------------------------------------------------------------
function shw_controller(Gc_Sys,H_Sys)
close(gcf); 
figure(findobj('Tag','CtrlLABMain')); uu0=get(gcf,'UserData'); 
extra_funs(4,3,'Checked',[11,23],[10,12,13,20:22]);
set(uu0{4}(26),'Enable','on','Checked','on');
if isa(Gc_Sys,'ss')
   [a,b,c,d]=ssdata(Gc_Sys); 
   set(uu0{1}(2),'UserData',{2,Gc_Sys,mat2str(a),mat2str(b),mat2str(c),num2str(d)});
else
   [nn,dd]=tfdata(Gc_Sys,'v'); 
   set(uu0{1}(2),'UserData',{1,Gc_Sys,mat2str(nn),mat2str(dd)});
end 
if nargin==2
   if isa(H_Sys,'ss')
      [a,b,c,d]=ssdata(H_Sys); 
      set(uu0{1}(3),'UserData',{2,H_Sys,mat2str(a), mat2str(b),mat2str(c),num2str(d)});
   else
      [nn,dd]=tfdata(H_Sys,'v');
      set(uu0{1}(3),'UserData',{1,H_Sys,mat2str(nn),mat2str(dd)});
   end
else, set(uu0{1}(3),'UserData',[]); end   

%display controller and set properties with controllers to enable
ctrllab(0,2); proc_model(1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -