You are on page 1of 65

Building a MATLAB/Simulink-based

truck simulator

T.A.H. Lousberg - 0930774


SEP report

DC2016-012

Supervisors:
K. Kural MSc.
Dr. ir. I.J.M. Besselink
Dynamics and Control Technology Group
Eindhoven University of Technology
Eindhoven, January 27, 2016
Abstract
This SEP project aims to design a MATLAB/Simulink-based truck simulator. This project
is done for the Dynamics and Control Technology Group of Eindhoven University of Tech-
nology. Previously, this research group has created MATLAB/Simulink models of trucks
which consist of longer and heavier commercial vehicle combinations, which are called LZV
trucks. However, these truck models can be expanded by a hardware input of a Logitech
steering wheel with pedals and gear selector. The existing truck model uses constant inputs
programmed into a MATLAB script by the user. To create a more convenient and user
friendly environment the input method were changed to a hardware one. To connect the
gaming steer wheel, the joystick block in Simulink is used. This block enables the interaction
between Simulink and the Logitech hardware. The difficulty in this project is not replacing
the original input signal by the hardware input, but rather in the replacing of the original
variables and constants in de MATLAB/Simulink model with variables and constants of the
hardware input model.

This report also discusses how the original cruise control is expanded with the hardware
input. Originally, the cruise control only compared a reference speed with the actual speed
of the truck, but when the truck is driving at a particular speed, it is desire to be able to
keep this speed constant using a button on the steering wheel. If this is possible, the speed
must also be made controllable by means of the steering wheel flippers for this case. By
making use of these flippers, the speed will gradually increase or decrease. In addition a
connection between the cruise control and the vehicle pedals needed. If the throttle, brake
or clutch pedal is pressed, the cruise control should switch off.

The truck simulator model is also expanded with a transmission model including clutch.
The transmission operates via the Logitech gear selector and clutch from Logitech. A disad-
vantage of the Logitech gear selector is that it only consist of six gears, while typically gear
selectors of trucks have many more. It is decided to still use the transmission model in the
simulation, to make the simulation more realistic. The behaviour of the engine speed or the
final drive torque remains the same.

With respect to the visualization, a number of improvements have been made. The truck is
extended with several components such as a steering wheel and arrows showing the magni-
tudes of tire forces programmed in VRML (Virtual Reality Modeling Language). Also text
displays in order to indicate the vehicle and motor speeds are created. To exercise manoeu-
vres during the simulation, an environment with a distribution centre has been created. In
order to easily visually estimate the velocity of the truck some road poles and trees have
been added.

Finally, a Graphical User Interface (GUI) in MATLAB has been created. In this GUI,
choices can been made between different LZV combinations and different parameters. In
the GUI the user can choose between a constant steering input and cruise control speed, or
simulate real time with extend input from the Logitech steering wheel, gear lever and pedals.
Contents

1 Introduction 1

2 Truck simulaton model 2


2.1 Initial Simulink model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Hardware input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Cruise Control 5

4 Powertrain model 8

5 Visualization 15
5.1 VRML Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.2 Dynamic VRML in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.3 Steering wheel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4 Tire force arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.5 Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.6 Viewpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.7 Environment design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

6 Graphical User Interface 22

7 Conclusions and recommendations 23

A Original MATLAB/Simulink transmission model 29

B VRML visualization user guide 34

C Graphical User Interface user guide 48

D Evaluation SEP 54

E Declaration concerning the TU/e Code of Scientific Conduct (Dutch ver-


sion) 56

F Declaration concerning the TU/e Code of Scientific Conduct (English ver-


sion) 57

i
List of symbols

pe Engine power [Js1 ]


Te Engine torque [Nm]
e Angular velocity of the engine [s1 ]
Je Inertia engine [kgm2 ]
Pc Clutch pressure [N m2 ]
Tc Clutch Torque [N m]
Tc,slip Clutch slip Torque [N m]
Tc,stick Clutch stick Torque [N m]
p Angular velocity of the powertrain [s1 ]
Mw Driven wheels moment [N m]
n Gear ratio [-]
nF D Final drive ratio [-]
TF D Torque final drive [Nm]
Jv,prim Inertia at primary shaft [kgm2 ]
Jv Inertia vehicle [kgm2 ]
v Angular velocity of the driven wheels [s1 ]
v Vehicle acceleration [s2 ]

ii
Chapter 1

Introduction

A MATLAB/Simulink-based truck simulator was built as part of the SEP project at Eind-
hoven University of Technology. This project is executed for the Dynamics and Control
Technology group of Eindhoven University of Technology. Previously, this research group
has created Simulink models of the LZV trucks [1]. Aspects such as vehicle dynamics, pow-
ertrain systems and tire models are included in these models. The current truck model
simulation uses a lookup table to specify velocity and steering input as a function of time.
For some applications, hardware inputs must added. This results in the model behaving
similar to an actual driving simulator. The hardware consists of a Logitech steering wheel
with pedals and gear selector.

The simulation model takes into consideration many signals such as tire forces and ve-
locities, and accelerations of several bodies of the truck. In order for the hardware input
to be simulated, the lookup table which specifies velocity and steering input must replace
with the new signals of the Logitech hardware. The description of this process can be found
in Chapter 2.1. The way the Logitech input is simulated in the MATLAB/Simulink model
is discussed in Chapter 2.2 and the way the cruise control is simulated in Chapter 3 and
Chapter 4 respectively. Chapter 5 discusses the visualization. Finally, Chapter 6 describes
how the Graphical User Interface (GUI) is created. Conclusions and recommendations are
given in Chapter 7.

1
Chapter 2

Truck simulaton model

2.1 Initial Simulink model

For the truck driving simulator, the already existing MATLAB/Simulink truck models are
used as a stacking point. Aspects like vehicle dynamics, powertrain and tyre are included in
this models. The models will be expanded using Logitech hardware, consisting of a steer-
ing wheel, pedals and a gear selector. The MATLAB/Simulink model consists out of four
subsystems: driver, tractor, semi-trailer and trailer. In the driver subsystem the inputs for
steering, throttle and brake control, and actual velocity for the cruise control are defined
explicitly as a function of time, see Figure 2.1.

Figure 2.1: MATLAB/Simulink driver subsystem


The four inputs: steering, throttle, brake, and cruise control input are defined in several
MATLAB scripts. The cruise control subsystem is expanded as shown in Chapter 3. In this
model the cruise control switch off if the user operates the throttle. The throttle switch off if
the user operates the brake input.

The value of the inputs in the driver block are defined in a MATLAB script. However
working with MATLAB scripts can be perceived as very cryptic for users without MATLAB

2
experience. Therefore these scripts will be replaced by a Graphical User Interface (GUI). In
this GUI the user can choose between look-up tables or external input. To realize this all,
the parameters and values of the MATLAB scripts are replace by parameters and values in
the Simulink models. An example of this can be found in Figure 2.2.

Figure 2.2: Replacing MATLAB script to Simulink parameters


For simulating with the Logitech steering wheel no MATLAB parameters are needed. Therefore
all parameters in Simulink such as the initial velocity are set equal to zero.

2.2 Hardware input

To realize the external input to the truck simulator, gaming device can be used. Other
requirements include: throttle, brake, steering, gear selector and clutch inputs, and com-
patibility with Simulink. The Logitech G27 Racing Wheel as shown in Figure 2.3 fits these
requirements.

Figure 2.3: Logitech G27 Gaming Wheel, pedals and gear selector

The interaction between the Logitech hardware and Simulink is provided by the joystick

3
block in Simulink. The joystick block generates the axes, buttons and points of view signals.
The throttle and brake signals, respectively signal two and three from the axes run from
-1 to 1 when the pedals are pressed. Therefore, a Simulink saturation and gain block are
used to set the minimum value to 0 and maximum to 1. When there is a critical look at
this Simulink model, it is considered that the use of saturations in order to hold the signals
between 0 to 1 instead of -1 to 1, is not allowed. It is recommended to take a critical look
at this, see Figure 2.4.

Figure 2.4: Joystick input Simulink system


The joystick block generates several signal as one output, such as the axes output.In order to
correctly process the generated signals of the joystick block, the Simulink function block is
used.

The signals for throttle is used for the driveline. The brake input is used for the braking
system. The brake signal is divided into three signals, two signals for the front and rear axle
of the tractor, and one for the trailer. The steer signal is the first output of the axis signal
of the Joystick block. This signal is multiplied by the maximum steer angle(2.1):

steerratio (2.1)
180
By choosing the right magnitude of the steer ratio, the truck steering wheel can make the
same steer angle as the Logitech steering wheel.

