• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: 其他
  • 标签: MPC例子  

资源简介

基于状态空间的模型预测MPC控制器的设计,适用于初学者,有需要的可以来看看

资源截图

代码片段和文件信息

function f=mpcsetup(ABCDpmQRx0u0)
% MPCSETUP  Set-up State Space MPC controller
%
%   SSMPC=MPCSETUP(ABCDPMQRX0U0) returns a function handle for a
%   state space model predictive control for the state space model
%   x(k+1) = Ax(k) + Bu(k)
%   y(k)   = Cx(k) + Du(k)
%   with predictive horizon P and moving horizon M performance weights of
%   output Q and of input R initial state X0 and initial control U0.
%
%   SSMPC is the online controller which can be called as follows 
%
%   U = SSMPC(YREF) returns the control input U (nu by 1) according to
%   current measured output Y (1 by ny) and future reference REF (nr by
%   ny nr>=1). 
%
%   The MPC minimize the following performance criterion:
%
%   J = min Y‘QY + U‘RU
%
%   The online controller is implemented as a nested function so that the
%   state of the internal model can be kept inside of the function. This
%   simplifies the input and output interface of the online controller.
%
% See also: mpc dmc

% Version 1.0 by Yi Cao at Cranfield University on 20 April 2008

% Example: 2-CSTR model
%{
% Six-state model
A=[ 0.1555  -13.7665   -0.0604         0         0         0
    0.0010    1.0008    0.0068         0         0         0
         0    0.0374    0.9232         0         0         0
    0.0015   -0.1024   -0.0003    0.1587  -13.6705   -0.0506
         0    0.0061         0    0.0006    0.9929    0.0057
         0    0.0001         0         0    0.0366    0.9398];
Bu=[0.0001       0
         0       0
   -0.0036       0
         0  0.0001
         0       0
         0 -0.0028];
Bd=[      0         0
          0         0
     0.0013         0
          0         0
          0         0
          0    0.0008];
C=[0 362.995 0 0 0 0
   0 0 0 0 362.995 0];
D=zeros(22);
% Prediction horizon and moving horizon
p=10;
m=3;
% Performance wights
Q=1.5*eye(2*p);
R=eye(2*m);
% MPC set-up
ssmpc=mpcsetup(ABuCDpmQR);
% Simulation length and variables for results
N=1500;
x0=zeros(61);
Y=zeros(N2);
U=zeros(N2);
% Predefined reference
T=zeros(N2);
T(10:N:)=1;
T(351:N:)=3;
T(600:N:)=5;
T(1100:N:)=3;
% Simulation
for k=1:N
    % Process disturbances
    w=Bd*(rand(21)-0.5)*2;
    % Measurements noise
    v=0.01*randn(21);
    % actual measurement
    y=C*x0+v;
    % online controller
    u=ssmpc(yT(k:end:));
    % plant update
    x0=A*x0+Bu*u+w;
    % save results
    Y(k:)=y‘;
    U(k:)=u‘;
end
t=(0:N-1)*0.1;
subplot(211)
plot(tYtT‘r--‘‘linewidth‘2)
title(‘output and setpoint‘)
ylabel(‘temp C^\circ‘)
legend(‘T_1‘‘T_2‘‘Ref‘‘location‘‘southeast‘)
subplot(212)
stairs(tU‘linewidth‘2)
legend(‘u_1‘‘u_2‘‘location‘‘southeast‘)
title(‘input‘)
ylabel(‘flow rate m^3/s‘)
xlabel(‘time s‘)
%}

% Input and output check
error(nargchk(810nargin));
error(nargoutchk(11nargout));

% dimension of the system
nx=size(A1);
[nynu]=size(D);

%

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4696  2008-04-22 00:12  mpcsetup.m

     文件       3819  2008-04-22 00:11  ssmpctutorial.m

----------- ---------  ---------- -----  ----

                 8515                    2


评论

共有 条评论

相关资源