Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(Script file)
%
% Implements unconstrained MPC for stable SISO discrete-time system
% defined as LTI object. Offset-free tracking included.
%
% The following are editable parameters (most have defaults):
% Tref: Time constant of exponential reference trajectory
% Ts: Sampling interval
% plant: Plant definition (discrete-time SISO LTI object)
% model: Model definition (discrete-time SISO LTI object)
% P: Vector of coincidence points
% M: Control horizon
% tend: Duration of simulation
% setpoint: Setpoint trajectory (column vector) - length must exceed
% no of steps in simulation by at least max(P).
% umpast, uppast, ympast, yppast: Initial conditions of plant & model.
%
% Assumes Matlab 5.3. Uses Control Toolbox LTI object class.
% No other toolboxes required.
numm=1;
denm = [1.0000 -1.6500 0.5700];
plant = tf(nump,denp,Ts);
if Tref == 0,
tend = 100*Ts;
else
tend = 10*Tref; % Duration of simulation (default 10*Tref)
end
tend = 200;
nsteps = floor(tend/Ts); % (Number of steps in simulation).
tvec = (0:nsteps-1)'*Ts; % Column vector of time points (first one 0)
% Initial conditions:
umpast = zeros(ndenm,1);
uppast = zeros(ndenp,1);
ympast = zeros(ndenm,1); % For model response
yppast = zeros(ndenp,1); % For plant response
%%%%%%%%%%%%%%%% SIMULATION:
for k=1:nsteps,
% Simulate plant:
% Update past plant inputs
uppast = [uu(k);uppast(1:length(uppast)-1)];
yp(k+1) = -denp(2:ndenp+1)*yppast+nump(2:nnump+1)*uppast; % Simulation
% Update past plant outputs
yppast = [yp(k+1);yppast(1:length(yppast)-1)];
% Simulate model:
% Update past model inputs
umpast = [uu(k);umpast(1:length(umpast)-1)];
ym(k+1) = -denm(2:ndenm+1)*ympast+numm(2:nnumm+1)*umpast; % Simulation
% Update past model outputs
ympast = [ym(k+1);ympast(1:length(ympast)-1)];
end % of simulation
figure
subplot(211)
% Plot output, solid line and set-point, dashed line:
plot(tvec,yp(1:nsteps),'-',tvec,setpoint(1:nsteps),'--');
grid; title('Plant output (solid) and set-point (dashed)')
xlabel('Time')
subplot(212)
% plot input signal as staircase graph:
stairs(tvec,uu,'-');
grid; title('Input')
xlabel('Time')