0% found this document useful (0 votes)
122 views

Matlab Project - Quarter Vehicle: Name: Sebastian Preil Student ID: 1256334 Winter Semester 2015/16

This document describes a Matlab program that models the dynamics of a quarter vehicle. The quarter vehicle model includes a wheel mass, undercarriage mass, and seat mass connected by springs and dampers. The document provides the mathematical model, including the system of equations of motion and matrix representations. It then describes programming the simulation model in Matlab, creating a graphical user interface, combining the model and interface, and testing the finished program. The program is designed to analyze the response of the wheel, undercarriage, and seat when the vehicle drives over a curb.

Uploaded by

Reza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

Matlab Project - Quarter Vehicle: Name: Sebastian Preil Student ID: 1256334 Winter Semester 2015/16

This document describes a Matlab program that models the dynamics of a quarter vehicle. The quarter vehicle model includes a wheel mass, undercarriage mass, and seat mass connected by springs and dampers. The document provides the mathematical model, including the system of equations of motion and matrix representations. It then describes programming the simulation model in Matlab, creating a graphical user interface, combining the model and interface, and testing the finished program. The program is designed to analyze the response of the wheel, undercarriage, and seat when the vehicle drives over a curb.

Uploaded by

Reza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Matlab Project – Quarter Vehicle

Figure 1: Quarter-Vehicle

Name: Sebastian Preil

Student ID: 1256334

Winter Semester 2015/16


Matlab Project – Quarter-Vehicle
Sebastian Preil

Table of Contents
1 Introduction ................................................................................................................................3
2 Mathematic Model .....................................................................................................................3
2.1 Equation of Motion .............................................................................................................3
3 Programming ..............................................................................................................................5
3.1 Program the simulation model – Qauarter_Vehicle.m .........................................................5
3.2 Creating the User-Interface with Matlab GUIDE ...................................................................7
3.3 Combination of the basic simulation model and the user-interface.................................... 18
3.4 Test of the finished Quarter-Vehicle simulation program ................................................... 26
4 Different Weight-Analysis.......................................................................................................... 28
5 Conclusion ................................................................................................................................ 29

Table of Figures
Figure 1: Quarter-Vehicle ....................................................................................................................1
Figure 2: Quarter-Vehicle / 3-Mass-System .........................................................................................3
Figure 3: First-Plot in the basic program ..............................................................................................7
Figure 4: Opening the "GUIDE" for creating the User-Interface ...........................................................7
Figure: 5: Blank GUI (Default) User-Interface Page ..............................................................................8
Figure 6: User-Interface with Graphic-Module and Static/Edit-Text-Modules ......................................8
Figure 7: Edit "Static-Text-Field"..........................................................................................................9
Figure 8: Edit "Edit-Text-Field" ............................................................................................................9
Figure 9: Edit "Axes" - Graphic-Module ............................................................................................. 10
Figure 10: Finished User-Interface..................................................................................................... 10
Figure 11: Edit "Push-Button" ........................................................................................................... 11
Figure 12: Finished User-Interface Callback ....................................................................................... 11
Figure 13: Test of the finished Quarter-Vehicle simulation program .................................................. 26
Figure 14: Finished Quarter-Vehicle simulation program ................................................................... 27
Figure 15: Light-Weight-Vehicle ........................................................................................................ 28
Figure 16: Normal-Weight-Vehicle .................................................................................................... 28
Figure 17: Heavy-Weight-Vehicle ...................................................................................................... 28

2
Matlab Project – Quarter-Vehicle
Sebastian Preil

1 Introduction
For my task to create a Matlab-Program I was looking for a project which is used in the reality and
refers to my major study – Automotive Engineering with preference to the matlab programming.
According to that I decided to write a program with a user interface for analysing a quarter-vehicle,
also known as a three-mass-system. The quarter-vehicle I programmed includes the street with an
edge with the height h, one wheel which contains one mass m1 and one spring stiffness c1, the
undercarriage (auto body, motor, …) with the functions of one mass m2, one spring stiffness c2 and
also one dumper constant k2. At last the program involves the seat of a car with one person on it
which also serves as one mass m3, one spring stiffness c3 and one dumper constant k3. The dumper
constant of the wheels can be neglected as far as the vibration damper of the undercarriage is
working correctly.

The focus of this analysation was to illustrate the answers of the system according to the liftings of
wheel, undercarriage and drivers-seat after driving over a kerb.

2 Mathematic Model

Figure 2: Quarter-Vehicle / 3-Mass-System