4
Chapter 3

Cruise Control

The basic idea behind ak cruise control is that the current speed of the truck is maintained
with respect to a reference speed. The difference between these velocities is converted to a
throttle input. When the actual speed of the vehicle is higher than the reference speed, the
throttle input is zero and vice versa. By using the cruise control on button, see Figure 3.1,
on the steering wheel, it is possible to set a reference speed equal to the current speed.

Figure 3.1: SteeringWheelDescription


Shifting by counting up or down of the incoming signal by the means of the counter blocks in
Simulink

By using an if-else statement, the reference speed stays 0 while the button is not in use. When
this is achieved, the reference speed should also be controllable by means of the steering wheel
flippers. When operating these flippers, the speed gradually increases or decreases, as shown
in Figure 3.1. For the increasing or decreasing of the vehicle speed, use is made of two
Simulink counter blocks, see Figure 3.2.

5
Figure 3.2: Cruise control shifting Simulink subsystem.
Shifting by counting up or down of the incoming signal by the means of the counter blocks in
Simulink

One counter-block provides acceleration and the other provides deceleration. Every time a
flipper is used, the reference speed is increased or decreased by 2 km/h, depending on the
flipper being used at the time. An interaction between the cruise control and the vehicle
pedals should also be present. When the throttle, brake or clutch is pressed, the cruise
control should switch off. The implementation of this, using an if- else function, can be seen
in Figure 3.3.

Figure 3.3: Switch off cruise control Simulink subsystem


Cruise control switches off by the means of an if-else function. The incoming signals compared
with constants in the if-block. For throttle input, brake input and CC is this value 0, if the
incoming value is higher than 0, the output of the if-else function is 1. For clutch input is the
compare value 70, if the incoming value of the clutch is lower than 70, the output of the if-else
function is also 1.

If the signal from throttle or brake pedals is positive, or the signal from the clutch pedal is
lower than 70, the output will become one. This signal will then be used to reset the counter
block in Simulink, see Figure 3.4.

6
Figure 3.4: Cruise control Simulink model
Total view Simulink cruise control model, with submodels CC off system and CC accelerate
system. The value of subsystem CC accelerate system is add by the value of the original cruise
control. If the value of the subsystem CC off system is 1, the input at de reset input of the
counter is high, then the output of the counter is 0. Furthermore this output is multiplied with
the added cruise control value and added to the current value of de vehicle speed.

The output of this counter block, due to the saturation block, is 1 or 0. This value will
be multiplied with the cruise control output so set the reference speed to 0 or the desired
reference speed. The estimated value of reference speed can be used in the original cruise
control of the truck model. This enables the hardware input to control the cruise control,
which can now be fully operated using the buttons and flippers on the steering wheel as well
as turned off by using the pedals.

7
Chapter 4

Powertrain model

In the original MATLAB/Simulink LZV truck models a detailed powertrain model is not
included. This powertrain model consist of the final drive ratio and the engine of the LZV
truck. The engine torque Te is calculated by dividing a constant engine power pe by the
product of the angular velocity of the driven wheels v and a half times of the final drive
ratio nF D as shown in Formula (4.1).

pe
Te = 1 (4.1)
2 v n F D

Then, as shown in Formula(4.2), the value of the calculated engine torque Te is multiplied by
the throttle input, which varies between zero and one. By this way the engine torque varies
between zero and the maximum engine torque. Finally, the engine torque Te is multiplied by
a half of the final drive ratio nF D to calculate the moment of the driven wheels Mw .

1
Mw = Te throttle input nF D (4.2)
2

In Figure 4.1 is the Simulink model of the original powertrain model of the truck shown.

Figure 4.1: Original Simulink model of the powertrain

8
As can be concluded, this model does not take in account the transmission or clutch. There-
fore, the model is extended with a gear selector and clutch, as shown schematically in Fig-
ure 4.2. The required parameters are the angular velocity of the driven wheels such as the
original model. Other required parameters are throttle input and gear ratio.

Figure 4.2: Schematic representation of the extended powertrain and clutch.

To build the new powertrain model, the existing powertrain model of dr.ir. T. Hofman [1]
is used as reference. This model can be found in Appendix A. In order to be able to shift
smoothly, the powertrain and engine velocities should be aligned. to achieve this, two new
signals are introduced for the engine and powertrain angular velocity, respectively e and
p . For calculating the angular velocity of the engine e the parameter clutch torque Tc is
required. For calculating the clutch torque Tc are following parameters required:
angular velocity of the engine e
angular velocity of the powertrain p
gear ratio n
engine torque Te
The engine torque Te is calculated in the same way as Formula (4.1). For calculating of the
parameter angular velocity of the powertrain p the angular velocity of the driven wheels v
and gear ratio n are required. The Simulink model in Figure 4.3 will give more clarity.

9
Figure 4.3: Powertrain Simulink model

The calculation of the angular velocity of the engine e in provided in the Simulink Engine
subsystem, which is shown in Figure 4.4. For the calculation of the angular velocity of the
engine e a new parameter is required: engine inertia Je .

Figure 4.4: Engine Simulink subsystem

The angular acceleration of the engine is calculated by subtracting the engine torque Te
by the clutch torque Tc and then dividing by the engine inertia Je . By integrating this
expression the angular velocity of the engine is calculated, see Formula(4.3)

Te Tc
Z
e = (4.3)
Je

10
Another Simulink subsystem is the transmission block. In this block the moment of the driven
wheels Mw and the angular velocity of the powertrain p are calculated. The transmission
subsystem is shown in Figure 4.5.

Figure 4.5: Transmission Simulink subystem

With respect to the calculation of the angular velocity of the powertrain p , the angular
velocity of the driven wheels w is divided by the gear ratio n, Formula(4.4)

v
p = (4.4)
n
The moment of the driven wheels is calculated by dividing the clutch torque Tc by the sum of
the gear ratio n and final drive ratio nF D , then multiplied by the throttle input, see Formula
(4.5).

Tc throttle input
Mv = (4.5)
n nF D

Another subsystem in Simulink is the clutch subsystem. The parameters engine torque Te ,
clutch pressure Pc , angular engine velocity e , angular powertrain velocity p and gear ratio
n are inputs in this block, the clutch subsystem is shown in Figure 4.6.

11
Figure 4.6: Clutch Simulink subsystem

For the calculation of the clutch torque Tc use is made of the interpreted MATLAB function
block in Simulink. This block refers to an external MATLAB script. For the calculation
of the clutch torque Tc a distinction is made between the clutch slip and stick torque. The
function determines whether the clutch is slipping or sticking in certain edge conditions. If
the absolute value of the subtraction of the angular velocity of the engine e and powertrain
p is lower or equal to 1, and the absolute value of clutch pressure times 1.3 is equal or
higher than the sticking clutch torque Tc,stick , the clutch torque is sticking. Otherwise, the
clutch torque is slipping Tc,slip .
f u n c t i o n [ output ]= s w i t c h f u n c ( u )
% function inputs
Te = u ( 1 ) ;
u1 = u ( 2 ) ;
we = u ( 3 ) ;
rgear = u ( 4 ) ;
wp = u ( 5 ) ;
% f i n a l drive ratio
rd = 0 . 1 ;
% v e h i c l e r o t a t i n g i n e r t i a a t primary s h a f t
J v e q =100 rd rd r g e a r r g e a r ;
% engine i n e r t i a
Je = 0 . 3 ;
% tolerance
eps = 1 ;
%% i f c l u t c h i s s l i p p i n g t h e f o l l o w i n g i n t e r f a c e t o r q u e a p p l i e s :
T c 1 s l i p=u1 s i g n ( wewp ) ;
%% i f c l u t c h i s s t i c k i n g t h e f o l l o w i n g i n t e r f a c e t o r q u e a p p l i e s :
T c 1 s t i c k =( J v e q Te+Je rd r g e a r ) / ( Je+J v e q ) ;
i f ( abs ( wewp) <= e p s ) & ( abs ( 1 . 3 u1)>=abs ( T c 1 s t i c k ) ) ,
Tc1=T c 1 s t i c k ;
else
Tc1=T c 1 s l i p ;
end
output = Tc1 ;

12
In Equations (4.6) the clutch torque is calculated while slipping. The clutch pressure Pc is
multiplied by the sign of the subtraction of the angular velocity of the engine e and the
angular velocity of the powertrain p . The sign of this subtraction is one if the subtraction
is positive and zero if the subtraction is negative. As an approximation, the clutch torque
Tc is equal to the clutch power Pc if the subtraction is positive, so when the angular velocity
of the engine is higher than the angular velocity of the powertrain.

