%function [yp,u,ym]=scmpc(pmod,imod,ywt,uwt,blocks,...
function [y,u,xi,xp,yp]=scmpc_912_1(pmod,imod,ywt,uwt,blocks,...
p,tend,setpts,ulim,ylim, ...
Kest,ydist,mdist,umdist,udist,yex,uex,xiex,xpex,ypex)
%SCMPC Simulate CL systems for constrained problems.
% [y,u,ym]=scmpc(pmod,imod,ywt,uwt,M,P,tend, ...
% r,ulim,ylim,Kest,z,v,w,wu)
% SCMPC designs an MPC-type controller for constrained problems
% and simulates the closed-loop system with hard constraints
% (inputs and outputs) using quadratic programming.
% NOTE: This version does not anticipate setpoint changes. The
% current setpoint is assumed to be constant over the
% prediction horizon.
% See SCMPCR for an alternative approach.
% Inputs:
% pmod: plant model in MOD format
% imod: internal model in MOD format -- used as basis for
% controller design.
% ywt: Penalty weighting for setpoint tracking.
% uwt: Penalty weighting for changes in manipulated variables.
% M: Number of moves OR sequence of blocking factors.
% P: Length of prediction horizon.
% tend: duration of the simulation.
% r: setpoint sequence, one column for each output.
% ulim: [Ulow Uhigh delU]. NOTE: delU must be finite.
% ylim: [Ylow Yhigh].
% Kest: Estimator gain matrix.
% z: Measurement noise.
% v: Measured disturbance (for feedforward control).
% w: General unmeasured disturbance.
% wu: Unmeasured disturbance added to manipulated variables.
% Outputs: y (system response), u (manipulated variables),
% ym (model response).
% See also PLOTALL, PLOTEACH, SMPCCL, SMPCCON, SMPCEST, SMPCSIM.
% Copyright 1994-2003 The MathWorks, Inc.
% $Revision: 1.1.6.2 $
% +++ Check input arguments for errors and set default values. +++
if nargin == 0
disp('USAGE: [y,u,ym]=scmpc(pmod,imod,ywt,uwt,M,P,tend, ...')
disp(' r,ulim,ylim,Kest,z,v,w,wu)')
return
elseif nargin < 8
error('Too few input arguments')
end
if isempty(pmod) | isempty (imod)
error('Plant and internal model must be in non-empty MOD format.')
end
% Get plant, internal, and reference models in state-space form.
[phip,gamp,cp,dp,minfop]=mod2ss(pmod);
tsamp=minfop(1);
np=minfop(2);
nup=minfop(3);
nvp=minfop(4);
nwp=minfop(5);
mp=nup+nvp+nwp;
nymp=minfop(6);
nyup=minfop(7);
nyp=nymp+nyup;
[phii,gami,ci,di,minfoi]=mod2ss(imod);
ni=minfoi(2);
nui=minfoi(3);
nvi=minfoi(4);
mi=nui+nvi;
nwi=minfoi(5);
if nwi > 0 % Strip off unmeasured disturbance model if necessary.
gami=gami(:,1:mi);
di=di(:,1:mi);
end
nymi=minfoi(6);
nyui=minfoi(7);
nyi=nymi+nyui;
% Check for errors and inconsistencies in the models.
if any(any(dp(:,1:nup)))
error(['PMOD: first nu=',int2str(nup),' columns of D must be zero.'])
elseif any(any(di(:,1:nui)))
error(['IMOD: first nu=',int2str(nui),' columns of D must be zero.'])
end
if minfoi(1) ~= tsamp
error('PMOD and IMOD have different sampling periods')
elseif nui ~= nup
error('PMOD and IMOD must have equal number of manipulated variables')
elseif nvi ~= nvp
error('PMOD and IMOD must have equal number of measured disturbances')
elseif nymi ~= nymp
error('PMOD and IMOD must have equal number of measured outputs')
end
if isempty(p)
p=1;
elseif p < 1
error('Specified prediction horizon is less than 1')
end
if isempty(ywt)
ywt=ones(1,nyi);
nywt=1;
else
[nywt,ncol]=size(ywt);
if ncol ~= nyi | nywt <= 0
error('YWT is wrong size')
end
if any(any(ywt < 0))
error('One or more elements of YWT are negative')
end
end
if isempty(uwt),
uwt=zeros(1,nui);
nuwt=1;
else
[nuwt,ncol]=size(uwt);
if ncol ~= nui | nuwt <= 0
error('UWT is wrong size')
end
if any(any(uwt < 0))
error('UWT is negative')
end
end
if isempty(setpts)
nset=1;
setpts=zeros(1,nyi);
else
[nset,ncol]=size(setpts);
if ncol ~= nyi
error('Setpoint input matrix has incorrect dimensions')
end
end
if isempty(blocks)
blocks=ones(1,p);
nb=p;
else
[nrow,nb]=size(blocks);
if nrow ~= 1 | nb < 1 | nb > p
error('M vector is wrong size')
end
if any(blocks < 1)
error('M contains an element that is < 1')
end
if nb == 1
% This section interprets "blocks" as a number of moves, each
% of one sampling period duration.
if blocks > p
disp('WARNING: M > P. Truncated.')
nb=p;
elseif blocks <= 0
disp('WARNING: M <= 0. Set = 1.')
nb=1;
else
nb=blocks;
end
blocks=[ones(1,nb-1) p-nb+1];
else
% This section interprets "blocks" as a vector of blocking factors.
sumblocks=sum(blocks);
if sumblocks > p
disp('WARNING: sum(M) > P.')
disp(' Moves will be truncated at P.')
nb=find(cumsum(blocks) > p);
nb=nb(1);
blocks=blocks(1,1:nb);
elseif sumblocks < p
nb=nb+1;
blocks(nb)=p-sumblocks;
disp('WARNING: sum(M) < P. Will extend to P.')
end
end
end
% Check the constraint specifications. First set up some indices to pick out
% certain columns of the ulim and ylim matrices.
iumin=[1:nui]; % Points to columns of ulim containing umin.
iumax=iumin+nui; % Points to columns of ulim containing umax.
idumax=iumax+nui; % Points to columns of ulim containing delta u max.
iymin=[1:nyi]; % Points to columns of ylim containing ymin.
iymax=iymin+nyi; % Points to columns of ylim containing ymax.
% Now check the values supplied by the user for consistency.
if nargin > 8
if isempty(ulim)
ulim=[-inf*ones(1,nui) inf*ones(1,nui) 1e6*ones(1,nui)];
else
[nulim,ncol]=size(ulim);
if ncol ~= 3*nui | nulim <= 0
error('ULIM matrix is empty or wrong size.')
elseif any(any(ulim(:,idumax) < 0))
error('A constraint on DELTA U was < 0')
elseif any(any(ulim(:,iumax)-ulim(:,iumin) < 0))
error('A lower bound on U was greater than its upper bound')
end
end
else
ulim=[-inf*ones(1,nui) inf*ones(1,nui) 1e6*ones(1,nui)];
end
% When using the DANTZGMP routine for the QP problem, we must have all
% bounds on delta u finite. A bound that is finite but large can cause
% numerical problems. Similarly, it can't be too small.
% The following loop checks for this.
ichk=0;
for i=idumax
ifound=find(ulim(:,i) > 1e6);
if ~ isempty(ifound)
ichk=1;
ulim(ifound,i)=1e6*ones(length(ifound),1);
end
ifound=find(ulim(:,i) < 1e-6);
if ~ isempty(ifound)
ichk=1;
ulim(ifound,i)=1e-6*ones(length(ifound),1);
end
end
if ichk
disp('One or more constraints on delta_u were > 1e6 or < 1e-6.')
disp('Modified to prevent numerical problems in QP.')
end
if nargin > 9
if isempty(ylim)
ylim=[-inf*ones(1,nyi) inf*ones(1,nyi)];
else
[nylim,ncol]=size(ylim);
if ncol ~= 2*nyi | nylim <= 0
error('YLIM matrix is wrong size')
elseif any(any(ylim(:,iymax)-ylim(:,iymin) < 0))
error('A lower bound on y was greater than its upper bound')
end
end
else
ylim=[-inf*ones(1,nyi) inf*ones(1,nyi)];
end
if nargin > 10
if isempty(Kest)
Kest=[zeros(ni,nymi)
eye(nymi)
zeros(nyui,nymi)];
else
[nrow,ncol]=size(Kest);
if nrow ~= ni+nyi | ncol ~= nymi
error('Estimator gain matrix is wrong size')
end
end
else
Kest=[zeros(ni,nymi)
eye(nymi)
zeros(nyui,nymi)];
end
% +++ If there are unmeasured outputs, add columns of zeros
% to the estimator gain matrix.
if nyup > 0
Kest=[Kest zeros(ni+nyi,nyup)];
end
if nargin > 11
if isempty(ydist)
MPC.rar_MPC_MPC 控制_MPC matlab_matlab mpc
版权申诉
164 浏览量
2022-09-14
19:18:32
上传
评论
收藏 13KB RAR 举报
小贝德罗
- 粉丝: 70
- 资源: 1万+
最新资源
- unity控制对象移动.rar
- TortoiseSVN-1.14.3.29387-x64-svn-1.14.2
- jdk-8u411-macosx-aarch64.dmg
- docker安装.rar
- 美赛数学建模算法-使用Matlab实现常微分方程OridinaryDifferentialEquation-国赛-题解.zip
- FileUploadTestController.java
- 基于MATLAB的数字水印系统源码+GUI操作界面+全部数据资料+使用文档(高分课程设计).zip
- 美赛数学建模算法-使用Matlab实现非线性规划NonLinearProgramming-国赛-题解.zip
- linux安装java8环境资源包
- pcb问题和3D猴制作外壳.7z
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