0% found this document useful (0 votes)
48 views11 pages

Me2608, Me3604, Me5541

This document discusses using MATLAB to simulate vehicle dynamics problems. It covers: 1) Simulating the motion of a pendulum subject to viscous friction using ordinary differential equations solved numerically in MATLAB. Parameters like length, mass, and friction are varied. 2) Simulating a quarter-car vehicle suspension model with one sprung mass using MATLAB. The displacement of the mass and road profile are plotted over time. 3) Combining multiple MATLAB programs and functions into a single file for distribution. The document provides examples of MATLAB code to set up and solve the dynamics simulations.

Uploaded by

RITESH RATHORE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views11 pages

Me2608, Me3604, Me5541

This document discusses using MATLAB to simulate vehicle dynamics problems. It covers: 1) Simulating the motion of a pendulum subject to viscous friction using ordinary differential equations solved numerically in MATLAB. Parameters like length, mass, and friction are varied. 2) Simulating a quarter-car vehicle suspension model with one sprung mass using MATLAB. The displacement of the mass and road profile are plotted over time. 3) Combining multiple MATLAB programs and functions into a single file for distribution. The document provides examples of MATLAB code to set up and solve the dynamics simulations.

Uploaded by

RITESH RATHORE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ME2608, 

ME3604, ME5541 
 
Solving Vehicle Dynamics Simulation and Design Problems using MATLAB 
 
Session 1:  Simulating System Dynamics using MATLAB 
 
1.1  Model system dynamics using ordinary differential equations. 
 
In physics, equations of motion are equations that describe the behaviour of a system as a function 
of time. In the case of a rigid body the term refers to the set of ordinary differential equations 
derived from Newton’s second law or Euler‐Lagrange  equations. In this practical session we will 
demonstrate how the equations of motion of a rigid body can be solved numerically using the 
MATLAB. For this demonstration we will consider the motion of a pendulum subject to viscous 
friction. The equations of motion will be derived and the MATLAB code to simulate the motion of the 
pendulum will be developed. The  students  then  will  be  asked  to  simulate  the  motion  of  the 
pendulum for  different  sets of parameters (pendulum length, mass, friction etc.) and describe their  
observations. 
 
Pendulum with Viscous  Damping: Consider the pendulum of figure on the 
right. The total mass m is considered to be concentrated at the end point of 
the string length L. The angular deflection of the pendulum is denoted by θ. The 
gravitational force (acceleration of gravity g) and the viscous friction moment 
M = −bθ  where b is the damping coefficient. 
d

 
Applying Newton’s second law we have: 
 
    mL2θ(t ) = −mgL sin(θ (t )) − bθ(t )       (1.1) 
 
