急!关于连续pid的S函数
各位大侠,本人是s函数的初学者,编了个pid控制的S函数,运行怎么不对啊?代码如下:
function = simpid(t,x,u,flag,kp,ki,kd)
switch flag,
case 0,
=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,kp,ki,kd);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function =mdlInitializeSizes(t,x,u,flag,kp,ki,kd)
sizes = simsizes;
sizes.NumContStates= 3;
sizes.NumDiscStates= 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
x0= ;
str = [];
ts= ;
function sys=mdlDerivatives(t,x,u)
x(2)=u;
x1dot=x(2);
x2dot=x(3);
sys =;
function sys=mdlUpdate(t,x,u)
sys = [];
function sys=mdlOutputs(t,x,u,kp,ki,kd)
sys =kp*x(2)+ki*x(1)+kd*x(3);
function sys=mdlTerminate(t,x,u)
sys = []; 你的输入是什么 误差?
页:
[1]