simulink仿真中S函数提示我变量‘t'没有定义怎么回事啊?
Undefinedfunctionorvariable't'.这个是错误提示程序如下,是一个简单的控制器function[sys,x0,str,ts]=controler...
Undefined function or variable 't'.这个是错误提示
程序如下,是一个简单的控制器
function [sys,x0,str,ts] = controler1(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 6;
sizes.DirFeedthrough = 0;
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 = [0 0];
function sys=mdlOutputs(t,x,u)
G=[1 2];
K=[2 2];
deta=0.5;
numda=0.05;
x=[u(1);u(2)];
xd=[u(3);u(4)];
A=[0 1;-1 1];
Ad=[0 0.5;0.5 0.5];
B=[1;2];
s=G*(x-[1;1])-u(5)-u(6);%滑模
ueq = -inv(G*B)*(numda+deta*norm(G)*norm(x))*sign(s);
ucon = -K*x;
ut = ueq+ucon;%控制律
int1=G*(A-B*K)*x;%要积分后回来构成滑模的两项
int2=G*Ad*xd;
sys(1)=ut;
sys(2)=int1;
sys(3)=int2;
% end mdlOutputs 展开
程序如下,是一个简单的控制器
function [sys,x0,str,ts] = controler1(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 6;
sizes.DirFeedthrough = 0;
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 = [0 0];
function sys=mdlOutputs(t,x,u)
G=[1 2];
K=[2 2];
deta=0.5;
numda=0.05;
x=[u(1);u(2)];
xd=[u(3);u(4)];
A=[0 1;-1 1];
Ad=[0 0.5;0.5 0.5];
B=[1;2];
s=G*(x-[1;1])-u(5)-u(6);%滑模
ueq = -inv(G*B)*(numda+deta*norm(G)*norm(x))*sign(s);
ucon = -K*x;
ut = ueq+ucon;%控制律
int1=G*(A-B*K)*x;%要积分后回来构成滑模的两项
int2=G*Ad*xd;
sys(1)=ut;
sys(2)=int1;
sys(3)=int2;
% end mdlOutputs 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询