In order to simulate the dynamics of the pendulum using MATLAB, we first need to express the 
above second order ordinary differential equation (ODE) ((Eq.1.1) as  a set of first order ODEs. To this 
end, define the following state variables as: 
 
⎡ z ⎤ ⎡θ ⎤
    z1  θ ; z2  θ   z = ⎢ 1 ⎥ = ⎢  ⎥            (1.2) 
⎣ z2 ⎦ ⎣θ ⎦
 
Using  the  above  definitions,  equation  (1.1)  can  be  expressed  as 
 
    z1 = θ = z2                   (1.3) 
g b g b
    z2 = − sin(θ ) − 2 θ = − sin(z1 ) − 2 z2           (1.4) 
L mL L mL
 
⎡θ ⎤ ⎡ z2 ⎤
Vector format:   ⎢
z = g ⎥ = ⎢ ⎥      (1.5) 
⎢ − sin(θ ) − b θ ⎥ ⎢ − g sin(z1 ) − b z2 ⎥
⎢⎣ L mL ⎥⎦ ⎣ L
2
mL ⎦
2

1
The above equations (1.3) and (1.4) can be now solved numerically using the  ode45 command of 
MATLAB.  The  time  span  of  the  solution  (initial  and  final  time  t0  and  tf  ),  as  well  as  initial  states 
(z1(t0) and z2(t0)) need to be provided. 
 
1.2  Using MATLAB ODE solver to simulate the system dynamics 
 
Task 1: Create a MATLAB function file to describe the motion equations 
 
Start MATLAB’s build‐in editor to start to create this function file. 
 
function zdot=pendulum_eom(t,z,g,L,b,m) First Line
z1 = z(1); Extract variables
z2 = z(2); from function inputs
z1dot = z2; Equation (1.3)
z2dot = -(g/L)*sin(z1)-(b/(m*L^2))*z2; Equation (1.4)
zdot = [z1dot; z2dot]; Generate function output
end Last line
 
The first line is the function heading which dictates the variable zdot (store 1st order derivatives 
of state variables) is a function of t, z, g, L, b, m  where t is the time variable, z is the 
state variables ( θ (t )  and  θ(t )  for this system), g, L, b and m  are parameters. 
 
Save this function file, the MATLAB will suggest to use the file name pendulum_eom.m, you 
must use this name (i.e. the function file name must be the same as function statement name). To 
make sure the function file has been created correctly, you need to test this function in MATLAB 
command window by typing the following in command prompt >>. 
 
>> pendulum_eom(10, [1;2], 9.8, 1, 2, 3)
 
This should produce a 2x1 vector. 
 
Task 2: Create a MATLAB program (m‐file) to solve the ODE and plot results. 
 
Start MATLAB’s build‐in editor to start to create a MATLAB program (m‐file). 
 
m=1; g=9.81; L=3; b=1;
                   % enter parameters: mass, gravity, pendulum length & damping coefficient 
z0 = [30*pi/180 ; 0];
          % Enter initial condition ( Initial position (rad) and Initial velocity (rad/sec)) 
t0 = 0; tf = 10;
          % Specify solution start and end times 
tspan = [t0, tf];
          % Solution time range 
2
          % Alternatively tspan = [t0 : 0.025 : tf] where 0.025 is the discretization time step. 
[t,Z] = ode45(@(t,z) pendulum_eom(t,z,g,L,b,m),tspan,z0);
                % using ODE solver ode45 to solve the differential equations 
theta = Z(:,1); dot_theta = Z(:,2);
             % Extract information (theta and dot_theta) from the solution 
             % The 1st column is theta and the 2nd column is dot_theta 
 
%PLOTS
 
figure(1)
plot(t,theta*180/pi)
% plot theta against time 
grid
xlabel('t (sec)'), ylabel('\theta (deg)')
title(‘\theta vs time’)
% add figure label and title 

figure(2)
plot(t,dot_theta*180/pi),
% plot doy_theta against time 
grid
xlabel('t (sec)'), ylabel('d\theta/dt (deg/sec)')
title('d\theta/dt vs time')
% add figure label and title 
 
figure(3)
% plot x‐y (position of the mass on the x‐y plane) 
x = L*sin(theta); y = -L*cos(theta);
% Calculate cartesian coordinates 
plot(x,y),grid,xlabel('x (m)'),ylabel('y (m)')
axis equal
 
After all above commands been entered. Save them as a m‐file (MATLAB program). You can use 
any program name, however the name must start with a letter and must not have any space. In 
this problem, the file is save as  pendulum.m  (or p1234.m). 
 
A MATLAB program can be run (executed) using either the following two ways. 
• Click big green arrow above Editor. 
• Type the program name (without .m) in the command prompt, i.e. >> pendulum. 
 
Task 3: Run animation program to watch the pendulum animation. 
 
Download the program pendulum_animation.m from Blackboard and run it by typing the 
following on the command prompt 
3
>> pendulum_animation(theta,dot_theta,t,x,y)
 
The MATLAB will give some warning messages for this program because the program was wriiten 
for older versions of MATLAB. No need to be alarm by error messages. 
 
Task 4: Change system parameters and test program at different conditions.  Open the program 
pendulum.m created in Task 2 and make some modifications. 
• Change L to 0.5 and repeated Task 2 and Task 3. 
• Change L to 2 and repeated Task 2 and Task 3. 
• Change L to 1 and b to 1, 5 or 10 repeated Task 2 and Task 3. 
 
MATLAB program deployment (distribution): To solve a complex engineering problem, a number 
of MATLAB programs and functions are usually produced.  To distribute them to other users, it is 
sometimes more convenient to combine all files together as a single file. MATLAB commands in 
MATLAB programs are excited squelchy, program can be combined according to the order of tasks. 
As for MATLAB function files, they must be added to the end of the combined MATLAB program. 
 
Session 2:  Investigate suspension systems using MATLAB Simulation 
 
2.1  One mass quarter suspension model simulation 
 
The quarter car model is used to study the motion of a 
single suspension of the vehicle. We assume that the 
suspension supports ¼ of the weight of the vehicle and 
consists of a linear spring with stiffness k and linear 
damper with damping ratio c. In the figure on right x 
corresponds to the position of the sprung mass of the 
vehicle and y corresponds to the profile of the road. 
 
The motion equation can be derived using Newton’s law: 
 
    mx(t ) = −mg − K (x(t ) − y(t )) − c(x(t ) − y(t ))           (2.1) 
 
Where the parameters are m=440kg, K = 22000N/m and c = 2800Ns/m. The road profile is 
assumed to be   y(t ) = 0.1sin(π t ) . 
 
Task 2.1: Write a MATLAB program to simulate the one mass quarter model and plot the 
displacement x and the road profile y against the time t on the same plot. 
 
Follow the procedure of Session 1, the First Step is to convert the 2nd order differential equation to 
two 1st order differential equations. 
 

4
⎡z ⎤ ⎡x⎤
Define    z1  x ; z2  x   z = ⎢ 1 ⎥ = ⎢ ⎥            (2.2) 
⎣ z2 ⎦ ⎣ x ⎦
 
Using  the  above  definitions,  equation  (2.1) can be  expressed  as 
 
    z1 = x = z2                   (2.3) 
K c K c
    z2 = −g − (x − y) − (x − y) = −g − (z1 − y) − (z2 − y)       (2.4) 
m m m m
 
⎡ x ⎤
⎡z ⎤ ⎡x⎤
Vector format:         z = ⎢ K c ⎥    where  z = ⎢ 1 ⎥ = ⎢ ⎥     (2.5) 
⎢ −g − (x − y) − (x − y)⎥ ⎣ z2 ⎦ ⎣ x ⎦
⎣ m m ⎦
 
The Second Step is to write a MATLAB function file to describe the motion equations. 
 
function zdot = quarter_1mass_eom(t,z,g,m,K,c)
z1 = z(1); z2 =z(2);

y = 0.1*sin(pi*t);
ydot = 0.1*pi*cos(pi*t);

z1dot = z2 ; Equation (2.3)
z2dot = -g - ???????? ; Equation (2.4)
zdot = [z1dot; z2dot];
end
 
To make sure the function file has been created correctly, you need to test this function in 
MATLAB command window by typing the following in command prompt >>. 
 
>> quarter_1mass_eom(10, [1;2], 9.8, 1, 2, 3)
 
This should produce a 2x1 vector. 
 
The Third Step is to write a MATLAB program (quarter_1mass.m) to complete the simulation and 
plotting tasks. 
 
m=440; g=9.8; K=22000; c=2800;
z0 = [0 ; 0];
tspan = [0, 10];
[t,Z] = ode45(@(t,z) quarter_1mass_eom(t,z,g,m,K,c),tspan,z0);
x = Z(:,1); % The purpose of this line is to extract x from ODE solution
Y=0.1*sin(pi*t);
figure(1)
plot(t,x, t, Y)
grid 5
xlabel('time (sec)');
ylabel('displacement (m)')
legend(‘x’, ‘y’)
 
2.2  Two masses quarter suspension model simulation 
 
A more realistic quarter car model of the suspension will 
consider sprung (vehicle body) and unsprung (wheel, tyre, 
etc) masses ms and mu respectively, as well as an 
additional stiffness term kt corresponding to the stiffness 
of the tyre. 
 
The motion equation can be derived using Newton’s law: 
 
    x s (t ) = −msg − K (x s (t ) − xu (t )) − c(x s (t ) − xu (t ))  
ms        (2.6) 
 
    xu (t ) = −mu g − kt (xu (t ) − y(t )) + K (x s (t ) − xu (t )) + c( x s (t ) − xu (t ))  
mu    (2.7) 
 
Where the parameters are ms=400kg, mu=40kg, K = 22000N/m, kt=190000N/m and c = 2800Ns/m.  
 
Task 2.2:  Simulate the motion of the suspension 
system considering separate sprung and unsprung 
masses considering a positive step road profile of 
0.15m applied 2sec after the start of the simulation 
as shown on right.  
 
 
Same as before, the First Step is to convert two 2nd order differential equation to four 1st order 
differential equations. 
 
⎡ z1 ⎤ ⎡ x s ⎤
⎢ z ⎥ ⎢ x ⎥
Define    z1  x s ; z2  x s   z3  xu ; z4  xu   z=⎢ 2⎥=⎢ s⎥    (2.7) 
⎢ z3 ⎥ ⎢ xu ⎥
⎢ ⎥ ⎢ ⎥
⎣ z4 ⎦ ⎣ xu ⎦
 
Using  the  above  definitions,  equations  (2.5) & (2.6) can be  expressed  as 
 
    z1 = x s = z2                   (2.8) 
K c K c
    z2 = −g − (x s − xu ) − (x s − xu ) = −g − (z1 − z3 ) − (z2 − z4 )     (2.9) 
ms ms ms ms
    z3 = xu = z4                   (2.10) 

6
kt c K c
z4 = −g − (xu − y) − (x s − xu ) + ( x s − xu ) + (x s − xu )
mu ms mu mu
        (2.11) 
kt K c
= −g − (z3 − y) + (z1 − z3 ) + (z2 − z4 )
mu mu mu
 
⎡ z2 ⎤
⎢ ⎥
⎢ −g − K (z1 − z3 ) − c (z2 − z4 ) ⎥
⎢ ms ms ⎥
Vector format:   z = ⎢ ⎥      (2.12) 
⎢ z 4 ⎥
⎢ kt K c ⎥
⎢ −g − (z3 − y) + (z1 − z3 ) + (z2 − z4 )⎥
⎣ mu mu mu ⎦
The Second Step is to write a MATLAB function file to describe the motion equations. 
 
function zdot = quarter_2mass_eom(t,z,g,mu,ms,K,kt,c)
z1 = z(1); z2 =z(2); z3=z(3); z4=z(4);
if t <= 2
y=0;
else
y =0.15;
end
z1dot = z2; Eq (2.8)
z2dot = -g -(k/ms)*(z1-z3) -(c/ms)*(z2-z4); Eq (2.9)
z3dot = ??????; Eq (2.10)
z4dot = ????; Eq (2.11)

zdot = [z1dot;z2dot;z3dot;z4dot];
end
 
To make sure the function file has been created correctly, you need to test this function in 
MATLAB command window by typing the following in command prompt >>. 
 
>> quarter_2mass_eom(10, [1;2;3;4],9.8,1,2,3,4,5)
 
This should produce a 4x1 vector. 
 
The Third Step is to write a MATLAB program (quarter_2mass.m) to complete the simulation and 
plotting Tasks. 
 
ms=400; g=9.81; K=22000; c=2800; mu=40; kt=190000;
z0 = [0 ; 0; 0 ; 0];
tspan = [0, 10];
[t,Z]=ode45(@(t,z) quarter_2mass_eom(t,z,g,mu,ms, K,kt,c),tspan,z0);
xs = Z(:,1); xu=Z(:,3);
for i = 1:length(t)
if t(i)<=2 7
Y(i) = 0;
else
Y(i) = 0.15;
end
end
figure(2)
plot(t,xs,t,xu,t,Y)
grid
xlabel('time (sec)'), ylabel('displacement (m)')
legend('xs', 'xu', 'y')
 
Task 2.3: Swap road profile between one mass model case and two masses case, check the result 
differences.  Swap the part of calculating road profile y in quarter_2mass_eom with the part in
quarter_1mass_eom, and swap the part of calculating road profile y in quarter_2mass 
with the part in quarter_1mass. 
 
Session 3:  Investigate the Impact of Longitudinal Tyre Forces on Vehicle’s Braking 
Responses 
 
Consider the translation and rotation of a tyre supporting ¼ of 
the vehicle’s total weight. The force acting on the tyre is 
described by the graph shown on the right, where Vx is vehicle 
speed; ω is tyre angular rate; T: drive/brake torque applied to 
the wheel; fx is: longitudinal tyre force; R is radius of the tyre; 
m is ¼ of vehicle mass, and J is moment of inertia of the wheel 
and tyre. 
 
The parameters are given as m=300kg, J=1Kgm2, R=0.3m, B=0.18, C=1.5, and D=3000N. In this 
session, the following two tasks are to be completed. 
 
Task 3.1: Simulate the vehicle’s acceleration from standstill with an input torque T=500Nm. What 
is the distance travelled and velocity achieved after 10 sec? 
 
Task 3.2: Simulate the braking case from an initial speed of 100km/h with an input torque 
T=300Nm. What is the stopping distance? 
 
3.1  Mathematical model development 
 
Motion equations derived using Newton’s law are as follow: 
 
    mVx (t ) = fx (t )                   (3.1) 
    Jω (t ) = T (t ) − Rfx (t )                 (3.1) 
 
8
The force fx is given by the Pacejka’s Magic Formula: 
 
    ( )
fx (t ) = −D sin C tan−1 (Bsx )               (3.3) 
 
Where the slip ratio sx is determined by 
 
⎧ ωR
⎪1 − V ; ωR ≤ Vx

    sx = ⎨ x
              (3.3) 
⎪ ω R
− 1; ωR ≥ Vx
⎪⎩ Vx
 
3.2  Write a MATLAB function file to describe the motion equations 
 
Same as before, the motion equations are first converted into standard format as: 
 
    x = Vx                     (3.4) 
f
    Vx = x                   (3.5) 
m
1 R
    ω = T − fx                   (3.7) 
J J
⎡ z1 ⎤ ⎡ x ⎤
Define    z = ⎢⎢ z2 ⎥⎥ = ⎢⎢Vx ⎥⎥                 (3.8) 
⎢⎣ z3 ⎥⎦ ⎢⎣ ω ⎥⎦
⎡ Vx ⎤
Vector format motion equation:    ⎢
z = ⎢ fx / m ⎥        (3.9) 

⎢⎣T / J − (R / J) fx ⎥⎦
 
function zdot = tyre_forces_eom(t,z,m,J,R,B,C,D,T)
x = z(1); Vx = z(2); omega = z (3);
if Vx>0 && omega>0 && abs(Vx)>abs(omega*R)
sx = (Vx - omega*R)/abs(Vx);
elseif Vx>0 && omega>0 && abs(Vx)<abs(omega*R)
sx = (Vx - omega*R)/abs(omega*R);
elseif Vx<0 && omega<0 && abs(Vx)>abs(omega*R)
sx = (Vx - omega*R)/abs(Vx);
elseif Vx<0 && omega<0 && abs(Vx)<abs(omega*R)
sx = (Vx - omega*R)/abs(omega*R);
elseif Vx>0 && omega<0
sx = (Vx - omega*R)/abs(Vx);
elseif Vx<0 && omega>0
sx = (Vx - omega*R)/abs(Vx);
elseif Vx==0 && omega==0
sx = 0;
elseif Vx==omega*R
sx = 0;
elseif Vx==0 && omega>0
9
sx = (Vx - omega*R)/abs(omega*R);
elseif Vx==0 && omega<0
sx = (Vx - omega*R)/abs(omega*R);
elseif Vx>0 && omega==0
sx = (Vx - omega*R)/abs(Vx);
elseif Vx<0 && omega==0
sx = (Vx - omega*R)/abs(Vx);
end
fx = - D*sin(C*atan(B*sx));
xdot = Vx;
Vxdot = fx/m;
omegadot = T/J - (fx*R)/J;
zdot = [xdot; Vxdot; omegadot];
end
 
To make sure the function file has been created correctly, you need to test this function in 
MATLAB command window by typing the following in command prompt >>. 
 
>>
  tyre_forces_eom(10, [1;2;3],100,1,2,3,4,5, 400)
This should produce a 3x1 vector. 
3.2  Write a program using MATLAB ODE solver to complete tasks 
 
Task 3.1: Simulate the vehicle’s acceleration from standstill with an input torque T=500Nm. What 
is the distance travelled and velocity achieved after 10 sec? 
 
m=300; J=1; R=0.3; B=0.18; C=1.5; D=3000;
x0=0; Vx0=0; omega0=Vx0/R; T=500;
% Note that Vx0=0 & T=500 for Task 3.1 and Vx0=100/3.6 & T=‐300 for Task 3.2 
z0 = [x0; Vx0; omega0];
tspan= [0 10];
[t, Z]=ode45(@(t,z) tyre_forces_eom(t,z,m,J,R,B,C,D,T),tspan, z0);
x=Z(:,1); Vx = Z (:,2);omega=Z (:,3);
figure(1)
plot(t,x),xlabel('t (sec)'), ylabel('distance (m)')
figure(2)
plot(t,Vx),xlabel('t (sec'),ylabel('speed (m/sec)')
figure(3)
plot(t,omega), xlabel('t (sec')
ylabel('wheel angular speed (rad/sec)')
 
The results can be found from the plots. Alternatively, the can be found and displayed by adding 
the following commands to the main program. 
 
fprintf('The distance travelled after 10sec is %g\n', x(end))
fprintf('The velocity reached after 10sec is %g\n', Vx(end))
 

10
 
 
Task 3.2: Simulate the braking case from an initial speed of 100km/h with an input torque 
T=300Nm. What is the stopping distance? 
 
Remember to change Vx0 and T in the program to simulating the breaking case. The results can be 
found from the plots.  
 

 
 
Alternatively, the can be found and displayed by adding the following commands to the main 
program. 
 
kstop1=find(Vx==0);
if isempty(kstop1)==0
t_stop=t(kstop1(1));
x_stop=x(kstop1(1));
else
kstop2=find(Vx<0);
t_stop=(t(kstop2(1)-1)+t(kstop2(1)))/2;
x_stop=(x(kstop2(1)-1)+x(kstop2(1)))/2;
end
fprintf('Car stop at %g sec and stop distance is %g\n',t_stop,x_stop)
 
11

You might also like