Tc,slip = Pc sign(we wp ) (4.6)

When the clutch torque is sticking, the parameters engine torque Te , engine inertia Je , gear
ratio n, final drive ratio nF D and the inertia at the primary shaft side Jv,prim are multiplied
and then divided by the interia of the engine Je and inetria at the primary shaft side Jv,prim .
If the clutch torque is sticking, equation (4.7) holds:

Jv,prim Te Je nF D n
Tc,stick = (4.7)
Je + Jv,prim

For calculating the inertia of the primary shaft side the following Equation (4.8) holds.
Here vehicle inertia Jv , gear ratio n squared, and final drive ratio nF D squared are multi-
plied.

Jv,prim = Jv n2F D n2 (4.8)

The transmission operates via the hardware gear selector and clutch from Logitech.A disad-
vantage of the Logitech gear selector is that it only consist of six gears, while gear selectors
of trucks typically have more gears. It is decided to still use the transmission model in the
simulation, to make the simulation more realistic. The signal for the gear ratio is generated
in de driver block where the Simulink joystick block is integrated. In Figure 4.7 is shown
how the gear ratio is selected when the Logitech gear selector is operated with an if else
function. The merge block ensures that there is always only one output is possible.

13
Figure 4.7: Selecting gear ratio Simulink model

14
Chapter 5

Visualization

5.1 VRML Language

The visualization is created in the programming language VRML, which is an abbreviation


of Virtual Reality Modeling Language. In MATLAB it is possible to create a virtual reality
world using the 3D World Editor. In the 3D World Editor nodes are added to the ROOT.
The main node is a transform. In order to make this transform an object, a shape can
be inserted as a child of the transform. In a transform the translation and rotation of
the children is established. Parameters such as the wheelbase should be easily modifiable by
the user. These parameters are adjusted in MATLAB. However, it is not possible to make
changes via a MATLAB script in the 3D World Editor. Therefore, it is necessary to use a
text editor to modify the visualization. This is achieved by writing a script in MATLAB
which creates a VRML file for the visualization. In this way the visualization automatically
adjust when the user changes parameters. In Appendix B is shown how this is done for a
several shapes of the trucks.

5.2 Dynamic VRML in Simulink

The purpose of the VRML model of the LZV truck is to visualize how the truck responds
to steering, brake, and throttle inputs. In order to achieve this, it is necessary to connect
these VRML models with the Simulink models. Simulink creates this connection with the
VR sink block. This block indicates the VRML file which needs to be visualized. Next, the
translations, rotations, or scales of the nodes can be connected to the Simulink inputs, as is
illustrated in Figure 5.1.

15
Figure 5.1: VR sink block parameters
All the nodes created in the ROOT are shown in the VRML Tree. The values such as rotation
or translation can be selected. By this way an input of the VR sink block is created for
concerned values.

5.3 Steering wheel

It is desirable to provide a VRML visualization of the steering input of the Logitech steering
wheel. For the creation of the steering wheel in VRML, the VRML model of an already
existing steering wheel is used. This VRML steering wheel model was already made by
MathWorks for the Simulink Skoda Octavia model [3]. The steering wheel consists of two
parts, the white round frame and, a yellow and red piece to indicate the rotation. The yellow
part always remains at the same position, the red part rotates equal to the current steering
input of the Logitech steering wheel. In Figure 5.2 this VRML steering wheel is shown.

Figure 5.2: VRML Steering wheel

It is necessary to write a MATLAB script for the VRML steering wheel to create a VRML
file, because Mathworks created this model in the 3D World Editor. This is necessary because
the position or scale should be variable in case parameters of the LZV truck change. In this

16
way, it is possible to turn off the visualization of the steering wheel by the user. In the
original Simulink model a signal for the steering input was already created. This signal is
used as an input for the VR sink block. In Appendix B the MATLAB script which created
a VRML file for the steering wheel can be found.

5.4 Tire force arrows

In addition to the visualization of the steering input, it is also desirable to provide a visu-
alization of the magnitude of the tire forces. This visualization is done by means of three
arrows, in three different colours for the X, Y and Z direction. In Figure 5.3 is shown how
Simulink generates the tire force magnitude signals.

Figure 5.3: Simulink model which generates the signals for the magnitude of the tire
forces. The rear axle consist of four wheels, this is the reason why there are two tire
force signals added. The signals are multiplied by a scale factor.

The tire force arrows, which are shown in Figure 5.4, are also existing shapes in the Math-
Works Skoda Octavia model [3].

17
Figure 5.4: VRML arrows for indicating the magnitude of the tire forces.

In the original truck Simulink model tire force signals are already generated. These signals
are used as an input of the VR sink block. The MATLAB file to create these arrows is shown
in Appendix B.

5.5 Displays

It is desirable to easily be able to read the current vehicle speed of the truck. For this purpose
a speedometer is used. The decision has been made to create a digital display because it is
easier to realize in VRML and because todays trucks are equipped with digital displays. To
build up the display use is made of the HUD (Head Up Display) which is already present
in MathWorks [4]. The signal for the vehicle speed is already available in de Simulink truck
model. Also, a display is designed for the engine speed. This is done because the model is
not equiped with sound. For shifting at the appropriate moments, it is desirable to provide
a visual map of the engine speed. In Figure 5.5 shows the VRML display. The MATLAB
file for creating these displays is given in Appendix B.

18
Figure 5.5: VR text block in Simulink and editing parameters for the text displays.

Different from foregoing shapes such as the steering wheel, or tire force arrows, the text
signals are not used in the VR sink block in Simulink. In this case, a separate block called
VR Text output is used in Simulink. It has to be indicated in this block which text should
be placed in the node.

5.6 Viewpoint

The original model comes equipped with different viewpoints: rear, front, top, and side.
These viewpoints are not connected to the rotation of the truck. Therefore, it may occur
that a part of the truck is no longer visible when the truck makes a turn. In order to create
this, a rotating viewpoint of the top of the truck is created. In Figure 5.6 the difference
between the rotating top view (right) and the normal top view (left) is displayed. Especially
when parking, it is desirable to see the entire truck. The MATLAB file for creating this
viewpoint is given in Appendix B.

Figure 5.6: standard top viewpoint (left) and rotating viewpoint (right).

In order to the rotating viewpoint from the top of the truck, viewpoints are created from
the drivers and mirrors view, see Figure 5.7

19
Figure 5.7: Right mirror viewpoint (left top), left mirror viewpoint (right top) and drivers
viewpoint (bottom left).

5.7 Environment design

To make the simulation more realistic, an environment is created. The environment consist of
a distribution centre and a roundabout. In this way it can be simulated how such long vehicles
with multiple articulations manoeuvre when parking at the gate of a distribution centre. The
distribution centre is shown in Figure 5.8, the M-file for creating the environment is shown
in Appendix B. When the user looks at the top of the truck, it is difficult to estimate how

Figure 5.8: Distribution centre

fast the truck is going. Therefore some road poles and trees are included in the visualization.
In this way it is easier to estimate the acceleration and speed of the truck, see Figure 5.9.

20
Figure 5.9: visualization of road poles and trees

21
Chapter 6

Graphical User Interface

A Graphical User Interface (GUI) is made to create an easy way to set simulation parame-
ters. In this GUI the user can select which truck is to be simulated. In the GUI the user can
choose between a constant steering input and cruise control speed, or simulate with Logitech
input, as shown in Figure 6.1.

Figure 6.1: Graphical User Interface

Because the VRML visualization is written using MATLAB functions, it is easy to add
more parameters to the GUI. Parameters such as the wheelbase lengths of trailers or dis-
abling visual components, for example steering wheel, text displays, or tire force arrows,
are easy to set. Also constant manoeuvring such as driving a sine wave or parking at the
distribution centre can be added in this GUI. In Appendix C a user guide for building a GUI
can be found.

22
Chapter 7

Conclusions and
recommendations

