AMESim和matlab联合仿真。使用PID控制有一个s函数编程求问。
以下这个程序求大神解释一下。function = spacemodel(t,x,u,flag)
switch flag,
case 0,
=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function =mdlInitializeSizes
sizes = simsizes;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 4;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0= [];
str = [];
ts= ;
function sys=mdlOutputs(t,x,u)
% r=1;
% dr=0;
% ddr=0;
% dddr=0;
% f=3;
% A=1;
% r=A*sin(2*pi*f*t);
% dr=A*2*pi*f*cos(2*pi*f*t);
% ddr=-A*(2*pi*f)^2*sin(2*pi*f*t);
% dddr=-A*(2*pi*f)^3*cos(2*pi*f*t);
% r=u(1);
% dr=u(2);
% % ddr=u(3);
% dddr=u(4);
% x1=u(1)-u(5);
% x2=u(2)-u(6);
% x3=u(3)-u(7);
x1=u(1);
x2=u(2);
x3=u(3);
% x4=u(4);
% if abs(x1)>=0.01
% K=600;
% else if 0.005<=abs(x1)<0.01
% K=400;
% else K=200;
% % else ifabs(x1)<0.01
% % K=200;
% % else ifabs(x1)<0.01
% % K=500;
% % end
% % end
% end
% end
K=300;
% kesai=0.2;
% wn=156;
c1=7561;
%c2=62;
c2=18;
%c2=360;
% c1=7885;
% c2=124;
s=c1*x1+c2*x2+x3;
M=2;
if M==1 %PD
%ut=1*x1+0.3*x2+0.3*x4;
ut=K*x1;
elseifM==2
if x1*s>0
ut=K*x1+50*sign(s);
else x1*s<0
ut=-K*x1+50*sign(s);
%ut=(2566*x2+30*x3+10*sign(s))/(11*156^2);
%u=10*sign(s);
%if s>0
%ut=((c1-wn^2)*x2+(c2-2*kesai*wn)*x3-0.1)/(wn^2);
%ut=(0.3*wn*x2+25);
%ut=0.1;
%else s<0
%ut=((c1-wn^2)*x2+(c2-2*kesai*wn)*x3+0.1)/(wn^2);
%ut=(0.3*wn*x2-25);
%ut=-0.1;
%end
%ut=(-(c1-wn^2)*x2-(c2-2*kesai*wn)*x3+0.1*sign(s)+200*s)/(wn^2)
%sunyanshi
%ut=((c1-wn^2)*x2+(c2-2*kesai*wn)*x3+1*sign(s)+0.00001*s+dddr+2*kesai*wn*ddr+wn^2*dr)/(0.12);
% ut=((c1-wn^2)*x2+(c2-2*kesai*wn)*x3+50*sign(s)+0.01*s++dddr+2*kesai*wn*ddr+wn^2*dr)/(1.2*156^2);
%ut=((c1-wn^2)*x2+10*sign(s)+10*s+dddr+2*kesai*wn*ddr)/(0.12);
%ut=((c1-wn^2)*x2+(c2-2*kesai*wn)*x3+10*(s/(abs(s)+10))+0.5*s+dddr+2*kesai*wn*ddr)/(0.12);%lianxuhanshu
end
%if ut>100
%ut=100;
%elseif ut<-100;
%ut=-100;
%e=r-y
%ut=(-(c1-wn^2)*x2-(c2-2*kesai*wn)*x3-0.1*sign(s)-200*s)/(wn^2)
%e=y-r
%
end
sys(1)=ut;
sys(2)=s;
sys(3)=x1;
页:
[1]