matlab传动系统模型,用S函数构建传动系统的仿真模型

时间: 2023-10-04 admin IT培训

matlab传动系统模型,用S函数构建传动系统的仿真模型

matlab传动系统模型,用S函数构建传动系统的仿真模型

用S函数仿真了齿轮,跑出来程序有问题。Error in 'untitled/S-Function' while executing MATLAB S-function 'geartest', flag = 1 (derivatives), at time 0.0. 函数或变量 't' 无法识别。 源码如下,请问该如何处理。

function [sys,x0,str,ts,simStateCompliance] = geartest(t,x,u,flag)

switch flag

case 0

[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;

case 1

sys=mdlDerivatives(t,x,u);

case 3

sys=mdlOutputs(t,x,u);

case {2, 4, 9}

sys = [];

otherwise

DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));

end

function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes

sizes = simsizes;

sizes.NumContStates  = 4;

sizes.NumDiscStates  = 0;

sizes.NumOutputs     = 4;

sizes.NumInputs      = 2;

sizes.DirFeedthrough = 0;

sizes.NumSampleTimes = 0;

sys = simsizes(sizes);

x0  = [0; 0; 0; 0];

str = [];

ts  = [];

simStateCompliance = 'UnknownSimState';

function sys=mdlDerivatives(t,x,u)

global rbp rbg e b

z1 = 53 ; z2 = 125 ; pi = 3.14159 ;

Jp = 6.55 ; Jg = 198; alpha0 = 20 ; %分度圆压力角

m = 4; b = 0.07 ; %齿侧间隙的一半

n1 = 5;

psi = pi/2;

k0=1;ka=1;

e0 = 2e-5;er = 2e-5;%齿轮传递误差的常数项 一阶谐波幅值

rbp = 0.5 * m * z1 * cos(alpha0) / 1000 ;

rbg = 0.5 * m * z2 * cos(alpha0) / 1000 ;

Omega1 = 2 * pi * n1;%角速度

km = k0+ka*cos(Omega1*t+psi);%时变啮合刚度  阻尼比

cm = 2*km*(km*Jp*Jg/(rbp^2*Jp+rbg^2*Jg))^0.5;%齿轮的啮合阻尼

e = e0 + er*sin(Omega1*t/60);%齿轮的静态传递误差

de = (er * Omega1 / 60) * cos(Omega1 * t / 60);%齿轮静态传递误差的导数

tol1 = u(1);

tol2 = u(2);

sys(1) = x(2);

sys(2) = (tol1-rbp*cm*(rbp*x(2)-rbg*x(4)-de)-rbp*km*ft(x))/Jp;

sys(3) = x(3);

sys(4) = (tol2-rbg*cm*(rbp*x(2)-rbg*x(4)-de)-rbg*km*ft(x))/Jp;

function sys=mdlOutputs(t,x,u)

sys(1) = x(1);

sys(2) = x(2);

sys(3) = x(3);

sys(4) = x(4);

function f=ft(x)

global rbp rbg e b

z1 = 53 ; z2 = 125 ; pi = 3.14159 ;n1 = 5;

alpha0 = 20 ; %分度圆压力角

m = 4; b = 0.07 ; %齿侧间隙的一半

rbp = 0.5 * m * z1 * cos(alpha0) / 1000 ;

rbg = 0.5 * m * z2 * cos(alpha0) / 1000 ;

e0 = 2e-5;er = 2e-5;Omega1 = 2 * pi * n1;%角速度

e = e0 + er*sin(Omega1*t/60);%齿轮的静态传递误差

delta=rbp*x(2)-rbg*x(4)-e;

f = (delta-b).*(delta>=b)+(delta+b).*(delta<=-b)+0*(abs(delta)