The goal of the project was to expand an existing truck model with Logitech gaming hard-
ware input. The MATLAB/Simulink truck simulation model interacts with the steering
wheel, throttle and brake pedal, some buttons and flippers on the steering wheel, clutch and
gear selector. The joystick block in Simulink generates signals when the Logitech hardware
operates. The input signals are used in the same way as the original simulation inputs.
The truck reacts, as can be expected from a regular truck, when the hardware input is
operated.
In addition the cruise control can now be operated using buttons and flippers on the steering
wheel, as well as being cancelled when a pedal is operated. The buttons and flippers work
similarly to regular cruise control buttons in a passenger car. While driving the truck, the
user can shift using the gear selector and clutch. Finally, the user can easily make choices
between several LZV trucks or simulation inputs using the GUI.
Summarizing: the truck simulator can now be directly operated using the Logitech gaming
hardware. This gives the driver the sensation of actually driving a truck. Also an environ-
ment with a roundabout and distribution centre is created .
When it is desirable to simulate without hardware input. It is recommended to expand the
model. For example it is possible to create preprogrammed manoeuvres in MATLAB. Al-
lowing the truck to manoeuvre without further control inputs making three-quarters rounds
at the roundabout and then parking backwards into the distribution centre is possible. The
GUI can also be extended with respect to choices of the vehicle parameters such as the
wheelbase. The visualization is create by MATLAB scripts which easily can be adapt by de
GUI script.
When there is a critical look at the Simulink model, some improvements could be made.
Firstly the use of saturations in the driver block in order to adapt the range of the joystick
block signals. Original, the throttle signal runs for example from -1 to 1, but with the
saturation just between 0 and 1. In this way a death zone is created, so there must be
some other way be devised in order to solve this problem. Another point is the use of if-else
function in the Simulink models. These if-else function which are used for for example the
gear ratio selection looks cumbersome. It is easer to write an external MATLAB script using
the MATLAB fcn block in Simulink. Finally, there still needs to be looked critically at the

23
whole transmission model. There are some small issues such as the fact that the throttle
input actually must be connected to the engine subsystem block instead of the powertrain
subsystem block.

24
25
Bibliography

[1] Eindhoven university of Technology, dr.ir. I. Bessilink, Dynamics and Control Technology
Group, MATLAB/Simulink LZV truck models
[2] Eindhoven university of Technology, dr.ir. T. Hofman, Fac. Werktuigbouwkunde, MAT-
LAB/Simulink transmission with clutch clutch,
[3] The MathWorks, Inc (1998) Vehicle Dynamics Visualization - Simulation of Mul-
tiple Objects, Accessed November 9, 2015, http://nl.mathworks.com/help/sl3d/
examples/vehicle-dynamics-visualization-simulation-of-multiple-objects.
html?s_tid=srchtitle
[4] The MathWorks, Inc (1998) Plane Take-Off with HUD Text, Accessed November 11, 2015,
http://nl.mathworks.com/help/sl3d/examples/plane-take-off-with-hud-text.
html?s_tid=srchtitle
[5] The Advisory Group on Computer Graphics (AGOCG) (1999) A Guide to VRML 2.0
and an Evaluation of VRML Modelling Tools, Accessed November 11, 2015, http://
www.agocg.ac.uk/train/vrml2rep/cover.htm

26
27
Appendices

28
Appendix A

Original MATLAB/Simulink
transmission model

To build the new powertrain Simulink model, the existing powertrain Simulink model of
dr.ir. T. Hofman [1] is used as reference. An overview of the Simulink blocks will be given
in this appendix.

Figure A.1: Original entire transmission Simulink model

29
Figure A.2: Original engine Simulink subsystem

Figure A.3: Original transmission and Vehicle Simulink subsystem

30
Figure A.4: Original transmission Simulink subsystem

Figure A.5: Original vehicle Simulink subsystem

31
Figure A.6: Original clutch Simulink subsystem

1 f u n c t i o n [ output ]= s w i t c h f u n c ( u )
2

3% function inputs
4 rgear = u(1) ;
5 u1 = u ( 2 ) ;

6 we = u ( 3 ) ;

7 wp = u ( 4 ) ;

8 Tk = u ( 5 ) ;

9 Te = u ( 6 ) ;

10 Tc1 = u ( 7 ) ;

11 s t i c k 1 = u ( 8 ) ;

12

13

% f i n a l drive ratio
14

rd = . 2 ;
15

16

% v e h i c l e i n e r t i a a t primary s h a f t
17

J v e q =100 rd rd r g e a r r g e a r ;
18

19

% engine i n e r t i a
20

Je = . 1 5 ;
21

22

23% tolerance
24 e p s = 1 ;

25

26%% i f c l u t c h i s s l i p p i n g t h e f o l l o w i n g i n t e r f a c e t o r q u e a p p l i e s :
27 T c 1 s l i p=u1 s i g n ( wewp) ;

28

%% i f c l u t c h i s s t i c k i n g t h e f o l l o w i n g i n t e r f a c e t o r q u e a p p l i e s :
29

T c 1 s t i c k =( J v e q Te+Je Tk rd r g e a r ) / ( Je+J v e q ) ;
30

32
31

32 i f ( abs ( wewp) <= e p s ) & ( abs ( 1 . 3 u1 )>=abs ( T c 1 s t i c k ) ) ,


33 Tc1=T c 1 s t i c k ;
34 stick1 = 1;
35 e l s e

36 Tc1=T c 1 s l i p ;
37 s t i c k 1 =0;
38 end

39

40 f l a g =(abs ( 1 . 3 u1 )>=abs ( T c 1 s t i c k ) ) ;
41 f l a g 2 =(abs ( wewp) <= e p s ) ;

42

% function outputs
43

output = [ Tc1 , f l a g , f l a g 2 , s t i c k 1 ] ;
44

33
Appendix B

VRML visualization user guide

The Virtual Reality Modelling Language (VRML) is used to display three-dimensional ob-
jects in a VRML viewer which is part of the Simulink 3D Animation toolbox. VRML provides
a platform for creating interactive three-dimensional virtual worlds. The LZV trucks have
all been visualized in VRML already. This visualization is enhanced with several parts such
as a visual steering wheel, a display for the vehicle and motor speed, and a visualization of
the magnitude of the tire forces. For these parts the same method is used as the visualization
of the LZV trucks themselves. Figure B.1 schematically shows how the visualization of the
LZV trucks has proceeded

Figure B.1: Schematic roadmap visualization LZV trucks


For the visualization of every LZV truck a MATLAB file is written which refers to several
MATLAB functions for truck parts such as the cabin or trailer. In this way a VRML file is
created for each truck. This VRML file is used in the VR sink block in MATLAB Simulink. All
the visualization parameters such as translation or rotation are connected with the truck model
in MATLAB Simulink.

All the LZV trucks consists of standard parts such as boxes and cylinders. The boxes are
used for parts such as: semi-trailers, dollies, trailers, tractors, and engines. In the next
example a box for the engine is created. The first line of the VRML file contains the header
#VRML V2.0 utf. This identifies it as a VRML 2.0 file, as opposed to a VRML 1.0 file, for
example. All VRML files must start with this header. The utf keyword refers to the UTF-8
international character set used in the file. A commend line starts with the # symbol. This
indicates that all the text with follows it, until the end of the line is a comment, and should
be ignored by the VRML software.

#VRML V2 . 0 u t f 8
1

3DEF e n g i n e Transform {
4 t r a n s l a t i o n 0.2 0 . 9 0

34
5 r o t a t i o n 1 0 0 1.57079632679490
6 children [
7 Shape {
8 a p p e a r a n c e Appearance {
9 material DEF e n g i n e m a t e r i a l M a t e r i a l {
ambientIntensity 0.2 diffuseColor 1 0 0 }
10 }
11 geometry Box { s i z e 1 . 8 0 . 3 5 0 . 7 }
12 }
13 ]
14 }

The rest of a VRML file consists of a list of nodes, each of which contain part of the
information that describes a shape or particular properties of an object, such as its colour or
coordinates. Each node consists of a name, that indicates the nodes type, followed by a set
a curly braces containing zero or more fields, that define the attributes of that node. A field
statement consists of the field name followed by one or more values. Fields can be written in
any order. Node type names start with a capital letter, field names begin with a lower case
letter. The table in Figure B.2 lists all of different types of VRML nodes be seen.

Figure B.2: VRML nodes

In the example, the nodes used are shape, box, appearance, and material. The shape node
contains two fields, geometry and appearance, each of which require other nodes as their val-
ues. The geometry field contains the Box node and the appearance field takes the appearance
node as its value. The appearance node then in turn contains another node, called Material.
This hierarchical structure of nodes contained within other nodes is called the scene graph.
In order to translate, rotate or scale an object the Transform node is used. The effect of the

