Hi, I try to run the code, when it runs the workspace is empty, even if i try to global, cant seem to show, even if i search for k, it cant detect the variable.iable.

3 visualizaciones (últimos 30 días)
%function
function [m, Ix, Iz, a1, a2, w, h, C_beta_f, C_beta_r, C_alpha_f, C_alpha_r,C_Tf, C_Tr, C_delta_phi_f, C_delta_phi_r, C_phi_f, C_phi_r, cut_sws_front, cut_sws_rear] = detail_handling
% mass in tonnes , inertia in tonnes.m^2
m = 0.690
Ix = 0.190
Iz = 1.05
%
a1 = 1.25; % Front wheelbase to cg
a2 = 1.51; % Rear wheelbase to cg
w=0.74;
%height from ground to cg
h=0.3;
%C_alpha (kN/rad)- tire sideslip coefficient
C_alpha_fL =26;
C_alpha_fR=26;
C_alpha_rL=32;
C_alpha_rR=32;
C_alpha_f = C_alpha_fL+C_alpha_fR;
C_alpha_r = C_alpha_rL+C_alpha_rR;
%C_beta - tire roll rate coefficient
C_beta_f=-0.4;
C_beta_r=-0.1;
%C_T - tire torque coefficient
C_Tf = -0.4;
C_Tr= -0.2;
%C_delta_phi -tire roll steering coefficient
C_delta_phi_f=0.1;
C_delta_phi_r=0;
%C_phi - tire camber trst coefficient
C_phi_f=-3.2;
C_phi_r=0;
cut_sws_front = 0.03;
cut_sws_rear =0.03;
%% Another file %%
function [range_p range_r settling_time_p settling_time_r overshot_r LTR]=transient_ploting (ksf,ksr,csf,csr)
[m Ix Iz a1 a2 w h C_beta_f C_beta_r C_alpha_f C_alpha_r C_Tf C_Tr C_delta_phi_f C_delta_phi_r C_phi_f C_phi_r cut_sws_front cut_sws_rear]= detail_handling ;
% ksf=17;
% ksr=22;
% csf=1.5;
% csr=1.5;
% k=(ksf+ksr);
% c=(csf+csr);
k=39;
c=3;
%k_phi - roll stiffness; c_phi - roll damping
k_phi=0.5*k*w^2;
c_phi=0.5*c*w^2;
%Vx - forward velocity,km/hr
Vx=80*(1000/3600);
C_r = -(a1/Vx)*C_alpha_f + ((a2/Vx)*C_alpha_r) ; %vehicle yaw-rate lateral-force coefficient
C_p = ((C_alpha_f*C_beta_f)/Vx) + ((C_alpha_r*C_beta_r)/Vx); %vehicle roll-rate lateral-force coefficient
C_beta = -(C_alpha_f+C_alpha_r); %vehicle slip-angle lateral-force coefficient
C_phi = (C_alpha_r*C_delta_phi_r) + (C_alpha_f*C_delta_phi_f) - C_phi_f - C_phi_r; %vehicle yaw-angle lateral-force coefficient
C_delta = C_alpha_f ; %vehicle steer-angle lateral-force coefficient
E_r = -(a1/Vx)*C_Tf*C_alpha_f + (a2/Vx)*C_Tr*C_alpha_r ; %vehicle yaw-rate roll-moment coefficient
E_p = (C_alpha_f*C_beta_f*C_Tf)/Vx + (C_alpha_r*C_beta_r*C_Tr)/Vx - c_phi ; %vehicle roll-rate roll-moment coefficient
E_beta = -C_alpha_f*C_Tf - C_alpha_r*C_Tr ; %vehicle slip-rate roll-moment coefficient
E_phi = -C_Tf*(C_phi_f - (C_alpha_f*C_delta_phi_f)) - k_phi - C_Tr*(C_phi_r - (C_alpha_r*C_delta_phi_r)) ; %vehicle yaw-angle roll-moment coefficient
E_delta = C_Tf*C_alpha_f ; %vehicle steer-angle roll-moment coefficient
D_r = -(a1^2/Vx)*C_alpha_f - (a2^2/Vx)*C_alpha_r ; %vehicle yaw-rate yaw-moment coefficient
D_p = (a1/Vx)*C_beta_f*C_alpha_f - (a2/Vx)*C_beta_r*C_alpha_r ; %vehicle roll-rate yaw-moment coefficient
D_beta = -(a1*C_alpha_f - a2*C_alpha_r) ; %vehicle slip-rate yaw-moment coefficient
D_phi = -a1*(C_phi_f - (C_alpha_f*C_delta_phi_f)) + a2*(C_phi_r - (C_alpha_r*C_delta_phi_r)); %vehicle yaw-angle yaw-moment coefficient
D_delta = a1*C_alpha_f ; %vehicle steer-angle yaw-moment coefficient
%Steady-state motion
A = [ C_beta/(m*Vx) C_p/m C_phi/m (C_r/m)-Vx;
E_beta/(Ix*Vx) E_p/Ix E_phi/Ix E_r/Ix;
0 1 0 0;
D_beta/(Iz*Vx) D_p/Iz D_phi/Iz D_r/Iz];
B = [C_delta/m ; E_delta/Ix ; 0 ; D_delta/Iz];
C = [1 0 0 0;0 1 0 0; 0 0 1 0 ; 0 0 0 1];
D = [0 ;0 ;0 ;0];
%state-space funtion
sys = ss(A,B,C,D);
%setting for the maneuver input
endtime=5;
initial_t=0;
initial_u=0;
% type of input = step, slow_inc_steer, sine_steer, sine_inc_amp,
% sine_dwell , pulsesteer
[u tm]=step(initial_u,initial_t,endtime);
%initial condition for the lsim
x0 = [0;0;0;0];
[y,time]=lsim(sys,u,tm,x0);
%range of roll rate
range_p = (max(y(:,2))-min(y(:,2)))*(180/pi)
%range of yaw rate
range_r = (max(y(:,4))-min(y(:,4)))*(180/pi)
%gradient for roll rate step&pulsesteer only p
inc=0.02;
for i=2:1:((endtime/inc)+1)
grad_p(i-1,:) = (y(i,2)-y((i-1),2))/inc;
end
a=1;
row = find(grad_p<0);
for i = 2:size(row)
h = row(i,1)-row(i-1,1);
if h>2
row_p(a,1)=row(i-1,1);
row_p(a+1,1)=row(i,1);
a=a+2;
else
end
end
for i=2:size(row_p)
h = abs(y(row_p(i,1),2)-y(row_p(i-1,1),2))*(180/pi);
if h<(0.1*range_p)
time_p=row_p(i,1)*inc;
break;
end
end
settling_time_p=max(time_p)
%gradient for yaw rate step only
for i=2:1:((endtime/inc)+1)
grad_r(i-1,:) = (y(i,4)-y((i-1),4))/inc;
end
a=1;
row = find(grad_r<0);
for i = 2:size(row)
h = row(i,1)-row(i-1,1);
if h>2
row_r(a,1)=row(i-1,1);
row_r(a+1,1)=row(i,1);
a=a+2;
else
end
end
for i=2:size(row_r)
h = abs(y(row_r(i,1),4)-y(row_r(i-1,1),4))*(180/pi);
if h<=(0.1*range_r)
time_r=row_r(i,1)*inc;
break;
end
end
settling_time_r=max(time_r)
%percentage overshoot for yaw rate
overshot_r = 100*abs((y(row_r(1,1),4)-y((endtime/inc),4))/y((endtime/inc),4))
%calculate lateral acceleration
Fy = C_r.*y(:,4)+C_p.*(y(:,2))+(C_beta.*(y(:,1))./Vx)+C_phi.*(y(:,3))+C_delta.*u;
acc=Fy./(m*9.81);
%load transfer ratio
ltr = (2/w).*( -k_phi.*(y(:,3))-c_phi.*(y(:,2)))./(m*9.81);
LTR=max(ltr)
figure (2)
subplot (3,2,1)
plot(time,y(:,1)), ylabel('V_y/ m/s'),xlabel('time,s'),grid minor
subplot (3,2,2)
plot(time,y(:,2).*(180/pi)), ylabel('Roll rate,p deg/s'),xlabel('time,s'),grid minor
subplot (3,2,3)
plot(time,y(:,3).*(180/pi)), ylabel('Roll angle,phi deg'),xlabel('time,s'),grid minor
subplot (3,2,4)
plot(time,y(:,4).*(180/pi)), ylabel('Yaw rate, r deg/s'),xlabel('time,s'),grid minor
subplot (3,2,5)
plot(time,acc./9.81), ylabel('Lateral acceleration, g'),xlabel('time,s'),grid minor
subplot (3,2,6)
plot(time,u.*(180/pi)), ylabel('Steering input, deg'),xlabel('time,s'),grid minor
figure (3)
plot(time,ltr),ylabel('Load Transfer Ratio'),xlabel('time,s'),grid minor
end

Respuestas (1)

Cris LaPierre
Cris LaPierre el 19 de Mayo de 2023
You are running a function, which has its own workspace. You can read more about that here: https://www.mathworks.com/help/matlab/matlab_prog/base-and-function-workspaces.html
Basically, a new workspace is created inside a function. That is where the variables created inside your function live. Once the function ends, that workspace is closed and all those variables are removed. Unless you pause your code execution inside a function (use a breakpoint to do this), you will only ever see the base MATLAB Workspace.
  1 comentario
Steven Lord
Steven Lord el 19 de Mayo de 2023
In addition to what Cris wrote, I recommend not writing functions that return 19(!) separate output arguments. It's way too easy to forget the order of the output arguments and debugging problems like that is often quite painful. Instead I'd probably use a struct array to package those disparate pieces of data into one output argument (which you could also pass into functions that require some or all of those pieces of data as input, rather than writing functions that require tens of input arguments.)

Iniciar sesión para comentar.

Categorías

Más información sobre Wheels and Tires en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by