2.1 Equation of Motion


The 3-Mass-System from Figure 2 gives me three differential equations:

̈ + ∗( ̇ − ̇ )+ ∗( − )=0

̈ + ∗( ̇ − ̇ )− ∗( − )+ ∗( ̇ − ̇ )+ ∗( − )=0

̈ + ∗( ̇ − ̇ )− ∗( − )+ ∗ = ∗ℎ

3
Matlab Project – Quarter-Vehicle
Sebastian Preil

System Matrix:

0 1 0 0 0 0
⎡ ( + ) ⎤
⎢− − 0 0 ⎥
⎢ ⎥
⎢ 0 0 0 1 0 0 ⎥
=⎢ ( + ) ( + ) ⎥
⎢ − − ⎥
⎢ ⎥
⎢ 0 0 0 0 0 1 ⎥
⎢ 0 0 − − ⎥
⎣ ⎦

Steering Matrix:

0
⎡ ⎤
⎢ ⎥
⎢ ⎥
=⎢ 0 ⎥
⎢ 0 ⎥
⎢ 0 ⎥
⎣ 0 ⎦

Observation Matrix:

= [1 0 0 0 0 0]

Control Ratio Matrix:

= [0]

Uncoupled, undamped natural frequency:

+
ℎ =
2∗

=
2∗

=
2∗

4
Matlab Project – Quarter-Vehicle
Sebastian Preil

3 Programming

3.1 Program the simulation model – Qauarter_Vehicle.m


I started with programming the definitions of the simulation model of the quarter-vehicle and
continued with the matrixes of the system and finished with the calculations and finally the
“Plot-Code” for visualising the movements of each part of the quarter vehicle.

I called this program: Quarter_Vehicle.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Name: Sebastian Preil %
% Student-ID: 1256334 %
% Date: November 2015 %
% %
% Matlab-Project: %
% Quarter-Vehicle %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc;
clear all;

% System Parameter

m1 = 30; % Mass Wheel [kg]


m2 = 300; % Mass Undercarriage [kg]
m3 = 30; % Mass Seat [kg]
c1 = 100000; % Spring Stiffness Wheel [N/m]
c2 = 20000; % Spring Stiffness Undercarriage [N/m]
c3 = 100000; % Spring Stiffness Seat [N/m]
k2 = 1100; % Damper Constant Undercarriage [Ns/m]
k3 = 300; % Damper Constant Seat [Ns/m]

tend = 5; % Simulation Period [sec]

eh = 0.2 % Edge-Height for driving over [m]

% System Matrix

A = [ 0 1 0 0 0 0 ;
-(c2+c1)/m1 -k2/m1 c2/m1 k2/m1 0 0 ;
0 0 0 1 0 0 ;
c2/m2 k2/m2 -(c3+c2)/m2 -(k3+k2)/m2 c3/m2 k3/m2 ;
0 0 0 0 0 1 ;
0 0 c3/m3 k3/m3 -c3/m3 -k3/m3];

5
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Steering Matrix

B = [0 c1/m1 0 0 0 0]';

% Observation Matrix

C = [1 0 0 0 0 0];

% Control Ratio Matrix

D = [0];

% Simulation Period

t = 0:0.001:tend;

% Uncoupled, undamped natural frequency

fWheel = sqrt((c1+c2)/m1)/(2*pi)
fCarriage = sqrt(c2/m2)/(2*pi)
fDriver = sqrt(c3/m3)/(2*pi)

% Street

f = fWheel; % Stimulation Frequency


h = [zeros(40,1); eh*ones(length(t)-40,1)]'; % Edge Stimulation

% Calculation

system = ss(A,B,C,D); % Definition of the State Space Model


[y,t,x] = lsim(system,h,t); % Simulation

% Answers from different liftings

hWheel = x(:,1); % Wheel lifting


hCarriage = x(:,3); % Undercarriage lifting
hSeat = x(:,5); % Seat lifting