35
node is to create a new coordinate system, which is used by all the children nodes of the
transform. A Transform node can be a child of another transform, so producing a hierarchy
or stack of coordinate transformations. The first Transform node translates the box to -0.2,
0.9, and 0 in the world coordinate system. VRML allows a name to given to a node, using
the DEF syntax. VRML uses a right-handed coordinate system. By default, the viewer is
on the Z-axis looking towards the origin with the X-axis to the right and Y-axis upwards.
Having defined the objects geometry through the Box node, it is necessary to describe the
objects colour and surface properties using the appearance node. The appearance node has
the field material. The material field takes the material node as its value. If the appearance
node is left undefined the object will be rendered as white. The material node specifies the
colour and reflective properties of an object with six fields. The diffuseColor field defines
the base colour of the object, that is reflected in all directions when it is illuminated. The
colour is specified using three floating point numbers ranging between 0.0 and 1.0 and rep-
resenting the amounts of red, green and blue. The default value is 0.8 0.8 0.8, which is a
grey colour.
The specularColor field defines the colour of the shiny highlights on the object. By
default this is 0.0 0.0 0.0 (black).
The emissiveColor field specifies the colour given off by objects, independent of any
light sources. The default value is 0.0 0.0 0.0 (black).
The shininess value controls the sharpness of the specular highlight. Increasing this
value will make the object appear more shiny. the default value is 0.2.
The transparency field specifies how clear the object is. A value of 0.0 (default)
indicates an opague object, 1.0 indicates full transparency.
The ambientIntensity value is used to simulate ambient (indirect) lighting of the object.
the default value is 0.2. In the first example, only the diffuseColor field is required to
define a basic yellow colour for the box shape.
In Figure B.3 is shown what the engine VRML script look like in the 3D World Editor.

36
Figure B.3: Visualization of the engine in the 3D World Editor.

The Box node has a single field called size, which sets the dimensions of the box shape that
is to be drawn. The field name is followed by three values that define the lengths of sides,
parallel to the X, Y and Z axes respectively, with the centre of the box at the origin. To create
the truck as described in the foregoing manner, the VRML script can been extended with
all the required parts. However, it is desirable to keep parameters such as translation, scale,
or rotation variable. It is not possible define parameters variable directly in a VRML file.
So a MATLAB script is created which generates a VRML file dpending on the parameters
used in the MATLAB script.
The main MATLAB script writes a VRML file for the whole LZV truck. This MATLAB
script refers to several MATLAB functions for writing the VRML files such as for the tires,
boxes, and cylinders (respectively wrl tyre.m, wrl box.m, and wrl cylinder.m). The inputs
for example the wrl box function are fid, box name, and a number of matrices for translation,
colour, and box size.

1 f i l e n a m e= LZV A . w r l
2 f i d = f o p e n ( f i l e n a m e , w ) ;
3

4 wrl header ( f i d ) ;
5 wrl text ( fid ) ;

6 wrl environment ( f i d ) ;

8 wrl tyre ( fid , tyre1 ,[ 0 1 0.5] , 0.55 ,0.315) ;


9 wrl tyre ( fid , tyre2 ,[ 0 1 0.5] ,0.55 ,0.315) ;
10 w r l c y l i n d e r ( f i d , f r o n t a x l e , [ 0 0 0.5] ,[0 0 1] ,0.1 ,2.4) ;
11

12 wrl tyre ( fid , tyre3 ,[ 3.8 1 0.5] ,0.55 ,0.315) ;

37
13 wrl tyre ( fid , tyre4 ,[ 3.8 0.6 0 . 5 ] , 0 . 5 5 , 0 . 3 1 5 ) ;
14 w r l tyre ( fid , tyre5 , [ 3 . 8 0.6 0 . 5 ] , 0 . 5 5 , 0 . 3 1 5 ) ;
15 w r l tyre ( fid , tyre6 , [ 3 . 8 1 0.5] ,0.55 ,0.315) ;
16 w r l c y l i n d e r ( fid , r e a r a x l e ,[ 3.8 0 0 . 5 ] , [ 0 0 1 ] , 0 . 1 , 2 . 6 ) ;
17

18 wrl box ( fid , c h a s s i s f r o n t , [ 0 0 0 . 9 ] , [ 0 . 9 0.9 0 . 9 ] , [ 2 . 6 1


0.2]) ;
19 w r l b o x ( f i d , c h a s s i s r e a r ,[ 2.7 0 0 . 9 ] , [ 0 . 9 0.9 0 . 9 ] , [ 3 . 3 0.8
0.2]) ;
20

21 wrl box ( fid , engine ,[ 0.2 0 0 . 9 ] , [ 1 0 0 ] , [ 1 . 8 0.35 0 . 7 ] ) ;


22

23 w r l c a b i n e ( f i d , [ 0 . 2 0 2 . 2 ] , [ 1 1 0 ] , [ 2 . 2 5 2 . 2 5 2 ] , [ 0.5 2
1 . 4 ] , [ 0.5 2 1 . 4 ] , [ 4 . 2 2 1 . 4 ] , [ 4 . 2 2 1 . 4 ] , [ 1 1
1 ] , [ 1 1 1] , [ 1 1 1] , [ 1 1 1]) ;

In the function wrl box use is made of the fprintf query which creates a VRML file for the box.
There can be easily seen that the name, translation, colour and box size are variable.

1 f u n c t i o n [ ] = w r l b o x ( f i d , name , t r a n s , c o l o r , b o x s i z e )
2

3 f p r i n t f ( f i d , DEF %s Transform {\n , name ) ;


4 f p r i n t f ( fid , t r a n s l a t i o n %0.5 g %0.5 g %0.5 g\n , t r a n s ( 1 ) , t r a n s
( 3 ) , t r a n s ( 2 ) ) ;
5 f p r i n t f ( fid , r o t a t i o n 1 0 0 1.57079632679490\n ) ;
6 f p r i n t f ( fid , children [\n ) ;
7 f p r i n t f ( fid , Shape {\n ) ;
8 f p r i n t f ( fid , a p p e a r a n c e Appearance {\n ) ;
9 f p r i n t f ( fid , material DEF %s m a t e r i a l M a t e r i a l {
a m b i e n t I n t e n s i t y 0 . 2 d i f f u s e C o l o r %0.5 g %0.5 g %0.5 g }\n ,
name , c o l o r ) ;
10 f p r i n t f ( f i d , }\n ) ;
11 f p r i n t f ( f i d , geometry Box { s i z e %0.5 g %0.5 g %0.5 g }\n ,
boxsize (1) , boxsize (2) , boxsize (3) ) ;
12 f p r i n t f ( f i d , }\n ) ;
13 f p r i n t f ( f i d , ]\n ) ;
14 f p r i n t f ( f i d , }\n\n ) ;

The main MATLAB script also refers to the function wrl cabine which has more inputs
than the wrl box function. These inputs are used for the scaling and translation of the tire
force arrows. The function wrl cabine also refers to the function wrl Steering wheel and four
times to the function wrl Tyre force arrows for each tire of the tractor. Finally, a rotating
viewpoint of the top of the truck is created in the wrl cabine MATLAB function. The
viewpoint node specifies the position and orientation of a favoured view within the VRML
world. When a VRML browser loads a VRML world containing a viewpoint node, the scene

38
will be initially displayed from that viewpoint. A VRML file can contain any number of
viewpoint nodes, although only one can be in use at a time. So, when a browser loads a
world with multiple viewpoint definitions it will initially bind to the first viewpoint listed in
the file.

1 function []= wrl cabine ( fid , trans cab , color cab , boxsize ,
trans tfa 1 , trans tfa 2 , trans tfa 3 , trans tfa 4 ,
scale tfa 1 , scale tfa 2 , scale tfa 3 , scale tfa 4 )
2

