资源简介
区间预测控制原代码,希望可以帮到大家 有约束无约束 主程序
代码片段和文件信息
%% State-space MPC set-up
% 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.
%
% the expression of SSMPC:
% SSMPC=MPCSETUP(ABCDPMQRX0U0);
%% Online controller
% The returned function handle from the MPC setup program is an online
% controller SSMPC. The controller is called by proving two inputs:
% current measurement Y and future reference Ref. On return it produces
% the optimal input U for next step:
% U = SSMPC(YRef) rolling optimization
%% A two-CSTR example
% A two-CSTR (Continuous Stired Reaction Tank) process is shown as follows.
% A linear state space of the model is developed for the plant. The model
% has six states two inputstwo input and two disturbances .
% The discrete model with sampling rate 0.1 s is as follows:
A=[ 0 0 0;
0 0.3679 0;
0 1.0000 0];
Bu=[ 1 0;
0 1;
0 0];
Bd=[ 0.050 0 ;
0 0.0817 ;
0 1 ];
C=[ 0.7 0.0290 -0.0107;
0.1057 3.6157 0];
%D=[0 0;0 0]
D=zeros(22);
%% MPC parameters
% The MPC controller is configured with following parameters.
% Prediction horizon and moving horizon
p=20;
m=4;
% Performance wights
%Q and R are diagonal matrices
Q=0.1*eye(2*p);
R=10*eye(2*m);
%% MPC set-up(建立函数)
% The MPC controller is set-up by calling SSMPCSETUP:
% ssmpc =@mpcsetup/ssmpc
ssmpc=mpcsetup(ABuCDpmQR);
%% Simulation
% Simulation length and variables for results
N=600;
x0=zeros(31);
%Y is a null matrix of 600*2
Y=zeros(N2);
%U is a null matrix of 600*2
U=zeros(N2);
% Predefined reference
%W is a null matrix of 600*2
W=zeros(N2);
W(1:N1)=0;
W(1:N2)=5.25;
%simulation
for k=1:N
%Process disturbances
%rand(21)is a random matrix of 2*1
w=Bd*(rand(21)-0.5)*2;
%Measurements noise
%randn(21)is a random matrix with normal distribution of 2*1
v=0.01*randn(21);
% actual measurement
%y=c*x(k)+d*u(k)
y=C*x0+v;
% online controller
u=ssmpc(yW(k:end:)‘);
%plant update
%x(k+1)=A*x(k)+Bu(k)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3509 2013-12-02 15:39 fanglujie.m
文件 4758 2013-12-02 11:16 mpcsetup.m
----------- --------- ---------- ----- ----
8267 2
评论
共有 条评论