- 积分
- 0
- 注册时间
- 2011-12-15
- 仿真币
-
- 最后登录
- 1970-1-1
|
我是做机械电子控制的。现在想在控制框图中编写s函数。其中在S函数中调用了其他的函数。
控制流程图如下:
我编写了以下s函数:
function [sys,x0,str,ts]=inversePImodel(t,x,u,flag)
switch flag
case 0 %initialize the conditions
[sys,x0,str,ts]=mdlInitializeSizes;
case 1 %compute the derivatives of continuous state
sys=mdlDerivatives(t,x,u);
case 2 %update the state
sys=mdlUpdate(t,x,u);
case 3 %compute the output
sys=mdlOutput(t,x,u);
case 4 %get the next sampling point
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9 %complete computation
sys=mdlTerminate(t,x,u);
otherwise %false input
error(['unhandled flag=',num2str(flag)]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [sys,x0,str,ts]=mdlInitializeSizes()
sizes=simsizes;
sizes.NumContStates=0;
sizes.NumDiscStates=0;
sizes.NumOutputs=1;
sizes.NumInputs=1;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=1;
sys=simsizes(sizes);
x0=[];
str=[];
ts=[1 0];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sys=mdlDerivatives(t,x,u)
sys=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sys=mdlUpdate(t,x,u)
sys=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sys=mdlOutput(t,x,u)
%F=[1 2 3 4;5 6 7 8;9 10 11 12]';
r=[0.0299 0.0253 0.0145 1.9702 1.8274 0.0050];
alpha=[2.2062 0.8445 0.7982 0.0244 0 0.7075];
sys=[alpha(1)*stopoperator(r(1),u)+alpha(2)*stopoperator(r(2),u)+alpha(3)*stopoperator(r(3),u)+alpha(4)*stopoperator(r(4),u)+alpha(5)*stopoperator(r(5),u)+alpha(6)*stopoperator(r(6),u)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime=[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sys=mdlTerminate(t,x,u)%FUNCTION SYS=MDLtERMINATE(T,X,U)
sys=[];
在这个s函数中,我调用了别的函数operator(r,x).
另一个s函数的情况也与这个类似。
但是运行的时候出现问题了:从s函数模块中没有任何输出信号。
求助......
谢谢
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|