Code covered by the BSD License  

Highlights from
MIMOtool

image thumbnail

MIMOtool

by

 

12 Nov 2001 (Updated )

Multi Input Multi Output Systems Toolbox

lqs_1.m
function lqs_1;

global stack;

A=stack.general.A; B=stack.general.B; 
C=stack.general.C; D=stack.general.D;
%--------------------------------------------------------------------
%trasformazione del sistema: nuovo stato (= nuova uscita) [x1,x2,x3]'
%ind_x1=indice stati selezionati con integratori
%ind_x2=indice stati selezionati senza integratori
%ind_x1=indice rimanenti stati non selezionati

ind_x1=find(stack.temp.outsi==1);
ind_x2=find(stack.temp.outs-stack.temp.outsi==1);
ind_x3=find(stack.temp.outs==0);
ind=[ind_x1;ind_x2;ind_x3];

%z=Tx con z nuovo vettore di stato
% z' = T*A*inv(T)z + TBu
% y  = C*inv(T)z   + Du
% ( questo tipo di sintesi  applicata solo se C=I e D=0)
T=zeros(size(A));
for i=1:length(ind), T(i,ind(i))=1; end;

At=T*A*inv(T); Bt=T*B; Ct=C*inv(T); Dt=D;

%--------------------------------------------------------------------
%costruzione del sistema aumentato con gli integratori richiesti
l_x1=length(ind_x1); l_x2=length(ind_x2); l_x3=length(ind_x3);

if l_x1==0  %non ci sono uscite che devono essere integrate
   Atilde=At; Btilde=Bt; Ctilde=Ct; Dtilde=Dt;
else        %il sistema deve essere aumentato
   l=length(ind);
   Atilde=zeros(l+l_x1,l+l_x1);
   Atilde(1:l_x1,l_x1+1:2*l_x1)=eye(l_x1);
   Atilde(l_x1+1:l+l_x1,l_x1+1:l+l_x1)=At;
   Btilde=[zeros(l_x1,size(Bt,2));Bt];
   Ctilde=zeros(l,l+l_x1);
   Ctilde(1:l_x1,1:l_x1)=eye(l_x1);
   Ctilde(l_x1+1:l,2*l_x1+1:l+l_x1)=eye(l_x2+l_x3);
   Dtilde=zeros(l,size(Btilde,2));
end;
Ptilde=pck(Atilde,Btilde,Ctilde,Dtilde);


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


%-----------aggiornamento variabili temporanee---------------
Q=eye(size(Atilde));
R=eye(size(Btilde,2));

stack.temp.T=T;            %matrice di trasformazione
stack.temp.Ptilde=Ptilde;  %sistema aumentato in forma packed
stack.temp.Q=Q;
stack.temp.R=R;
stack.temp.flagQ=0;   %flag di memorizzazione di Q
stack.temp.flagR=0;   %flag di memorizzazione di R
%-------------------------------------------------

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

sizetext=.3;sizetext1=.195;sizefor=jsz/2+.55;

lq(1)=uicontrol('style','frame',...
   'units','normalized','position',[0.035 0.835 0.11 0.11],...
   'backgroundcolor',[1 1 1],'Visible','off','tag','FQ');

lq(2)=uicontrol('style','frame',...
   'units','normalized','position',[0.165 0.835 0.11 0.11],...
   'backgroundcolor',[1 1 1],'Visible','off','tag','FR');

ist0='set(findobj(''tag'',''nota''),''visible'',''off'');';
ist01='delete(findobj(''tag'',''inf''));';
ist1='set(findobj(''tag'',''FQ''),''visible'',''off'');';
ist2='set(findobj(''tag'',''FR''),''visible'',''off'');';
ist3='set(findobj(''tag'',''FQ''),''visible'',''on'');';
ist4='set(findobj(''tag'',''FR''),''visible'',''on'');';
ist5='set(findobj(''tag'',''BREG''),''visible'',''off'');';
ist6='set(findobj(''tag'',''BSAVE''),''visible'',''on'',''enable'',''on'');';

lq(3)=uicontrol('style','push',...
   'unit','normalized','position',[0.05 0.85 0.08 0.08],...
   'fontunits','normalized','fontsize',.5,'fontweight','bold',...
   'Horizontalalignment','center','string','Q',...
   'callback',[ist0,ist01,ist2,ist3,'setmatrix(stack.temp.Q,''Q'');',ist5,ist6],'tag','BQ');
    
