资源简介
学习模型预测控制,基本代码
代码片段和文件信息
function [sysx0strts] = mpcsfunc(tzyflagABCDPMQRTs)
%sfunction for mpc.
%
%By Yi Cao Cranfield University UK (c) 27 January 2009
%
persistent ssmpc ny
switch flag
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0
error(nargchk(1313nargin));
[nxnu]=size(B);
ny=size(C1);
if ~isequal(size(A) [nx nx]) || ~isequal(size(D)[ny nu])
error(‘Model matrix dimension does not match.‘);
end
if ~isscalar(P) || ~isscalar(M) || P<=0 || M <= 0 || M>P
error(‘P and M must be positive scalars and P>=M.‘)
end
if ~isequal(size(Q) [ny*P ny*P]) || ~isequal(size(R) [nu*M nu*M])
error(‘Weight matrix dimension does not match.‘)
end
if ~isscalar(Ts) || Ts<=0
error(‘dt must be a positive scalar.‘);
end
% MPC set-up
ssmpc=mpcsetup(ABCDPMQR);
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
% sizes.NumDiscStates = nx+ny;
sizes.NumOutputs = nu;
sizes.NumInputs = 2*ny; % output + setpoint
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
str = [];
x0 = [];
% offset=zeros(ny1);
% x0 = zeros(nx+ny1);
% du = zeros(nu1);
ts = [Ts 0];
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2
sys = [];
%%%%%%%%%%
% Output %
%%%%%%%%%%
case 3
sys = ssmpc(y(1:ny)‘y(ny+1:2*ny)‘);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9
sys = []; % do nothing
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error([‘unhandled flag = ‘num2str(flag)]);
end
end
function f=mpcsetup(ABCDpmQRx0u0)
% Input and output check
error(nargchk(810nargin));
error(nargoutchk(11nargout));
% dimension of the system
nx=size(A1);
[nynu]=size(D);
% precalculate the gain matrices of the online controller
[KPr] = predmat(ABCDpmQR);
% only the first instance is required
K1 = K(1:nu:);
Pr = Pr(1:nu:);
% default initial conditions
if nargin<9
x0=zeros(nx1);
end
if nargin<10
u0=zeros(nu1);
end
% the online controller
f = @ssmpc;
function u=ssmpc(yr)
% update state
x0 = A*x0 + B*u0;
% get the reference
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9353 2009-01-27 11:38 82493621mpCsimuli
文件 11531 2009-01-27 11:59 82493621mpCsimuli
文件 6536 2009-01-27 11:59 82493621mpCsimuli
文件 9080 2009-01-27 11:59 82493621mpCsimuli
文件 8823 2009-01-27 11:40 82493621mpCsimuli
文件 1327 2009-05-20 04:16 82493621mpCsimuli
文件 39285 2017-07-18 09:48 82493621mpCsimuli
文件 32203 2009-01-27 11:05 82493621mpCsimuli
文件 4339 2009-01-27 11:02 82493621mpCsimuli
文件 3985 2017-07-20 10:01 82493621mpCsimuli
文件 30915 2009-01-27 11:20 82493621mpCsimuli
文件 29327 2008-04-21 11:32 82493621mpCsimuli
文件 11147 2008-04-21 12:11 82493621mpCsimuli
文件 7084 2008-04-21 12:11 82493621mpCsimuli
文件 1327 2009-05-20 04:16 82493621mpCsimuli
文件 4696 2008-04-21 12:12 82493621mpCsimuli
文件 3819 2008-04-21 12:11 82493621mpCsimuli
目录 0 2017-07-03 16:26 82493621mpCsimuli
目录 0 2017-07-03 16:26 82493621mpCsimuli
目录 0 2017-07-03 16:26 82493621mpCsimuli
目录 0 2017-07-20 17:18 82493621mpCsimuli
目录 0 2017-07-03 16:26 82493621mpCsimuli
----------- --------- ---------- ----- ----
214777 22
- 上一篇:GPS-INS.zip
- 下一篇:社交接口设计文档 适合小白参考
评论
共有 条评论