|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
各位大侠:
我在做自抗器时,全部按照薛定宇的《基于Matlab /Simulink的系统仿真技术与应用》搭建了系统,但系统报错
Error getting arg counts for S-function 'eso3' in 'ADRC1/ESO'.MATLAB error meaasge:Error:File:d:\MTALAB704\work\eso3.m Line:1 Column:49Expression or statement is incorrect
eso的程序如下:
function [sys,x0,str,ts] = ESO(t,x,u,flag,d,bet,,b,T)
% 扩张状态观测器(extended stste observer)
% 2009.05.15
switch flag,
case 0
[sys,x0,str,ts] = mdlInitializeSizes; % 初始化
case 2
sys = mdlUpdates(x,u,d,bet,b,T); % 离散状态的更新
case 3
sys = mdlOutputs(x); % 输出量的计算
case { 1, 4, 9 }
sys = []; % 未使用的flag值
otherwise
error(['Unhandled flag = ',num2str(flag)]); % 处理错误
end;
%==============================================================
% 当flag为0时进行整个系统的初始化
%==============================================================
function [sys,x0,str,ts] = mdlInitializeSizes
% 首先调用simsizes函数得出系统规模参数sizes, 并根据离散系统的实际
% 情况设置sizes变量
sizes = simsizes;
sizes.NumContStates = 0; % 无连续状态变量
sizes.NumDiscStates = 3; % 3个离散状态变量
sizes.NumOutputs = 3; % 三路输出
sizes.NumInputs = 2; % 两路输入:u和y
sizes.DirFeedthrough = 0; % 输入信号不直接在输出中反映出来
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0; 0; 0]; % 设置初始状态为零状态
str = []; % 将str变量设置为空字符串
ts = [-1 0]; % 采样周期: 假设它继承输入信号的采样周期
%==============================================================
% 在主函数的flag=2时,更新离散系统的状态变量
%==============================================================
function sys = mdlUpdates(x,u,d,bet,b,T)
e=x(1)-u(2);
sys(1,1)=x(1)+T*(x(2)-bet(1)*e);
sys(2,1)=x(2)+T*(x(3)-bet(2)*fal(e,0.5,d)+b*u(1));
sys(3,1)=x(3)-T*bet(3)*fal(e,0.25,d);
%==============================================================
% 在主函数flag=3时,计算系统的输出变量
%==============================================================
function sys = mdlOutputs(x)
sys=x;
%==============================================================
% 用户定义的子函数: fal
%==============================================================
function f=fal(e,a,d)
if abs(e)<d
f=e*d^(a-1);
else
f=(abs(e))^a*sign(e);
end
第49行就是
% 用户定义的子函数: fal
TD程序
function [sys,x0,str,ts] = TD(t,x,u,flag,r,h,T)
% 微分跟踪器
% 2009.05.15
switch flag,
%%%%%%%%%%
% 初始化 %
%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(T);
%%%%%%%%%%%%%%%
% 离散状态更新 %
%%%%%%%%%%%%%%%
case 2,
sys=mdlUpdate(x,u,r,h,T);
%%%%%%%%%%%%%
% 输出量计算 %
%%%%%%%%%%%&&
case 3,
sys=mdlOutputs(x);
%%%%%%%%%%
% 未使用 %
%%%%%%%%%%
case {1,4,9},
sys=[];
%%%%%%%%%%%%
% 处理错误 %
%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% 整个系统初始化
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(T)
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 2;
sizes.NumOutputs = 2;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [0;0];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [-1 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlUpdate
% 更新离散系统状态变量
%=============================================================================
%
function sys = mdlUpdate(x,u,r,h,T)
sys(1,1) = x(1)+T*x(2);
sys(2,1) = x(2)+T*fst2(x,u,r,h);
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% 计算系统输出变量:返回两个状态
%=============================================================================
%
function sys=mdlOutputs(x)
sys = x;
% end mdlOutputs
%
%=============================================================================
% fst2
% 用户自定义子函数:fst2
%=============================================================================
%
function f = fst2(x,u,r,h)
delta = r * h;
delta0 = delta * h;
y = x(1) - u + h * x(2);
a0 = sqrt(delta * delta + 8 * r * abs(y));
if abs(y) <= delta0
a = x(2) + y / h;
else
a = x(2) + 0.5 * (a0 - delta) * sign(y);
end
if abs(a) <= delta
f = -r * a / delta;
else
f = -r * sign(a);
end
% end fst2
NLSEF的程序:
function [sys,x0,str,ts] = NLSEF(t,x,u,flag,aa,bet1,b,d)
% 自抗扰控制器(Active Disturbance Rejection Controller)
% 2009.05.15
%
% The following outlines the general structure of an S-function.
%
switch flag,
%%%%%%%%%%
% 初始化 %
%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(t,u,x);
%%%%%%%%%%%%%%%
% 输出量的计算 %
%%%%%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u,aa,bet1,b,d);
%%%%%%%%%%
% 未使用 %
%%%%%%%%%%
case {1,2,4,9},
sys=[];
%%%%%%%%%%%%
% 处理错误 %
%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(t,u,x)
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [-1 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u,aa,bet1,b,d)
e1=u(1)-u(3);
e2=u(2)-u(4);
u0=bet1(1)*fal(e1,aa(1),d)+bet1(2)*fal(e2,aa(2),d);
sys = u0-u(5)/b;
% end mdlOutputs
%
%=============================================================================
% fal
% user-defined function
%=============================================================================
%
function f=fal(a,e,d)
if abs(e)<d
f=e*d^(a-1);
else
f=(abs(e))^a*sign(e);
end
% end fal
怎么回事呢?求教各位
[ 本帖最后由 jadasn 于 2009-7-27 16:17 编辑 ] |
|