3 f p r i n t f ( f i d , DEF %s Transform {\n , cab ) ;


4 f p r i n t f ( fid , t r a n s l a t i o n %0.5 g %0.5 g %0.5 g\n , t r a n s c a b ( 1 ) ,
t r a n s c a b ( 3 ) , t r a n s c a b ( 2 ) ) ;
5 f p r i n t f ( fid , r o t a t i o n 1 0 0 1.57079632679490\n ) ;
6 f p r i n t f ( fid , children [\n ) ;
7 f p r i n t f ( fid , Shape {\n ) ;
8 f p r i n t f ( fid , a p p e a r a n c e Appearance {\n ) ;
9 f p r i n t f ( fid , material DEF %s m a t e r i a l M a t e r i a l {
a m b i e n t I n t e n s i t y 0 . 2 d i f f u s e C o l o r %0.5 g %0.5 g %0.5 g }\n ,
cab , c o l o r c a b ) ;
10 f p r i n t f ( f i d , }\n ) ;
11 f p r i n t f ( f i d , geometry Box { s i z e %0.5 g %0.5 g %0.5 g }\n ,
boxsize (1) , boxsize (2) , boxsize (3) ) ;
12 f p r i n t f ( f i d , }\n ) ;
13

14 wrl Steering Wheel ( fid , [0 0 1 . 5 ] , [ 0 . 1 0.1 0 . 1 ] )


15

16 Tyre force arrow ( fid , Tyre Force 1 , [ trans tfa 1 (1) ,


trans tfa 1 (2) , trans tfa 1 (3) ] , [ s c a l e t f a 1 (1) ,
s c a l e t f a 1 (2) , s c a l e t f a 1 (3) ] )
17 T y r e f o r c e a r r o w ( f i d , Tyre Force 2 , [ trans tfa 2 (1) ,
trans tfa 2 (2) , trans tfa 2 (3) ] , [ s c a l e t f a 2 (1) ,
s c a l e t f a 2 (2) , s c a l e t f a 2 (3) ] )
18 T y r e f o r c e a r r o w ( f i d , Tyre Force 3 , [ trans tfa 3 (1) ,
trans tfa 3 (2) , trans tfa 3 (3) ] , [ s c a l e t f a 3 (1) ,
s c a l e t f a 3 (2) , s c a l e t f a 3 (3) ] )
19 T y r e f o r c e a r r o w ( f i d , Tyre Force 4 , [ trans tfa 4 (1) ,
trans tfa 4 (2) , trans tfa 4 (3) ] , [ s c a l e t f a 4 (1) ,
s c a l e t f a 4 (2) , s c a l e t f a 4 (3) ] )
20

21 f p r i n t f ( fid , DEF %s Anchor {\n , V i e w p o i n t T o p R o t a t i n g ) ;


22 f p r i n t f ( fid , children [\n ) ;
23 f p r i n t f ( f i d , DEF %s Transform {\n , v e h i c l e p o s i t i o n ) ;
24 f p r i n t f ( f i d , t r a n s l a t i o n 0 0 . 2 8 6 4 0\n ) ;
25 f p r i n t f ( f i d , children [\n ) ;
26 f p r i n t f ( f i d , DEF %s Transform {\n , v e h i c l e r o t a t i o n ) ;
27 f p r i n t f ( f i d , children [\n ) ;
28 f p r i n t f ( f i d , DEF %s Viewpoint {\n , View Top Rotating ) ;
29 f p r i n t f ( f i d , fieldOfView 0.9\n ) ;

39
30 f p r i n t f ( fid , jump TRUE\n ) ;
31 f p r i n t f ( f i d , o r i e n t a t i o n 1 0 0 0\n ) ;
32 f p r i n t f ( f i d , position 10 0 30\n ) ;
33 f p r i n t f ( f i d , d e s c r i p t i o n Top r o t a t i n g view \n ) ;
34 f p r i n t f ( f i d , }\n ) ;
35 f p r i n t f ( f i d , ]\n ) ;
36 f p r i n t f ( f i d , }\n ) ;
37 f p r i n t f ( f i d , ]\n ) ;
38 f p r i n t f ( f i d , }\n ) ;
39 f p r i n t f ( f i d , ]\n ) ;
40 f p r i n t f ( f i d , }\n\n ) ; f p r i n t f ( f i d , ] \ n ) ;
41 f p r i n t f ( f i d , }\n\n ) ;

In Figure B.4 is shown how the VRML script for the cabin with steering wheel and tire force
arrows creates the visualization in the 3D World Editor.

Figure B.4: Visualization of the cabine of the LZV truck with the steering wheel and
tire force arrows

40
For the steering wheel and tyre force arrows VRML scripts use is made of already consisting
VRML Octavia [3] files from MathWorks. For these VRML files a MATLAB script are
created such as for the box and cabin. Only the scale, translation, and rotation are different
from the original VRML file from MathWorks. The steering wheel is created using the
Extrusion node. This node describes a shape using a cross section that is extruded along a
3D spine.

1 function []= Tyre force arrow ( fid , name tyre force ,


trans tyre force , scale tyre force )
2

3 f p r i n t f ( f i d , DEF %s Transform {\n , n a m e t y r e f o r c e ) ;


4 f p r i n t f ( fid , t r a n s l a t i o n %0.5 g %0.5 g %0.5 g\n ,
trans tyre force (1) , trans tyre force (2) , trans tyre force
(3) ) ;
5 f p r i n t f ( f i d , s c a l e %0.5 g %0.5 g %0.5 g \n , s c a l e t y r e f o r c e (1) ,
s c a l e t y r e f o r c e (2) , s c a l e t y r e f o r c e (3) ) ;
6 f p r i n t f ( fid , children [\n ) ;
7 f p r i n t f ( fid , Switch {\n ) ;
8 f p r i n t f ( f i d , whichChoice 0\n ) ;

9 f p r i n t f ( fid , choice [\n ) ;


10 f p r i n t f ( f i d , Shape {\n ) ;

11 f p r i n t f ( f i d , geometry I n d e x e d L i n e S e t {\n ) ;
12 f p r i n t f ( f i d , c o l o r I n d e x 0 1 2\n ) ;

13 f p r i n t f ( f i d , c o l o r P e r V e r t e x FALSE \n ) ;

14 f p r i n t f ( f i d , c o o r d I n d e x 0 1 1 0 2 1 0 3 1 \n ) ;
15 f p r i n t f ( f i d , c o o r d C o o r d i n a t e {\n ) ;
16 f p r i n t f ( f i d , p o i n t 0 0 0 1 0 0 0 1 0 0 0 1 \n ) ;
17 f p r i n t f ( f i d , }\n ) ;
18 f p r i n t f ( f i d , c o l o r C o l o r {\n ) ;
19 f p r i n t f ( f i d , c o l o r 1 0 0 0 1 0 0 0 1\n ) ;
20 f p r i n t f ( f i d , }\n ) ;
21 f p r i n t f ( f i d , }\n ) ;
22 f p r i n t f ( f i d , }\n ) ;
23 f p r i n t f ( f i d , Shape {\n ) ;

24 f p r i n t f ( f i d , geometry I n d e x e d L i n e S e t {\n ) ;
25 f p r i n t f ( f i d , c o l o r I n d e x 0 1 2\n ) ;

26 f p r i n t f ( f i d , c o l o r P e r V e r t e x FALSE \n ) ;

27 f p r i n t f ( f i d , c o o r d I n d e x 0 1 1 2 3 1 4 5 1 \n ) ;
28 f p r i n t f ( f i d , c o o r d C o o r d i n a t e {\n ) ;
29 f p r i n t f ( f i d , p o i n t 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1\n ) ;
30 f p r i n t f ( f i d , }\n ) ;
31 f p r i n t f ( f i d , c o l o r C o l o r {\n ) ;
32 f p r i n t f ( f i d , c o l o r 1 0 0 0 1 0 0 0 1\n ) ;
33 f p r i n t f ( f i d , }\n ) ;
34 f p r i n t f ( f i d , }\n ) ;
35 f p r i n t f ( f i d , }\n ) ;
36 f p r i n t f ( f i d , ]\n ) ;
37 f p r i n t f ( f i d , }\n ) ;

41
38 f p r i n t f ( fid , ]\n ) ;
39 f p r i n t f ( f i d , }\n\n ) ;

For shapes such as the tire force arrows it is necessary to use the indexedLineSet node, which
defines the coordinates of each face. First, the 3D coordinates of the square are listed using
the coordinate node, then the coordIndex field describes the order in which the coordinate
points should be joined together to form a single face. The order is important because it
defines which side of the face is the front. By default, only the front face is rendered. Both
sides are rendered if the solid field is made FALSE. There is also a pointSet node that defines
a set of points and a indexedLineSet node for defining a 3D polyline.

1 function []= Tyre force arrow ( fid , name tyre force ,


trans tyre force , scale tyre force )
2

