Challenge

Problem Set-1 c Week 11Challenge : Transient Handling

% Transient model - F1 car
clear all
close all

l = 9.52*12*.0254 ; % Wheelbase (m)
a = 5.71 * 12 * .0254; % cg to front axle (m)
b = l-a; % cg to rear axle (m)
m = 1719 * 0.453; % Mass (kg)
Jz = 865 ; % moment of inertia (kg-m^2)
Cv = 62228*4.45; % front cornering stiffness (N/rad)
Ch = 96608*4.45; % rear cornering stiffness (N/rad)
v = 350/3.6; % m/s

%% A,B,C,D Matrices
Yb=Cv+Ch;
Nb=(a*Cv)-(b*Ch);
Yr=((a*Cv)-(b*Ch))/v;
Nr=((a^2*Cv)+(5^2*Ch))/v;
% Numerical calculations.
Wn=((Yb*Nr)+(Nb*m*v)-(Yr*Nb))/(m*v*Jz); % Undamped natural frequeno
Zeta=-((Nr+Yb)/(2*Wn*(Jz*m*v))); % Damping ratio.
Wd=Wn*sqrt(1-Zeta^2); % Damp frequency.
theta=atan(sqrt(1-Zeta^2)/Zeta); % Angle for rise time.
Tr=(pi-theta)/Wd; % Rise time in seconds.

A = [ - (Cv+Ch)/(m*v), (b*Ch-a*Cv)/(m*v)-v
(b*Ch-a*Cv)/(Jz*v), - (a^2*Cv + b^2 * Ch)/(Jz*v)];

B = [Cv/m; a*Cv/Jz];

C_Vy = [1 0]; D_Vy = 0; % lateral speed
C_Yaw = [0 1]; D_Yaw = 0; % yaw rate
C_Ay = A(1,:) + v * [0,1]; D_Ay = B(1); % lateral acceleration

C = [C_Vy;C_Yaw;C_Ay];
D = [D_Vy;D_Yaw;D_Ay];

t = [0:0.01:1];
del_v = pi/180 * 5 * sin(7*2*pi*t); % 5 deg steering input at 7 Hz

sys = ss(A,B,C,D); % State space representation

Y = lsim ( sys, del_v , t); % linear simulation

sys.inputname = {'steering'};
sys.outputname = {'Vy','Yaw rate','Ay'};

%% Frequency response plot

figure(1)
[mag,phase,omega] = bode(sys({'Ay'},'steering'));

i = 1;
for i = 1:length(omega)
magnitude(i,1) = mag(:,:,i);
i = i+1;
end
loglog(omega/6.28,magnitude,'linewidth',2);
grid on

set(gca,'fontsize',10);
title('Lateral acceleration / Steer Angle Frequency Response');
xlabel ('Freqency (Hz)');
ylabel ('Lateral acceleration gain(m/s^2)/rad');

%% Step response
figure(2)

stepplot(sys,'r',2);
xlim([0 1]);

%% Sine response

figure(3)

% Lateral speed
subplot(2,2,1)
plot (t,Y(:,1),'linewidth',2);
title('Lateral speed');
xlabel ('Time (s)');
ylabel ('Lateral speed (m/s)');


% Yaw rate
subplot(2,2,2)
plot (t,Y(:,2)*180/pi,'linewidth',2);
title('Yaw rate');
xlabel ('Time (s)');
ylabel ('Yaw rate (deg/s)');

% Lateral acceleration
subplot(2,2,3)
plot (t,Y(:,3),'linewidth',2);
title('Lateral acceleration');
xlabel ('Time (s)');
ylabel ('Lateral acceleration (m/s^2)');

% Steer input
subplot(2,2,4)
plot (t,del_v*180/pi,'linewidth',2);
title('Steer angle');
xlabel ('Time (s)');
ylabel ('Steer angle (deg)');

%% System step response values
y = stepinfo(sys);
[wn, z] = damp(sys);

EG= (m*((Ch*b)-(Cv*a)))/(l*Ch*Cv);
V_ch= (sqrt(l/EG));


%% Sine response
figure(3)

% Lateral speed
subplot(2,2,1)
plot (t,Y(:,1),'linewidth',2);
title('Lateral speed');
xlabel ('Time (s)');
ylabel ('Lateral speed (m/s)');


% Yaw rate
subplot(2,2,2)
plot (t,Y(:,2)*180/pi,'linewidth',2);
title('Yaw rate');
xlabel ('Time (s)');
ylabel ('Yaw rate (deg/s)');

% Lateral acceleration
subplot(2,2,3)
plot (t,Y(:,3),'linewidth',2);
title('Lateral acceleration');
xlabel ('Time (s)');
ylabel ('Lateral acceleration (m/s^2)');

% Steer input
subplot(2,2,4)
plot (t,del_v*180/pi,'linewidth',2);
title('Steer angle');
xlabel ('Time (s)');
ylabel ('Steer angle (deg)');

%% System step response values
y = stepinfo(sys);
[wn, z] = damp(sys);

EG= (m*((Ch*b)-(Cv*a)))/(l*Ch*Cv);
V_ch= (sqrt(l/EG));

