% Trainsient handling simulation for lateral speed, lateral accelration and
% yaw rates
clear all
clc
a = 1.14 ; % m Front axle to CG
L = 2.54 ; % m Wheel Base of the vehicle
m = 1500 ; % kg Mass of the vehicle
Iz =2420 ; % kg-m^2 Mass moment of inertia
Caf = 54000*2 ; % N/rad cornering stiffness of front tire combined
Car = 47000*2 ; % N/rad Cornering stiffness of rear tires combined
u = 20 ; % m/sec Speed of the vehicle
b = L-a ; % rear axle to CG
% Defining the matrixes for the State space equation of the vehicle.
A = [ -(Caf + Car)/(m*u), (b*Car-a*Caf)/(m*u)-u ; (b*Car - a*Caf)/(Iz*u), -(a^2*Caf + b^2*Car)/(Iz*u)];
B = [Caf/m ; a*Caf/Iz];
C_lat = [1,0]; D_lat = 0; % lateral Speed
C_yaw = [0,1]; D_yaw = 0; % yaw rate
C_acc = A(1,:) + u*[0,1]; D_acc = B(1); % lateral acceleration
C = [C_lat; C_yaw; C_acc];
D = [D_lat; D_yaw; D_acc];
% Defining the simulation time
t = [0:0.01:6];
% Defining the steering input
U = (pi/180)*sin(0.5*2*pi*t) % rad , Steering input for sinosoidal wave, i.e. sinwt, w = 2*pi*f, for the function is 1deg steering input at frequency of 0.5hz
sys = ss(A,B,C,D) % State space repersantation
y = lsim(sys,U,t) % Sinosoidal input
sys.inputname = {'Steering'};
sys.outputname = {'lat';'yaw';'acc'};
figure(1) % frequency response plot
[mag,p,w] = bode(sys('yaw','Steering'));
loglog(w/6.28,mag(1,:),'linewidth',3);
grid on;
set (gca,'fontsize',15);
title('Yaw v/s Steering angle');
xlabel('Frequency(Hz)');
ylabel('Yaw rate(deg/sec)');
figure(2) % frequency response plot
[mag_1,p_1,w_1] = bode(sys('lat','Steering'));
loglog(w_1/6.28,mag_1(1,:),'linewidth',3);
grid on;
set (gca,'fontsize',15);
title('Lateral Speed v/s Steering angle');
xlabel('Frequency(Hz)');
ylabel('Lateral speed(m/sec)');
figure(3) % frequency response plot
[mag_2,p_2,w_2] = bode(sys('acc','Steering'));
loglog(w_2/6.28,mag_2(1,:),'linewidth',3);
grid on;
set (gca,'fontsize',15);
title('Lateral Acceleration v/s Steering angle');
xlabel('Frequency(Hz)');
ylabel('Lateral Acceleration(g)');
figure(4) % Step response
step(sys);
set (gca,'fontsize',15);
figure(5) % Sine response
subplot(2,2,1)
plot(t,y(:,1),'linewidth',2,'color','r') % for lateral speed
set(gca,'fontsize',15)
title('lateral speed')
xlabel('time(sec)')
ylabel('lateral speed(m/sec)')
subplot(2,2,2)
plot(t,y(:,2),'linewidth',2,'color','r') % for yaw Rate
set(gca,'fontsize',15)
title('yaw Rate')
xlabel('time(sec)')
ylabel('Yaw Rate(deg/sec)')
subplot(2,2,3)
plot(t,y(:,3),'linewidth',2,'color','r') % for lateral acceleration
set(gca,'fontsize',15)
title('Lateral acceleration')
xlabel('time(sec)')
ylabel('Yaw Rate(deg/sec)')
subplot(2,2,4)
plot(t,(U*180/pi),'linewidth',2,'color','r') % steering input in deg
set(gca,'fontsize',15)
title('Steering Angle')
xlabel('time(sec)')
ylabel('Steering Angle(deg)')