3 f p r i n t f ( f i d , DEF %s Transform {\n , n a m e t y r e f o r c e ) ;


4 f p r i n t f ( fid , t r a n s l a t i o n %0.5 g %0.5 g %0.5 g\n ,
trans tyre force (1) , trans tyre force (2) , trans tyre force
(3) ) ;
5 f p r i n t f ( f i d , s c a l e %0.5 g %0.5 g %0.5 g \n , s c a l e t y r e f o r c e (1) ,
s c a l e t y r e f o r c e (2) , s c a l e t y r e f o r c e (3) ) ;
6 f p r i n t f ( fid , children [\n ) ;
7 f p r i n t f ( fid , Switch {\n ) ;
8 f p r i n t f ( f i d , whichChoice 0\n ) ;

9 f p r i n t f ( fid , choice [\n ) ;


10 f p r i n t f ( f i d , Shape {\n ) ;

11 f p r i n t f ( f i d , geometry I n d e x e d L i n e S e t {\n ) ;
12 f p r i n t f ( f i d , c o l o r I n d e x 0 1 2\n ) ;

13 f p r i n t f ( f i d , c o l o r P e r V e r t e x FALSE \n ) ;

14 f p r i n t f ( f i d , c o o r d I n d e x 0 1 1 0 2 1 0 3 1 \n ) ;
15 f p r i n t f ( f i d , c o o r d C o o r d i n a t e {\n ) ;
16 f p r i n t f ( f i d , p o i n t 0 0 0 1 0 0 0 1 0 0 0 1 \n ) ;
17 f p r i n t f ( f i d , }\n ) ;
18 f p r i n t f ( f i d , c o l o r C o l o r {\n ) ;
19 f p r i n t f ( f i d , c o l o r 1 0 0 0 1 0 0 0 1\n ) ;
20 f p r i n t f ( f i d , }\n ) ;
21 f p r i n t f ( f i d , }\n ) ;
22 f p r i n t f ( f i d , }\n ) ;
23 f p r i n t f ( f i d , Shape {\n ) ;

24 f p r i n t f ( f i d , geometry I n d e x e d L i n e S e t {\n ) ;
25 f p r i n t f ( f i d , c o l o r I n d e x 0 1 2\n ) ;

26 f p r i n t f ( f i d , c o l o r P e r V e r t e x FALSE \n ) ;

27 f p r i n t f ( f i d , c o o r d I n d e x 0 1 1 2 3 1 4 5 1 \n ) ;
28 f p r i n t f ( f i d , c o o r d C o o r d i n a t e {\n ) ;
29 f p r i n t f ( f i d , p o i n t 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 1\n ) ;
30 f p r i n t f ( f i d , }\n ) ;
31 f p r i n t f ( f i d , c o l o r C o l o r {\n ) ;

42
32 f p r i n t f ( fid , c o l o r 1 0 0 0 1 0 0 0 1\n ) ;
33 f p r i n t f ( f i d , }\n ) ;
34 f p r i n t f ( f i d , }\n ) ;
35 f p r i n t f ( f i d , }\n ) ;
36 f p r i n t f ( f i d , ]\n ) ;
37 f p r i n t f ( f i d , }\n ) ;
38 f p r i n t f ( f i d , ]\n ) ;
39 f p r i n t f ( f i d , }\n\n ) ;

For the realization of the Head Up Display (HUD) use is made in the same way such as the
steering wheel and tire force arrows of the already existing VRML files from MathWorks. A
MATLAB script for the conversion to a VRML file is also created. Text shapes are added
to a VRML world using the text geometry node. The fontstyle node is used to specify the
characteristics of this text. The HUD is an object with a fixed position at the user screen. The
proximitySensor node is a way of providing interactivity with the user. The proximitySensor
generates events when the user enters, leaves or moves in a defined rectangular box. This
node has the following fields:
enabled specifies the status of the sensor;
center determines the center of the rectangular box;
size specifies the size of the box.
When the mouse is inside, enters or leaves the box, the following events are generated when
the mouse moves:
position changed: Provides the 3D position of the user in the sensors coordinate sys-
tem.
orientation changed: provides the users orientation.

1 function []= wrl text ( f i d )


2

3 f p r i n t f ( fid , DEF %s Group {\n , HUD ) ;


4 f p r i n t f ( fid , children [\n ) ;
5 f p r i n t f ( fid , DEF %s P r o x i m i t y S e n s o r {\n , ps ) ;
6 f p r i n t f ( fid , s i z e 1000 1000 1000\ n ) ;
7 f p r i n t f ( fid , }\n ) ;
8

9 f p r i n t f ( fid , DEF %s Transform {\n , S p e e d T e x t P o s i t i o n ) ;


10 f p r i n t f ( f i d , r o t a t i o n 0.0993388 0 . 9 9 0 0 7 5 0 . 0 9 9 4 1 8 1 . 5 7 9 9 7 \ n ) ;
11 f p r i n t f ( f i d , children [\n ) ;
12 f p r i n t f ( f i d , DEF %s Transform {\n , S p e e d T e x t O f f s e t ) ;
13 f p r i n t f ( f i d , t r a n s l a t i o n 1.7 0.8 3\n ) ;
14 f p r i n t f ( f i d , children [\n ) ;
15 f p r i n t f ( f i d , Shape {\n ) ;
16 f p r i n t f ( f i d , a p p e a r a n c e Appearance {\n ) ;
17 f p r i n t f ( f i d , material Material {\n ) ;

43
18 f p r i n t f ( fid , d i f f u s e C o l o r 0 1 1\n ) ;
19 f p r i n t f ( f i d , }\n ) ;
20 f p r i n t f ( f i d , }\n ) ;
21 f p r i n t f ( f i d , geometry [ \ n ) ;
22 f p r i n t f ( f i d , DEF %s Text {\n , Speed Text ) ;
23 f p r i n t f ( f i d , s t r i n g V e l o c i t y \n ) ;
24 f p r i n t f ( f i d , f o n t S t y l e F o n t S t y l e {\n ) ;
25 f p r i n t f ( f i d , f a m i l y TYPEWRITER\n ) ;
26 f p r i n t f ( f i d , s i z e 0.12\n ) ;
27 f p r i n t f ( f i d , s t y l e BOLD\n ) ;
28 f p r i n t f ( f i d , }\n ) ;
29 f p r i n t f ( f i d , }\n ) ;
30 f p r i n t f ( f i d , ]\n ) ;
31 f p r i n t f ( f i d , }\n ) ;
32 f p r i n t f ( f i d , ]\n ) ;
33 f p r i n t f ( f i d , }\n ) ;
34 f p r i n t f ( f i d , ]\n ) ;
35 f p r i n t f ( f i d , }\n\n ) ;
36 f p r i n t f ( f i d , ]\n ) ;
37 f p r i n t f ( f i d , }\n ) ;

In Figure B.5 is shown how the VRML script for the HUD creates the visualization in the
3D World Editor.

Figure B.5: Head Up Display (HUD) for the vehicle velocity and engine speed

44
In order for a node to receive an event from another node, they must be connected using a
ROUTE statement. Routes are usually listed at the bottom of a VRML file. The general
syntax is: ROUTE Node1.eventOut TO Node2.eventIn. Note that a node must be named
with a DEF, for it to be able to send or receive an event through a ROUTE.

1 f u n c t i o n [ ] = wrl ROUTE ( f i d ) ;
2

3 f p r i n t f ( fid , DEF CamPos1 Transform {\n ) ;


4 f p r i n t f ( fid , t r a n s l a t i o n 0 . 0 0 . 5 0\n ) ;
5 f p r i n t f ( fid , r o t a t i o n 0 0 0 0\n ) ;
6 f p r i n t f ( fid , }\n\n ) ;
7

8 f p r i n t f ( f i d , ROUTE ps . p o s i t i o n c h a n g e d TO S p e e d T e x t P o s i t i o n .
s e t t r a n s l a t i o n \n ) ;
9 f p r i n t f ( f i d , ROUTE ps . o r i e n t a t i o n c h a n g e d TO

S p e e d T e x t P o s i t i o n . s e t r o t a t i o n \n ) ;
10 f p r i n t f ( f i d , ROUTE ps . p o s i t i o n c h a n g e d TO

E n g i n e S p e e d T e x t P o s i t i o n . s e t t r a n s l a t i o n \n ) ;
11 f p r i n t f ( f i d , ROUTE ps . o r i e n t a t i o n c h a n g e d TO

E n g i n e S p e e d T e x t P o s i t i o n . s e t r o t a t i o n \n ) ;
12 f p r i n t f ( f i d , ROUTE CamPos1 . t r a n s l a t i o n TO Camera1 . t r a n s l a t i o n \n

);
13 f p r i n t f ( f i d , ROUTE CamPos1 . t r a n s l a t i o n TO Camera2 . t r a n s l a t i o n \n

);
14 f p r i n t f ( f i d , ROUTE CamPos1 . t r a n s l a t i o n TO Camera3 . t r a n s l a t i o n \n

);
15 f p r i n t f ( f i d , ROUTE CamPos1 . t r a n s l a t i o n TO Camera4 . t r a n s l a t i o n \n

);

For the environment of the simulation some objects are inserted. Objects, such as road
poles and trees, are created with the node Inline. The Inline node is used to tell the VRML
browser to fetch the VRML file from the location specified in the url field and insert it into
this world. Inlining is useful because it enables objects to be reused in different scenes and
helps make large worlds more manageable. The VRML files for the road poles and trees are
standard available and can be found in the MATLAB toolbox library folder.

1 function []= wrl environment ( f i d )


2

