Code covered by the BSD License  

Highlights from
MIMOtool

image thumbnail

MIMOtool

by

 

12 Nov 2001 (Updated )

Multi Input Multi Output Systems Toolbox

pid1.m
function pid1;
%Massimo Davini 08/11/99

watchon;
global stack;

nm=stack.temp.canali;

stack.temp.canale=nan;                    %canale attuale
stack.temp.stabili=nan*ones(1,nm);        %flag di stabilit dei canali (open loop)
stack.temp.stabilicl=nan*ones(1,nm);      %flag di stabilit dei canali (closed loop)
stack.temp.flag=zeros(1,nm);              %flag di salvataggio parametri dei canali
stack.temp.pid_type=5*ones(1,nm);         %tipo di controllore selezionato 
stack.temp.parametri=cell(1,nm);          %parametri di tutti i controllori dei canali
stack.temp.parametri_dfl=cell(1,nm);      %parametri di tutti i controllori di default dei canali

%ogni riga (5)  un vettore [Kp(i),Ti(i),Td(i),pd(i)]
for i=1:nm
 stack.temp.parametri{i}=NaN*zeros(5,4);
 stack.temp.parametri_dfl{i}=NaN*zeros(5,4);
end;
stack.temp.dfl=ones(5,nm);                %flag che indica per ogni canale se sono stati scelti 
                                          %i parametri di default
stack.temp.controllo=cell(1,nm);          %controllore di ogni canale
stack.temp.time=cell(1,nm);               %tempo t per i grafici di ogni canale
stack.temp.grafico=cell(1,3);             %t,grafico ol,grafico cl

set(stack.temp.handles,'visible','off');
drawnow;

% enlarge text if java machine is running
jsz=stack.general.javasize;

sz=2.5*jsz+.3;

channels=stack.temp.canali;
stack.temp.canale=1;
stack.temp.pid_type(1)=5;  %default

campi=['''canale'',''stabili'',''stabilicl'',''flag'',''pid_type'',''parametri'',',...
       '''parametri_dfl'',''dfl'',''controllo'',''time'',''grafico'''];
pid1(1)=uicontrol('style','push','unit','normalized','position',[0.05 0.05 0.14 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'string','BACK','Horizontalalignment','center','tag','pid1',...
   'TooltipString','Back to the previous window',...
   'callback',sprintf('back_syn(''pid0'',%u,%s);',length(stack.temp.handles),campi));
   
campi=['''integratori'',''plant'',''augmplant'',''canali'',''canale'',''stabili'',''stabilicl'',''Num'',''Den'',',...
        '''flag'',''pid_type'',''parametri'',''parametri_dfl'',''dfl'',''controllo'',''time'',''grafico'''];
