Compare the closed-loop response of a linear system

Compare the closed-loop response with PID control and with constant-gain
feedback.
Uses the statespace class.
------------------------------------------------------------------------
See also statespace, getabcd, ND2SS, PID, SS2ND, TResp
------------------------------------------------------------------------

Contents

%---------------------------------------------------------------------------
%   Copyright (c) 1997, 2014 Princeton Satellite Systems, Inc.
%   All rights reserved.
%---------------------------------------------------------------------------

default parameters

%-------------------
T         = 8;                      % end time  [sec]
dT        = .001;                   % time-step [sec]
kF        = 1;                      % forward gain
kP        = 90;                     % proportional gain
kR        = 5;                      % rate gain
kI        = 3.5;                    % integral gain
omegaR    = 18;                     % rate cutoff
KG        = 1;                      % constant controller gain
[a,b,c,d] = ND2SS( 4, [1 0.5 0] );   % plant state space matrices
g         = statespace(a,b,c,d);    % plant state space system

Plant info

%-----------
[a,b,c,d] = getabcd(g);
[nU,nY]   = size(d);
if( nU > 1 )
   b = b(:,1);
   d = d(:,1);
end
if( nY > 1 )
   c = c(1,:);
   d = d(1,:);
end
[np,dp] = SS2ND(a,b,c,d);

Constant gain closed-loop

%--------------------------
numCG             = np*KG;
denCG             = dp + [zeros(1,length(dp)-length(np)), np];
[aCG,bCG,cCG,dCG] = ND2SS(numCG,denCG);
gCG               = statespace(aCG,bCG,cCG,dCG);

Step-response of constant gain closed-loop

%-------------------------------------------
[xCG,yCG]         = TResp( gCG, zeros(length(aCG),1), ones(1,floor(T/dT)), dT, T );

Design PID controller

%-----------------------
gK                    = PID( kF, kP, kR, kI, omegaR );

PID closed-loop system

%------------------------
[ak,bk,ck,dk]         = getabcd( gK );
[nk,dk]               = SS2ND(ak,bk,ck,dk);
npnk                  = conv(np,nk);
dpdk                  = conv(dp,dk);
numPID                = npnk;
denPID                = dpdk + [zeros(1,length(dpdk)-length(npnk)), npnk];
[aPID,bPID,cPID,dPID] = ND2SS(numPID,denPID);
gPID                  = statespace(aPID,bPID,cPID,dPID);

step-response of lead-lag closed-loop

%--------------------------------------
[xPID,yPID,t,u] = TResp( gPID, zeros(length(aPID),1), ones(1,floor(T/dT)), dT, T );

plot

%-----
Plot2D(t,[yCG;yPID], 'Time (sec)', 'Output', 'PID Demo');
legend('constant gain','with pid control');

%--------------------------------------
% $Date$
% $Id: 6d7ea5792ccbefe446787798e78e358d436a6e91 $