% Transient model - F1 car
clear all
close all

l = 9.33*12*.0254 ; % Wheelbase (m)
a = 2.92 * 12 * .0254; % cg to front axle (m)
b = l-a; % cg to rear axle (m)
m = 2000 * 0.453; % Mass (kg)
Jz = 1128 ; % moment of inertia (kg-m^2)
Cv = 13752*4.45; % front cornering stiffness (N/rad)
Ch = 11460*4.45; % rear cornering stiffness (N/rad)
v = 100/3.6; % m/s

%% A,B,C,D Matrices
Yb=Cv+Ch;
Nb=(a*Cv)-(b*Ch);
Yr=((a*Cv)-(b*Ch))/v;
Nr=((a^2*Cv)+(5^2*Ch))/v;
% Numerical calculations.
Wn=((Yb*Nr)+(Nb*m*v)-(Yr*Nb))/(m*v*Jz); % Undamped natural frequeno
Zeta=-((Nr+Yb)/(2*Wn*(Jz*m*v))); % Damping ratio.
Wd=Wn*sqrt(1-Zeta^2); % Damp frequency.
theta=atan(sqrt(1-Zeta^2)/Zeta); % Angle for rise time.
Tr=(pi-theta)/Wd; % Rise time in seconds.

A = [ - (Cv+Ch)/(m*v), (b*Ch-a*Cv)/(m*v)-v
(b*Ch-a*Cv)/(Jz*v), - (a^2*Cv + b^2 * Ch)/(Jz*v)];

B = [Cv/m; a*Cv/Jz];

C_Vy = [1 0]; D_Vy = 0; % lateral speed
C_Yaw = [0 1]; D_Yaw = 0; % yaw rate
C_Ay = A(1,:) + v * [0,1]; D_Ay = B(1); % lateral acceleration

C = [C_Vy;C_Yaw;C_Ay];
D = [D_Vy;D_Yaw;D_Ay];

t = [0:0.01:1];
del_v = pi/180 * 5 * sin(7*2*pi*t); % 5 deg steering input at 7 Hz

sys = ss(A,B,C,D); % State space representation

Y = lsim ( sys, del_v , t); % linear simulation

sys.inputname = {'steering'};
sys.outputname = {'Vy','Yaw rate','Ay'};

%% Frequency response plot

figure(1)
[mag,phase,omega] = bode(sys({'Ay'},'steering'));

i = 1;
for i = 1:length(omega)
magnitude(i,1) = mag(:,:,i);
i = i+1;
end
loglog(omega/6.28,magnitude,'linewidth',2);
grid on

set(gca,'fontsize',10);
title('Lateral acceleration / Steer Angle Frequency Response');
xlabel ('Freqency (Hz)');
ylabel ('Lateral acceleration gain(m/s^2)/rad');

%% Step response
figure(2)

stepplot(sys,'r',2);
xlim([0 1]);

%% Sine response

figure(3)

% Lateral speed
subplot(2,2,1)
plot (t,Y(:,1),'linewidth',2);
title('Lateral speed');
xlabel ('Time (s)');
ylabel ('Lateral speed (m/s)');


% Yaw rate
subplot(2,2,2)
plot (t,Y(:,2)*180/pi,'linewidth',2);
title('Yaw rate');
xlabel ('Time (s)');
ylabel ('Yaw rate (deg/s)');

% Lateral acceleration
subplot(2,2,3)
plot (t,Y(:,3),'linewidth',2);
title('Lateral acceleration');
xlabel ('Time (s)');
ylabel ('Lateral acceleration (m/s^2)');

% Steer input
subplot(2,2,4)
plot (t,del_v*180/pi,'linewidth',2);
title('Steer angle');
xlabel ('Time (s)');
ylabel ('Steer angle (deg)');

%% System step response values
y = stepinfo(sys);
[wn, z] = damp(sys);

EG= (m*((Ch*b)-(Cv*a)))/(l*Ch*Cv);
V_ch= (sqrt(l/EG));


%% Sine response
figure(3)

% Lateral speed
subplot(2,2,1)
plot (t,Y(:,1),'linewidth',2);
title('Lateral speed');
xlabel ('Time (s)');
ylabel ('Lateral speed (m/s)');


% Yaw rate
subplot(2,2,2)
plot (t,Y(:,2)*180/pi,'linewidth',2);
title('Yaw rate');
xlabel ('Time (s)');
ylabel ('Yaw rate (deg/s)');

% Lateral acceleration
subplot(2,2,3)
plot (t,Y(:,3),'linewidth',2);
title('Lateral acceleration');
xlabel ('Time (s)');
ylabel ('Lateral acceleration (m/s^2)');

% Steer input
subplot(2,2,4)
plot (t,del_v*180/pi,'linewidth',2);
title('Steer angle');
xlabel ('Time (s)');
ylabel ('Steer angle (deg)');

%% System step response values
y = stepinfo(sys);
[wn, z] = damp(sys);

EG= (m*((Ch*b)-(Cv*a)))/(l*Ch*Cv);
V_ch= (sqrt(l/EG));

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.