4 f p r i n t f ( f i d , DEF %s Transform {\n , RoadPoles ) ;


5 f p r i n t f ( fid , children [\n ) ;
6

7 f p r i n t f ( fid , DEF %s Transform {\n , RoadPole 1 ) ;


8 f p r i n t f ( fid , t r a n s l a t i o n 28 0 9\n ) ;
9 f p r i n t f ( fid , children [\n ) ;
10 f p r i n t f ( f i d , I n l i n e {\n ) ;

45
11 f p r i n t f ( fid , u r l Road Pole . w r l \n ) ;
12 f p r i n t f ( f i d , }\n ) ;
13 f p r i n t f ( f i d , ]\n ) ;
14 f p r i n t f ( f i d , }\n ) ;
15 f p r i n t f ( f i d , ]\n ) ;
16 f p r i n t f ( f i d , }\n ) ;

In this way the visualization is done for all the parts of the LZV trucks. The translations,
colours and rotations are variable and can be change by changing the MATLAB script. For
more information about working with VRML a reference is made to the tutorial: A Guide
to VRML 2.0 and an Evaluation of VRML Modelling Tools [5].
The VRML trucks can be used as a visualization of the MATLAB/Simulink simulation.
Within MATLAB Simulink exists the VR sink block for connecting a VRML file with
Simulink. In Figure B.6 is the VR sink block shown.

Figure B.6: Simulink VR sink block

By double-clicking on the VR sink block, the window as shown in Figure B.7 appears. By
clicking on the browse button the desired VRML file can be selected. Also a description can
be added, then this description is added in the upper bar of the visualization window. When
the desired VRML file is selected, all the nodes are shown in the VRML Tree. By pressing
the plus sign, it is possible to expand the nodes. When expanding the nodes, parameters
such as the scale of tire force 1 of the cabin can be selected. All the selected parameters are
now inputs of the VR sink block. It is important that the desired VRML files are located in
the same folder as the Simulink model.

46
Figure B.7: VR sink block parameters and selection of desired node for simulation inputs

47
Appendix C

Graphical User Interface user


guide

How a GUI can been created is described in the this section. The GUI can be made within
MATLAB in two ways: by manual programming or using GUIDE. GUIDE is a function
which is specially designed to create a GUI. There is chosen to work with GUIDE. It is
possible within GUIDE to drag all the components to the right place. In addition, the
empty Call Back Functions are created automatically. This is the main difference between
GUIDE and manually programming a GUI. The MATLAB script, which is made for the
designed GUI, is generated by MATLAB itself. In MATLAB GUIDE, all components such
as pop-up menus can be placed. MATLAB writes for each component an empty Callback
Function. In Figure C.1 is shown how a number of components placed in GUIDE. The choice
between the various components can be selected at the left side of the screen.

48
Figure C.1: Creating a GUI with MATLAB Guide

MATLAB generates then automatically a script with several callback functions for each
component. With the first pop-up menu the user can choose between the LZV trucks. The
callback function is extended with a switch case function. Every option in the first pop-up
menu is a case with the parameter str. The parameters str are equal to a string which refers
to a LZV truck name such as LZV A. MATLAB remembers this name in the workspace.
Later in this tutorial it becomes clear how the desired truck simulation is opened in this
way.

1 f u n c t i o n p o p u p m e n u c h o o s e t r u c k C a l l b a c k ( hObject , ev en td at a ,
handles )
2

3 s w i t c h g e t ( h a n d l e s . popupmenu choose truck , Value )


4 case 1
5 s t r = LZV A ;
6 case 2
7 s t r = LZV B ;
8 case 3
9 s t r = LZV C ;
10 case 4
11 s t r = LZV D ;
12 case 5
13 s t r = LZV E ;
14 case 6
15 s t r = LZV F ;

49
16 case 7
17 s t r = LZV G ;
18 end
19

20 s e t ( h a n d l e s . popupmenu choose truck , UserData , s t r ) ;


21 g u i d a t a ( hObject , h a n d l e s )

In the next pop-up menu the user can choose between a constant input for the vehicle velocity
and steering angle or a joystick input. By choosing the joystick input, the user can drive the
truck by itself with the Logitech gaming hardware. For this pop-up menu also use is made
of a switch function. By choosing one of these options, constant or joystick, a part of the
MATLAB Simulink model will be enabled and another part will be disabled.

1 f u n c t i o n popupmenu9 Callback ( hObject , ev en td at a , h a n d l e s )


2

3 s w i t c h g e t ( h a n d l e s . popupmenu9 , Value )
4 case 1
5 Enable Constant Input = 1;
6 Enable Joystick Input = 0;
7 a s s i g n i n ( base , Enable Constant Input ,
Enable Constant Input ) ;
8 a s s i g n i n ( base , Enable Joystick Input ,
Enable Joystick Input ) ;
9 case 2
10 s e t ( h a n d l e s . popupmenu10 , Enable , on )
11 s e t ( h a n d l e s . popupmenu11 , Enable , on )
12 Enable Constant Input = 0;
13 Enable Joystick Input = 1;
14 a s s i g n i n ( base , Enable Constant Input ,
Enable Constant Input ) ;
15 a s s i g n i n ( base , Enable Joystick Input ,
Enable Joystick Input ) ;
16 end

17

18 s w i t c h g e t ( hObject , Value )
19 case 1
20 s e t ( h a n d l e s . popupmenu10 , Enable , on ) ;
21 s e t ( h a n d l e s . popupmenu11 , Enable , on ) ;
22 case 2
23 s e t ( h a n d l e s . popupmenu10 , Enable , o f f ) ;
24 s e t ( h a n d l e s . popupmenu11 , Enable , o f f ) ;
25 end

26

27 g u i d a t a ( hObject , h a n d l e s )

50
There are two subsystems, as shown in Figure C.2, which can been enabled or disabled in
the MATLAB Simulink truck model. These subsystems are called enabled subsystems in
Simulink. For this model, a constant block is used as input for this enabled port. The value
in this constant block is the value 1 or the value 0. In the script of the GUI the value of
these constant blocks are selected.

Figure C.2: Enable or disable subsystems in MATLAB Simulink

Finally, if the user selects the joystick input, the last two pop-up menus are disabled. This
is done by the second switch case in the GUI script. In the third pop-up menu the user can
choose a constant vehicle velocity. In this case, use is made of a switch case function. The
user can choose between several velocities which are called Cruise Control Input.

1 f u n c t i o n p o p u p m e n u c r u i s e c o n t r o l C a l l b a c k ( hObject , e ve nt da ta ,
handles )
2

3 s w i t c h g e t ( h a n d l e s . p o p u p m e n u c r u i s e c o n t r o l , Value )
4 case 1
5 Cruise Control Input = 5/3.6;
6 case 2
7 Cruise Control Input = 10/3.6;
8 case 3
9 Cruise Control Input = 25/3.6;
10 case 4
11 Cruise Control Input = 50/3.6;
12 case 5
13 Cruise Control Input = 75/3.6;
14 end

15

51
16 a s s i g n i n ( base , Cruise Control Input , Cruise Control Input ) ;

The parameter Cruise Control Input is used in the Simulink model in the constant subsystem
of the driver block, see Figure C.3.

Figure C.3: Variable input for the cruisecontrol velocity

For the constant steering input, the switch case in the fourth pop-up menu works in the
same way as for the velocity pop-up menu.

1 f u n c t i o n p o p u p m e n u s t e e r i n g I n p u t C a l l b a c k ( hObject , ev en tda ta ,
handles )
2

3 s w i t c h g e t ( h a n d l e s . popupmenu11 , Value )
4 case 1
5 C o n s t a n t S t e e r I n p u t=p i / 1 8 0 2 0 0 ;
6 case 2
7 C o n s t a n t S t e e r I n p u t =0;
8 end

10 a s s i g n i n ( base , Constant Steer Input , Constant Steer Input ) ;

52
Figure C.4: Variable input for the steering angle input

Finally, if the user choose all the desired parameters, the user pressed on the simulation
button. When the simulation button is pressed, the parameter A is introduced with the
value of the chosen option in the first pop-up menu. Then the desired truck simulation
automatically opened in MATLAB Simulink.

1 f u n c t i o n p u s h b u t t o n 4 C a l l b a c k ( hObject , ev en td at a , h a n d l e s )
2

A=g e t ( h a n d l e s . popupmenu1 , Userdata ) ;


3

open (A)
4

53
Appendix D

Evaluation SEP

54
55
Appendix E

Declaration concerning the TU/e


Code of Scientific Conduct (Dutch
version)

56
Appendix F

Declaration concerning the TU/e


Code of Scientific Conduct (English
version)

57
58

You might also like