📄 msf1df_sim.m
字号:
function msf1df_sim(simulate,pnummt,pdenmt,pdeadmt,mnummt,mdenmt,mdeadmt,pdnummt,pddenmt,cnummt,cdenmt,...
order,x,y,Epsilon,subs,slbs,d_through_p,cnums,cdens)
global time TimeScale st_size plot_setpoint plot_disturb plot_effort setpoint_Enable
global disturb_Enable effort_Enable plot_IMC plot_IMC_sat plot_MSF clflag clmap
global gh1 gh2 old_handle keep numPs denPs Pdelay numMs denMs Mdelay Md Setpoint
global Disturb denFs numFs numPd denPd Ksp K Mnt
%Model
%-----------------------------------------------
[Ksp,K]=msfgain(cnums,cdens,Epsilon(1));
[numMs]=mt2poly(mnummt,y);
[denMs]=mt2poly(mdenmt,y);
[mdeadx,mnumT,mdenT]=mt2dt(mdeadmt,y);
%Process
%-----------------------------------------------
if isempty(pnummt) | isempty(pdenmt)
numPs=numMs;
denPs=denMs;
pdeadx=mdeadx;
pnumT=mnumT;
pdenT=mdenT;
else
[numPs]=mt2poly(pnummt,x);
[denPs]=mt2poly(pdenmt,x);
[pdeadx,pnumT,pdenT]=mt2dt(pdeadmt,x);
end
%if any(real(roots(denPs)))>0
% d_through_p=1;
%end
% inv(F(esetpoint)*F(eDis.) part----------
denF=[];
for i=1:order
denF(i,1)=Epsilon(1);
denF(i,2)=1;
end
[r,c]=size(denF);
numFs=denF(1,:);
for i=2:r
numFs=conv(numFs,denF(i,:));
end
if Epsilon==0
numFs=1;
end
denF=[];
for i=1:order
denF(i,1)=Epsilon(1);
denF(i,2)=1;
end
[r,c]=size(denF);
denFs=denF(1,:);
for i=2:r
denFs=conv(denFs,denF(i,:));
end
if Epsilon==0
denFs=1;
end
%IMC Controller
denCs=mt2poly(cnummt,y);
numCs=mt2poly(cdenmt,y);
%Approximated feed-back form controller
%[Csnum,Csden]=pid_tf(numMs,denMs,mnumT,mdenT,denCs,numCs,denFs);
denCs=conv(denCs,denFs);
% Disturbance lag------------------
numPd=mt2poly(pdnummt,x);
denPd=mt2poly(pddenmt,x);
%Delays and Saturation bounds
%---------------------------------------------------------
Mdelay=mdeadx;
Pdelay=pdeadx;
Satub=str2num(subs);
Satlb=str2num(slbs);
dimn=length(numMs);
dimd=length(denMs);
numMs=numMs/denMs(dimd);
denMs=denMs/denMs(dimd);
Md=denMs;
Md(dimd+1:9)=0;
Mnt=[];
for i=1:(dimd-1)
if (dimn-i+1)>0;
Mnt(dimd-i)=numMs(dimn-i+1);
else (dimn-i+1)<=0;
Mnt(dimd-i)=0;
end
end
Mnt(dimd:8)=0;
if length(K)<dimd;
Ktemp=K;
for i=1:dimd;
if i <=length(K);
K(1,dimd+1-i)=Ktemp(1,length(K)+1-i);
else
K(1,dimd+1-i)=0;
end
end
end
K(dimd+1:9)=0;
Setpoint=1;
Disturb=0;
if ~simulate
return
end
if isempty(keep) | ~keep
if exist('old_handle') & ~isempty(old_handle) & old_handle==gcf
figure(old_handle);
if ~isempty(x)
set(old_handle,'Name',['Step responses for process with current parameter x = [ ',...
num2str(x),' ]']);
else
set(old_handle,'Name','Step responses for process with perfect model');
end
clf
uicontrol(old_handle,...
'Style','push',...
'Position',[550 170 85 25],...
'String','Change Process',...
'Callback',['change_P1(''main'',x,Epsilon{1,1});']);
uicontrol(old_handle,...
'Style','push',...
'Position',[555 140 75 25],...
'String','Add&Remove',...
'Callback',['add_remove3(''main'');']);
uicontrol(old_handle,...
'Style','push',...
'Position',[555 110 75 25],...
'String','Change time',...
'Callback',['change_time2(''main'');']);
uicontrol(old_handle,...
'Style','push',...
'Position',[565 80 55 25],...
'String','Close',...
'Callback','close');
uicontrol(old_handle,...
'Style','push',...
'Position',[565 50 55 25],...
'String','Help',...
'Callback','sayhelp(4260)');
else
time=15; TimeScale=200; st_size=1; plot_setpoint=1; plot_disturb=0;
plot_effort=1; setpoint_Enable='on'; disturb_Enable='off';
effort_Enable='on'; plot_IMC=0; plot_IMC_sat=0; plot_MSF=1;
store=Epsilon; Etry=Epsilon;storex=x; clflag=1;
clmap=[1,0,0;1,1,0;1,0,1;0,0,1;1,1,1];
f=crfig(3,5,634,410,'MSF_SAT time responses','k','figure','on');
whitebg('white');
%colordef black;
uicontrol(f,...
'Style','push',...
'Position',[550 170 85 25],...
'String','Change Process',...
'Callback',['change_P1(''main'',x,Epsilon{1,1});']);
uicontrol(f,...
'Style','push',...
'Position',[555 140 75 25],...
'String','Add&Remove',...
'Callback',['add_remove3(''main'');']);
uicontrol(f,...
'Style','push',...
'Position',[555 110 75 25],...
'String','Change time',...
'Callback',['change_time2(''main'');']);
uicontrol(f,...
'Style','push',...
'Position',[565 80 55 25],...
'String','Close',...
'Callback','close');
uicontrol(f,...
'Style','push',...
'Position',[565 50 55 25],...
'String','Help',...
'Callback','sayhelp(4260)');
end
else % keep
if isempty(old_handle) | ~ishandle(old_handle)
errordlg('The original figure was gone');
return
end
figure(old_handle)
set(old_handle,'Name',['Step responses for process with current parameter x = [ ',...
num2str(x),' ]']);
end % keep
options = simset('SrcWorkspace','current');
if plot_MSF
if plot_setpoint
Setpoint=1;
Disturb=0;
[t]=sim('msf1df',time,options);
axis('auto');
if plot_effort
gh1=subplot(2,1,1);h=plot(t,simout(:,1),'r');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
gh2=subplot(2,1,2);h=plot(t,simout(:,2),'r');
title(['Control effort when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Control effort'); grid on;
hold on
elseif plot_disturb
gh1=subplot(2,1,1);h=plot(t,simout(:,1),'r');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
else
gh1=plot(t,simout(:,1),'r');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
end
end
if plot_disturb
Setpoint=0;
Disturb=1;
[t]=sim('msf1df',time,options);
axis('auto');
if plot_effort
gh1=subplot(2,1,1);h=plot(t,simout(:,1),'r');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
gh2=subplot(2,1,2);h=plot(t,simout(:,2),'r');
title(['Control effort when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Control effort'); grid on;
hold on
elseif plot_setpoint
gh2=subplot(2,1,2);h=plot(t,simout(:,1),'r');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
else
gh1=plot(t,simout(:,1)),'r';
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
end
end
end
if plot_IMC_sat
if plot_setpoint
Setpoint=1;
Disturb=0;
[t]=sim('imc1df',time,options);
axis('auto');
if plot_effort
gh1=subplot(2,1,1);h=plot(t,simout,'m');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
gh2=subplot(2,1,2);h=plot(t,effort,'m');
title(['Control effort when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Control effort'); grid on;
hold on
elseif plot_disturb
gh1=subplot(2,1,1);h=plot(t,simout,'m');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
else
gh1=plot(t,simout,'m');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
end
end
if plot_disturb
Setpoint=0;
Disturb=1;
[t]=sim('imc1df',time,options);
axis('auto');
%load sisomsf.mat;
if plot_effort
gh1=subplot(2,1,1);h=plot(t,simout,'m');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
gh2=subplot(2,1,2);h=plot(t,effort,'m');
title(['Control effort when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Control effort'); grid on;
hold on
elseif plot_setpoint
gh2=subplot(2,1,2);h=plot(t,simout,'m');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
else
gh1=plot(t,simout,'m');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
end
end
end
if plot_IMC
if plot_setpoint
Setpoint=1;
Disturb=0;
[t]=sim('unsat_imc1df',time,options);
axis('auto');
if plot_effort
gh1=subplot(2,1,1);h=plot(t,simout,'g');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
gh2=subplot(2,1,2);h=plot(t,effort,'g');
title(['Control effort when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Control effort'); grid on;
hold on
elseif plot_disturb
gh1=subplot(2,1,1);h=plot(t,simout,'g');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
else
gh1=plot(t,simout,'g');
title(['Setpoint Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
end
end
if plot_disturb
Setpoint=0;
Disturb=1;
[t]=sim('unsat_imc1df',time,options);
axis('auto');
%load sisomsf.mat;
if plot_effort
gh1=subplot(2,1,1);h=plot(t,simout,'g');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel(' '); ylabel('Output'); grid on;
hold on;
gh2=subplot(2,1,2);h=plot(t,effort,'g');
title(['Control effort when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Control effort'); grid on;
hold on
elseif plot_setpoint
gh2=subplot(2,1,2);h=plot(t,simout,'g');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
else
gh1=plot(t,simout,'g');
title(['Disturbance Step Response when Epsilon = ',num2str(Epsilon(1))])
xlabel('Time'); ylabel('Output'); grid on;
hold on;
end
end
end
y_limit=get(gh1,'Ylim');
y_scale=(y_limit(2)-y_limit(1))/6;
y_position=y_limit(1)+y_scale;
x_position=0.7*time;
if plot_MSF
subplot(gh1);
h=text(x_position,y_position,'* MSF');
set(h,'color','r');
y_position=y_position+y_scale;
end
if plot_IMC_sat
subplot(gh1);
h=text(x_position,y_position,'* constrained IMC');
set(h,'color','m');
y_position=y_position+y_scale;
end
if plot_IMC
subplot(gh1);
h=text(x_position,y_position,'* unconstrained IMC');
set(h,'color','g');
y_position=y_position+y_scale;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -