How to correct my s function code ?please help
Show older comments
when I run the simulink of tire model, it always occur :Output returned by S-function 't_dugoff' in 'untitled1/front tire model' during flag=3 call must be a real vector of length 3,
the code is like this:
function [sys,x0,str,ts] = t_dugoff(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys = mdlOutputs(t,x,u);
case { 1, 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 = 4;
sizes.DirFeedthrough =1 ;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [];
function sys = mdlOutputs(t,x,u)
wload=u(4);
vspd=u(2);
whlspd=u(1);
slip_A=u(3);
R=0.334;
cx=20000;
cy=16000;
fscl=0.0034;
u0=0.9;
a=slip_A*pi/180;
slip=(vspd-R*whlspd)/vspd;
uf=u0*(1-fscl*vspd*slip);
epslon=1e-6;
MAXF=uf*wload*(1-slip);
demandF=((cx*slip)^2+(cy*tan(a))^2)^0.5;
lamda=MAXF/2/demandF;
if lamda>=1
Flf=cx*slip/(1-slip);
Fyf=cy*tan(a)/(1-slip);
end
if lamda<1
Flf=cx*slip/(1-slip)*(2-lamda)*lamda;
Fyf=cy*tan(a)/(1-slip)*(2-lamda)*lamda;
end
sys=[Flf Fyf slip];
2 Comments
Hadi Abbas
on 1 Apr 2018
Do you remember how you solved this problem??
Walter Roberson
on 1 Apr 2018
What happens if lambda equals 1 exactly?. What happens if slip is 1, leading to division by 0?
Answers (1)
Kaustubha Govind
on 6 Apr 2012
It looks like this line may not be returning a vector with 3 elements (because you have configured the S-function for 3 outputs) as Simulink expects:
sys=[Flf Fyf slip];
It might be that Flf, Fyf and slip are not scalars, and therefore concatenate to a vector that does not have a size equal to 3.
I would recommend setting a breakpoint at the line. Then run your model again and examine the dimensions of the intermediate variables and of the output 'sys'.
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!