plot(t, [h', hWheel, hCarriage, hSeat]);


legend('h - Street','z1 - Wheel','z2 - Undercarriage','z3 - Seat');
xlabel('Time [s]');
ylabel('Vertical movement [m]');

6
Matlab Project – Quarter-Vehicle
Sebastian Preil

For this first program I declared the system parameters to fixed values. I did this for an easy control
check if the programming is correct and works properly. After I have finished writing this program I
pushed the “Run-Button” to see if everything is working well.

Figure 3: First-Plot in the basic program

3.2 Creating the User-Interface with Matlab GUIDE


When the simulation model was programmed and working, I opened the interface creator with the
“guide” command and chose “Blank GUI (Default)” to get a blank page for the user-interface.

Figure 4: Opening the "GUIDE" for creating the User-Interface

7
Matlab Project – Quarter-Vehicle
Sebastian Preil

Figure: 5: Blank GUI (Default) User-Interface Page

After I generated the blank GUIDE-Page, I established one area “axes1” whereas the graphs will be
illustrated in for the simulation program. Also I created 10 “Static-Text” and 10 “Edit-Text” fields. Into
the static-text fields I wrote the variable names and they will stay fixed the whole time, whereas the
edit-text fields will be clear in the finished program and there the user can type in the values of the
variables.

Figure 6: User-Interface with Graphic-Module and Static/Edit-Text-Modules

8
Matlab Project – Quarter-Vehicle
Sebastian Preil

Figure 7 is an example how I edited the static-text fields. Into the


“String-Field” I put in the text which I would like to show in the
program. Here it is the variable “Mass Wheel – m1 [kg]”. Anything
else can be kept as it was when I created the field.

Figure 7: Edit "Static-Text-Field"

Figure 8 shows the information of an “Edit-Text-Field”. I deleted


anything what was in the “String-Field” because the user has to write
into it a number, the value of the chosen variable; here it is the edit-
field for the variable m1. That is why I called the “Tag-Field” –
“editm1”. Later on I have to write this “editm1” into the M-File of the
Matlab-Program. All other variables in that editor can also be kept as
it is the standard.

Figure 8: Edit "Edit-Text-Field"

9
Matlab Project – Quarter-Vehicle
Sebastian Preil

In Error! Reference source not found. there is the set-up of the


graphic-module “axes1” which will illustrate the liftings of the quarter
vehicle. For the M-File I need “axes1” from the “Tag-Field” to specify
where the graphics should be shown at.

Figure 9: Edit "Axes" - Graphic-Module

In the next step I moved the static- and the edit-text fields and created another graphic-module to
insert “Figure 2: Quarter-Vehicle / 3-Mass-System” (page 3) which shall be shown all the time. The
set up for “axes2” is similar to that what you can see in Figure 9: Edit "Axes" - Graphic-Module.
Furthermore I built up a push-button and called it “RUN”, which starts calculating the simulation
after the user has typed in all variable values and will show the graphic solution of the system.

Figure 10: Finished User-Interface

10
Matlab Project – Quarter-Vehicle
Sebastian Preil

In Figure 11 there is the definition of the “Run-Push-Button”. I


changed the colour to green and named the String-Field “RUN”, that
is what the user can see in the user-interface. Additionally I changed
the Tag-Field to “runbutton” what I need in the M-File in the
simulation program.

Figure 11: Edit "Push-Button"

The user-interface in the Matlab-GUIDE is finished now. I clicked onto the “RUN-Button” and did the
“Callback” for generating a new M-File with all the functions of that interface and called it
“Quarter_Vehicle_User.m”.

Figure 12: Finished User-Interface Callback

11
Matlab Project – Quarter-Vehicle
Sebastian Preil

Quarter_Vehicle_User.m

function varargout = Quarter_Vehicle_User(varargin)


% QUARTER_VEHICLE_USER MATLAB code for Quarter_Vehicle_User.fig
% QUARTER_VEHICLE_USER, by itself, creates a new QUARTER_VEHICLE_USER
or raises the existing
% singleton*.
%
% H = QUARTER_VEHICLE_USER returns the handle to a new
QUARTER_VEHICLE_USER or the handle to
% the existing singleton*.
%
% QUARTER_VEHICLE_USER('CALLBACK',hObject,eventData,handles,...) calls
the local
% function named CALLBACK in QUARTER_VEHICLE_USER.M with the given
input arguments.
%
% QUARTER_VEHICLE_USER('Property','Value',...) creates a new
QUARTER_VEHICLE_USER or raises the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before Quarter_Vehicle_User_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to Quarter_Vehicle_User_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Quarter_Vehicle_User

% Last Modified by GUIDE v2.5 10-Nov-2015 20:36:56

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Quarter_Vehicle_User_OpeningFcn, ...
'gui_OutputFcn', @Quarter_Vehicle_User_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

12
Matlab Project – Quarter-Vehicle
Sebastian Preil

% --- Executes just before Quarter_Vehicle_User is made visible.


function Quarter_Vehicle_User_OpeningFcn(hObject, eventdata, handles,
varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Quarter_Vehicle_User (see VARARGIN)
clc
% Choose default command line output for Quarter_Vehicle_User
handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Quarter_Vehicle_User wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Quarter_Vehicle_User_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

function editm1_Callback(hObject, eventdata, handles)


% hObject handle to editm1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editm1 as text


% str2double(get(hObject,'String')) returns contents of editm1 as a
double

% --- Executes during object creation, after setting all properties.


function editm1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editm1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

13
Matlab Project – Quarter-Vehicle
Sebastian Preil

function editm2_Callback(hObject, eventdata, handles)


% hObject handle to editm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editm2 as text


% str2double(get(hObject,'String')) returns contents of editm2 as a
double

% --- Executes during object creation, after setting all properties.


function editm2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editm3_Callback(hObject, eventdata, handles)


% hObject handle to editm3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editm3 as text


% str2double(get(hObject,'String')) returns contents of editm3 as a
double

% --- Executes during object creation, after setting all properties.


function editm3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editm3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editc1_Callback(hObject, eventdata, handles)


% hObject handle to editc1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editc1 as text


% str2double(get(hObject,'String')) returns contents of editc1 as a
double

14
Matlab Project – Quarter-Vehicle
Sebastian Preil

% --- Executes during object creation, after setting all properties.


function editc1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editc1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editc2_Callback(hObject, eventdata, handles)


% hObject handle to editc2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editc2 as text


% str2double(get(hObject,'String')) returns contents of editc2 as a
double

% --- Executes during object creation, after setting all properties.


function editc2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editc2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editc3_Callback(hObject, eventdata, handles)


% hObject handle to editc3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editc3 as text


% str2double(get(hObject,'String')) returns contents of editc3 as a
double

% --- Executes during object creation, after setting all properties.


function editc3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editc3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

15
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editk2_Callback(hObject, eventdata, handles)


% hObject handle to editk2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editk2 as text


% str2double(get(hObject,'String')) returns contents of editk2 as a
double

% --- Executes during object creation, after setting all properties.


function editk2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editk2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editk3_Callback(hObject, eventdata, handles)


% hObject handle to editk3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editk3 as text


% str2double(get(hObject,'String')) returns contents of editk3 as a
double

% --- Executes during object creation, after setting all properties.


function editk3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editk3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

16
Matlab Project – Quarter-Vehicle
Sebastian Preil

function edittend_Callback(hObject, eventdata, handles)


% hObject handle to edittend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edittend as text


% str2double(get(hObject,'String')) returns contents of edittend as
a double

% --- Executes during object creation, after setting all properties.


function edittend_CreateFcn(hObject, eventdata, handles)
% hObject handle to edittend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in runbutton.


function runbutton_Callback(hObject, eventdata, handles)
% hObject handle to runbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

function edith_Callback(hObject, eventdata, handles)


% hObject handle to edith (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edith as text


% str2double(get(hObject,'String')) returns contents of edith as a
double

% --- Executes during object creation, after setting all properties.


function edith_CreateFcn(hObject, eventdata, handles)
% hObject handle to edith (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

17
Matlab Project – Quarter-Vehicle
Sebastian Preil

3.3 Combination of the basic simulation model and the user-interface


Now I had two M-Files, Quarter_Vehicle.m and Quarter_Vehicle_User.m. I basically inserted the basic
simulation model from Quarter_Vehicle.m into the user-interface M-File Quarter_Vehicle_User.m
and changed the fixed variables from the basic model into editable variables for the user-interface.
Additionally I defined the two graphics to show the “plot” of the system and the “Figure 2: Quarter-
Vehicle / 3-Mass-System”. The whole program I saved into the User-Interface M-File with the name
“Quarter_Vehicle_User.m”.

In the following pages there is the combination of both programs shown. The different program-lines
of the user-interface M-File are marked as:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Name: Sebastian Preil %
% Student-ID: 1256334 %
% Date: November 2015 %
% %
% Matlab-Project: %
% Quarter-Vehicle %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = Quarter_Vehicle_User(varargin)


% QUARTER_VEHICLE_USER MATLAB code for Quarter_Vehicle_User.fig
% QUARTER_VEHICLE_USER, by itself, creates a new QUARTER_VEHICLE_USER
or raises the existing
% singleton*.
%
% H = QUARTER_VEHICLE_USER returns the handle to a new
QUARTER_VEHICLE_USER or the handle to
% the existing singleton*.
%
% QUARTER_VEHICLE_USER('CALLBACK',hObject,eventData,handles,...) calls
the local
% function named CALLBACK in QUARTER_VEHICLE_USER.M with the given
input arguments.
%
% QUARTER_VEHICLE_USER('Property','Value',...) creates a new
QUARTER_VEHICLE_USER or raises the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before Quarter_Vehicle_User_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to Quarter_Vehicle_User_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Quarter_Vehicle_User

18
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Last Modified by GUIDE v2.5 10-Nov-2015 20:36:56

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Quarter_Vehicle_User_OpeningFcn, ...
'gui_OutputFcn', @Quarter_Vehicle_User_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before Quarter_Vehicle_User is made visible.


function Quarter_Vehicle_User_OpeningFcn(hObject, eventdata, handles,
varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Quarter_Vehicle_User (see VARARGIN)
clc
% Choose default command line output for Quarter_Vehicle_User
handles.output = hObject;

% Insert Picture Image

axes(handles.axes2); % Image will be shown in small Graph "Axes 2"


imshow('Image_Dynamik.jpg'); % Show data file "Image_Dynamik.jpg"
axis image; % Show Graphic
axis off; % turn off the axes

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Quarter_Vehicle_User wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Quarter_Vehicle_User_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

19
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Get default command line output from handles structure


varargout{1} = handles.output;

function editm1_Callback(hObject, eventdata, handles)


% hObject handle to editm1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editm1 as text


% str2double(get(hObject,'String')) returns contents of editm1 as a
double

% --- Executes during object creation, after setting all properties.


function editm1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editm1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editm2_Callback(hObject, eventdata, handles)


% hObject handle to editm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editm2 as text


% str2double(get(hObject,'String')) returns contents of editm2 as a
double

% --- Executes during object creation, after setting all properties.


function editm2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editm2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editm3_Callback(hObject, eventdata, handles)


% hObject handle to editm3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

20
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Hints: get(hObject,'String') returns contents of editm3 as text


% str2double(get(hObject,'String')) returns contents of editm3 as a
double

% --- Executes during object creation, after setting all properties.


function editm3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editm3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editc1_Callback(hObject, eventdata, handles)


% hObject handle to editc1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editc1 as text


% str2double(get(hObject,'String')) returns contents of editc1 as a
double

% --- Executes during object creation, after setting all properties.


function editc1_CreateFcn(hObject, eventdata, handles)
% hObject handle to editc1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editc2_Callback(hObject, eventdata, handles)


% hObject handle to editc2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editc2 as text


% str2double(get(hObject,'String')) returns contents of editc2 as a
double

% --- Executes during object creation, after setting all properties.


function editc2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editc2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

21
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editc3_Callback(hObject, eventdata, handles)


% hObject handle to editc3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editc3 as text


% str2double(get(hObject,'String')) returns contents of editc3 as a
double

% --- Executes during object creation, after setting all properties.


function editc3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editc3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function editk2_Callback(hObject, eventdata, handles)


% hObject handle to editk2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editk2 as text


% str2double(get(hObject,'String')) returns contents of editk2 as a
double

% --- Executes during object creation, after setting all properties.


function editk2_CreateFcn(hObject, eventdata, handles)
% hObject handle to editk2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

22
Matlab Project – Quarter-Vehicle
Sebastian Preil

function editk3_Callback(hObject, eventdata, handles)


% hObject handle to editk3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editk3 as text


% str2double(get(hObject,'String')) returns contents of editk3 as a
double

% --- Executes during object creation, after setting all properties.


function editk3_CreateFcn(hObject, eventdata, handles)
% hObject handle to editk3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edittend_Callback(hObject, eventdata, handles)


% hObject handle to edittend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edittend as text


% str2double(get(hObject,'String')) returns contents of edittend as
a double

% --- Executes during object creation, after setting all properties.


function edittend_CreateFcn(hObject, eventdata, handles)
% hObject handle to edittend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in runbutton.


function runbutton_Callback(hObject, eventdata, handles)
% hObject handle to runbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

23
Matlab Project – Quarter-Vehicle
Sebastian Preil

% System Parameter

m1 = str2num(get(handles.editm1,'String')); % Mass Wheel


[kg]
m2 = str2num(get(handles.editm2,'String')); % Mass Undercarriage
[kg]
m3 = str2num(get(handles.editm3,'String')); % Mass Seat
[kg]
c1 = str2num(get(handles.editc1,'String')); % Spring Stiffness Wheel
[N/m]
c2 = str2num(get(handles.editc2,'String')); % Spring Stiffness
Undercarriage [N/m]
c3 = str2num(get(handles.editc3,'String')); % Spring Stiffness Seat
[N/m]
k2 = str2num(get(handles.editk2,'String')); % Damper Constant
Undercarriage [Ns/m]
k3 = str2num(get(handles.editk3,'String')); % Damper Constant Seat
[Ns/m]

tend = str2num(get(handles.edittend,'String')); % Simulation Period


[sec]

eh = str2num(get(handles.edith,'String')); % Edge-Height for driving


over [m]

% System Matrix

A = [ 0 1 0 0 0 0 ;
-(c2+c1)/m1 -k2/m1 c2/m1 k2/m1 0 0 ;
0 0 0 1 0 0 ;
c2/m2 k2/m2 -(c3+c2)/m2 -(k3+k2)/m2 c3/m2 k3/m2 ;
0 0 0 0 0 1 ;
0 0 c3/m3 k3/m3 -c3/m3 -k3/m3];

% Steering Matrix

B = [0 c1/m1 0 0 0 0]';

% Observation Matrix

C = [1 0 0 0 0 0]; % Wheel movement is watched

% Control Ratio Matrix

D = [0];

% Simulation Period

t = 0:0.001:tend;

24
Matlab Project – Quarter-Vehicle
Sebastian Preil

% Uncoupled, undamped natural frequency

fWheel = sqrt((c1+c2)/m1)/(2*pi)
fCarriage = sqrt(c2/m2)/(2*pi)
fDriver = sqrt(c3/m3)/(2*pi)

% Street

f = fWheel; % Stimulation Frequency


h = [zeros(40,1); eh*ones(length(t)-40,1)]'; % Edge Stimulation

% Calculation

system = ss(A,B,C,D); % Definition of the State Space Model


[y,t,x] = lsim(system,h,t); % Simulation

% Answers from different liftings

hWheel = x(:,1); % Wheel lifting


hCarriage = x(:,3); % Undercarriage lifting
hSeat = x(:,5); % Seat lifting

axes(handles.axes1); % Image will be shown in big Graph "Axes 1"

plot(t, [h', hWheel, hCarriage, hSeat]);


legend('h - Street','z1 - Wheel','z2 - Undercarriage','z3 - Seat');
xlabel('Time [s]');
ylabel('Vertical movement [m]');

function edith_Callback(hObject, eventdata, handles)


% hObject handle to edith (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edith as text


% str2double(get(hObject,'String')) returns contents of edith as a
double

% --- Executes during object creation, after setting all properties.


function edith_CreateFcn(hObject, eventdata, handles)
% hObject handle to edith (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

25
Matlab Project – Quarter-Vehicle
Sebastian Preil

3.4 Test of the finished Quarter-Vehicle simulation program


First of all you can see in Figure 13 that I used for testing the same variable values like in the basic
simulation program Quarter_Vehicle.m and the result of the graph is fortunately exactly the same,
what represents that I combined both programs together right.

Figure 13: Test of the finished Quarter-Vehicle simulation program

Secondly there was a small mistake about the y-axle in the graph on the left, because you cannot see
the labelling. So I changed the graphic design of “axes1” in the GUIDE-Model
“Quarter_Vehicle_User.fig” and compiled the user-interface and the program was changed
automatically. In Figure 14 there is everything correct now.

26
Matlab Project – Quarter-Vehicle
Sebastian Preil

Figure 14: Finished Quarter-Vehicle simulation program

27
Matlab Project – Quarter-Vehicle
Sebastian Preil

4 Different Weight-Analysis
Figure 15: Light-Weight-Vehicle

Figure 16: Normal-Weight-Vehicle

Figure 17: Heavy-Weight-Vehicle

28
Matlab Project – Quarter-Vehicle
Sebastian Preil

In the Figures 15 to 17 above there I used the same spring-stiffness- and dumper-constant-settings; I
only diversified the weights m1, m2 and m3 to see the influences related to the liftings of each part
of the quarter-vehicle-system. As you can see, the heavier the masses the larger is the amount of the
amplitudes and the oscillating time of a heavy car is also longer than of a light-weight vehicle.

5 Conclusion
With this project I have learned a lot about Matlab, Matlab-GUI and its programming. Also I have
established Matlab is a very useful and powerful tool for analysing simulation models. Additionally I
enlarged my matrixes knowledge and learned how to work and program in a structural way.

After the program was finally written, I could “play” with the physical variables and the program
generated an easily interpreted graphic image of the consequences on the movements in the
quarter-vehicle-system.

29

You might also like