lq(4)=uicontrol('style','push',...
   'unit','normalized','position',[0.18 0.85 0.08 0.08],...
   'fontunits','normalized','fontsize',.5,'fontweight','bold',...
   'Horizontalalignment','center','string','R',...
   'callback',[ist0,ist01,ist1,ist4,'setmatrix(stack.temp.R,''R'');',ist5,ist6],'tag','BR');

lq(5)=uicontrol('style','push',...
   'unit','normalized','position',[0.5 0.85 0.45 0.08],...
   'fontunits','normalized','fontsize',.5,'fontweight','bold',...
   'Horizontalalignment','center','string','COMPUTE LQ - SERVO',...
   'callback','lqs_2;','tag','BREG');

lq(6)=uicontrol('style','push',...
   'unit','normalized','position',[0.5 0.85 0.45 0.08],...
   'fontunits','normalized','fontsize',.5,'fontweight','bold',...
   'Horizontalalignment','center','string','SAVE MATRIX',...
   'enable','off','callback','salvalqs;','tag','BSAVE');

lq(7)=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','BottBC',...
   'TooltipString','Back to the previous window',...
   'userdata',sprintf('feval(''back_syn'',''lqs0'',%u,''T'',''Ptilde'',''Q'',''R'',''flagQ'',''flagR'')',length(stack.temp.handles)),...
   'callback',sprintf('if stack.general.K_flag messag(gcf,''kns'',''back'');else back_syn(''lqs0'',%u,''T'',''Ptilde'',''Q'',''R'',''flagQ'',''flagR'');end;',length(stack.temp.handles)));

lq(8)=uicontrol('style','push','unit',...
   'normalized','position',[0.2 0.05 0.14 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'string','CLOSE','Horizontalalignment','center',...
   'userdata','back_syn(''syn0'',0,''outs'',''outsi'',''T'',''Ptilde'',''Q'',''R'',''flagQ'',''flagR'');',...
   'TooltipString','Back to the main SYNTHESIS window','tag','BottBC',...
   'callback','if stack.general.K_flag messag(gcf,''kns'',''close'');else back_syn(''syn0'',0,''outs'',''outsi'',''T'',''Ptilde'',''Q'',''R'',''flagQ'',''flagR'');end;');

lq(9)=uicontrol('style','push',...
   'unit','normalized','position',[0.39 0.05 0.275 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'TooltipString','Evaluate the computed Controller',...
   'Horizontalalignment','center','string','EVALUATION',...
   'callback','valuta;','tag','BEVAL','enable','off');

lq(10)=uicontrol('style','push',...
   'unit','normalized','position',[0.675 0.05 0.275 0.12],...
   'fontunits','normalized','fontsize',.35,'fontweight','bold',...
   'TooltipString','Open the SIMULINK Closed-Loop-System',...
   'Horizontalalignment','center','string','SIMULATION',...
   'callback','simula;','tag','BSIMU','enable','off');

drawnow;

lq(11)=uicontrol('style','frame',...
   'units','normalized','position',[0.15 0.27 0.7 0.48],...
   'backgroundcolor',[1 1 1],'tag','nota');

str=['Insert the matrices Q and R of the cost ',...
     'function J that will be minimized :'];
lq(12)=uicontrol('style','text',...
   'units','normalized','position',[.18 .59 .64 0.13],...
   'fontunits','normalized','fontsize',sizetext,'fontweight','bold',...
   'backgroundcolor',[1 1 1],'foregroundcolor','white',...
   'HorizontalAlignment','left','tag','nota',...
   'string',str);

lq(13)=uicontrol('style','text',...
   'units','normalized','position',[.17 .51 .66 0.07],...
   'fontunits','normalized','fontsize',sizefor,'fontweight','bold',...
   'backgroundcolor',[1 1 1],'foregroundcolor','white',...
   'HorizontalAlignment','center','tag','nota',...
   'string','J = Integral {  X'' Q X + U'' R U  } dt');

str=['where X and U are respectively the State and Control vector',...
      ' of the system built according to the previous ',...
      'requirements (press Help on context for more details).'];
lq(14)=uicontrol('style','text',...
   'units','normalized','position',[.18 .29 .64 0.2],...
   'fontunits','normalized','fontsize',sizetext1,'fontweight','bold',...
   'backgroundcolor',[1 1 1],'foregroundcolor','white',...
   'HorizontalAlignment','left','tag','nota',...
   'string',str);

set(lq(12),'foreground','black');
set(lq(13),'foreground','red');
set(lq(14),'foreground','black');

%aggiornamento handles temporanei
stack.temp.handles=[stack.temp.handles,lq];

Contact us