pid1(2)=uicontrol('style','push','unit','normalized','position',[0.2 0.05 0.14 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'string','CLOSE','Horizontalalignment','center',...
   'TooltipString','Back to the main SYNTHESIS window','tag','pid1',...
   'callback',sprintf('back_syn(''syn0'',0,%s);',campi));

pid1(3)=uicontrol('style','push','unit','normalized','position',[0.81 0.05 0.14 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'Horizontalalignment','center','string','NEXT','tag','pidnext',...
   'TooltipString','Go to the next window','callback','pid2;','enable','off');

cb=['stack.temp.parametri{stack.temp.canale}(stack.temp.pid_type(stack.temp.canale),:)=',...
    'stack.temp.parametri_dfl{stack.temp.canale}(stack.temp.pid_type(stack.temp.canale),:);',...
    'stack.temp.dfl(stack.temp.pid_type(stack.temp.canale),stack.temp.canale)=1;pid1_opt(stack.temp.pid_type(stack.temp.canale));'];
pid1(4)=uicontrol('style','push','unit','normalized','position',[0.35 0.05 0.21 0.055],...
   'fontunits','normalized','fontsize',1.9*jsz+.35,'fontweight','bold',...
   'string','Ziegler/Nichols','Horizontalalignment','center','tag','pid1',...
   'TooltipString','Load the Ziegler-Nichols''s parameters',...
   'callback',cb,'enable','off','visible','off');

pid1(5)=uicontrol('style','push','unit','normalized','position',[0.35 0.115 0.21 0.055],...
   'fontunits','normalized','fontsize',1.9*jsz+.35,'fontweight','bold',...
   'string','Closed Loop','Horizontalalignment','center','tag','pid1',...
   'TooltipString','Plot the channel''s closed loop step response',...
   'callback','pid1_cl;','enable','on','visible','off');

pid1(6)=uicontrol('style','push','unit','normalized','position',[0.57 0.05 0.11 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'string','<<','Horizontalalignment','center','tag','pid1<<',...
   'TooltipString','Previous channel',...
   'enable','off','callback','pid1_ffrw(''rw'');','visible','off');

pid1(7)=uicontrol('style','push','unit','normalized','position',[0.69 0.05 0.11 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'string','>>','Horizontalalignment','center','tag','pid1>>','visible','off',...
   'TooltipString','Next channel','callback','pid1_ffrw(''ff'');');
if channels==1 set(pid1(7),'enable','off');end; 

pid11(1)=uicontrol('style','text','unit','normalized','position',[0.05 0.9 0.9 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string','CHANNEL 1-1 :','tag','tx1');

pid11(2)=uicontrol('style','text','unit','normalized','position',[0.05 0.8 0.07 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string','Kp = ','tag','pid1');

cb='stack.temp.dfl(stack.temp.pid_type(stack.temp.canale),stack.temp.canale)=0;';
pid11(3)=uicontrol('style','edit','unit','normalized','position',[0.12 0.795 0.14 0.06],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'visible','off','Horizontalalignment','left','tag','ed1',...
   'backgroundcolor','yellow','callback',cb);

pid11(4)=uicontrol('style','text','unit','normalized','position',[0.28 0.8 0.07 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string','Ti = ','tag','pid1');

pid11(5)=uicontrol('style','edit','unit','normalized','position',[0.35 0.795 0.14 0.06],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'visible','off','Horizontalalignment','left','tag','ed2',...
   'backgroundcolor','yellow','callback',cb);

pid11(6)=uicontrol('style','text','unit','normalized','position',[0.51 0.8 0.07 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string','Td = ','tag','pid1');

pid11(7)=uicontrol('style','edit','unit','normalized','position',[0.58 0.795 0.14 0.06],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'visible','off','Horizontalalignment','left','tag','ed3',...
   'backgroundcolor','yellow','callback',cb);

pid11(8)=uicontrol('style','text','unit','normalized','position',[0.74 0.8 0.07 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string','pd = ','tag','pid1');

pid11(9)=uicontrol('style','edit','unit','normalized','position',[0.81 0.795 0.14 0.06],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'visible','off','Horizontalalignment','left','tag','ed4',...
   'backgroundcolor','yellow','callback',cb);

pid11(10)=uicontrol('style','text','unit','normalized','position',[0.43 0.28 0.05 0.03],...
   'visible','off','tag','pid1','backgroundcolor','blue');

pid11(11)=uicontrol('style','text','unit','normalized','position',[0.5 0.27 0.52 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'visible','off','tag','pid1','backgroundcolor',[.6 .7 .9],...
   'string','Open loop step response','Horizontalalignment','left');

pid11(12)=uicontrol('style','text','unit','normalized','position',[0.43 0.23 0.05 0.03],...
   'visible','off','tag','pid1','backgroundcolor','red');

pid11(13)=uicontrol('style','text','unit','normalized','position',[0.5 0.22 0.52 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'visible','off','tag','pidnota','backgroundcolor',[.6 .7 .9],...
   'string','Closed loop step response','Horizontalalignment','left');

pid1(8)=uicontrol('style','frame','unit','normalized','position',[0.05 0.41 0.29 0.34],...
   'tag','pid1','visible','off','backgroundcolor',[1 1 1]);

pid1(9)=uicontrol('style','radiobutton','unit','normalized','position',[0.07 0.68 0.25 0.05],...
   'fontunits','normalized','fontsize',2.5*jsz+.35,'fontweight','bold',...
   'Horizontalalignment','center','string',' Controller P','tag','pidopt1',...
   'callback','pid1_opt(1);','backgroundcolor',[1 1 1],'visible','off');

pid1(10)=uicontrol('style','radiobutton','unit','normalized','position',[0.07 0.62 0.25 0.05],...
   'fontunits','normalized','fontsize',2.5*jsz+.35,'fontweight','bold',...
   'Horizontalalignment','center','string',' Controller I','tag','pidopt2',...
   'callback','pid1_opt(2);','backgroundcolor',[1 1 1],'visible','off');

pid1(11)=uicontrol('style','radiobutton','unit','normalized','position',[0.07 0.56 0.25 0.05],...
   'fontunits','normalized','fontsize',2.5*jsz+.35,'fontweight','bold',...
   'Horizontalalignment','center','string',' Controller PI','tag','pidopt3',...
   'callback','pid1_opt(3);','backgroundcolor',[1 1 1],'visible','off');

pid1(12)=uicontrol('style','radiobutton','unit','normalized','position',[0.07 0.5 0.25 0.05],...
   'fontunits','normalized','fontsize',2.5*jsz+.35,'fontweight','bold',...
   'Horizontalalignment','center','string',' Controller PD','tag','pidopt4',...
   'callback','pid1_opt(4);','backgroundcolor',[1 1 1],'visible','off');

pid1(13)=uicontrol('style','radiobutton','unit','normalized','position',[0.07 0.44 0.25 0.05],...
   'fontunits','normalized','fontsize',2.5*jsz+.35,'fontweight','bold','foregroundcolor','r',...
   'Horizontalalignment','center','string',' Controller PID','tag','pidopt5','value',1,...
   'callback','pid1_opt(5);','backgroundcolor',[1 1 1],'visible','off');


str1=['                       1       sTd'];
str2=sprintf('PID = Kp( 1 + ---- + ---------- )');
str3=sprintf('                     sTi   1+s/pd');
pid1(14)=uicontrol('style','text','unit','normalized','position',[0.05 0.32 0.35 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string',str1,'tag','f1');

pid1(15)=uicontrol('style','text','unit','normalized','position',[0.05 0.27 0.35 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string',str2,'tag','f2');

pid1(16)=uicontrol('style','text','unit','normalized','position',[0.05 0.22 0.35 0.05],...
   'fontunits','normalized','fontsize',sz,'fontweight','bold',...
   'backgroundcolor',[.6 .7 .9],'visible','off',...
   'Horizontalalignment','left','string',str3,'tag','f3');

set(pid11(1:9),'visible','on');
set(pid1,'visible','on');
stack.temp.handles=[stack.temp.handles,pid1,pid11];
drawnow;

pid1_dfl;

if stack.temp.stabili(1) str='STABLE';else str='UNSTABLE';end;
set(pid11(1),'string',sprintf('CHANNEL 1-1 : %s ( open loop )',str));

if length(find(isnan(stack.temp.parametri{1}(5,:))==1))==4
     set(pid1(4),'enable','off');
     par=NaN*ones(1,4);
else par=stack.temp.parametri{1}(5,:);
     set(pid1(4),'enable','on');
     set(findobj('tag','pidnota'),'string','Closed loop step response from Z/N');
end;

set(findobj('tag','ed1'),'string',num2str(par(1)));
set(findobj('tag','ed2'),'string',num2str(par(2)));
set(findobj('tag','ed3'),'string',num2str(par(3)));
set(findobj('tag','ed4'),'string',num2str(par(4)));


sys=tf(stack.temp.Num(1,:),stack.temp.Den);
[y,t]=step(sys);

axes('Position',[0.43 0.41 0.52 0.34]);
set(gca,'drawmode','fast');
plot(t,y,'tag','plotol','visible','off');
set(gca,'tag','grafico','NextPlot','replace','userdata',[min(y) max(y) max(t)],...
   'Ylim',[min(y)-0.2*abs(min(y)) max(y)+0.2*abs(max(y))],...
   'Xlim',[0,max(t)]); 
crea_pop(1,'crea');
drawnow;

set(pid11(10:13),'visible','on');
stack.temp.time{1}=t;
drawnow;
pid1_cl;

watchoff;

Contact us