0% found this document useful (0 votes)
16 views64 pages

Exercises MBD 02062024

exercise

Uploaded by

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

Exercises MBD 02062024

exercise

Uploaded by

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

Fakultät für Ingenieurwissenschaften

Prof. Dr.-Ing. Franz Perschl

Exercises for the lecture


Model based development (Master)
Revision 23.05.2024

Inhalt
Exercise 1 ............................................................................................................................................................. 2
Exercise 2 ............................................................................................................................................................. 5
Exercise 3 ........................................................................................................................................................... 14
Examination 13.07.2023 (Summer term 2023) ................................................................................................. 21
Examination 14.07.2022 (Summer term 2022) ................................................................................................. 26
Examination 10.02.2022 (Winter term 2021).................................................................................................... 31
Examination 14.07.2021 (Summer term 2021) ................................................................................................. 37
Examination 14.09.2020 (Summer term 2020) ................................................................................................. 42
Examination 27.01.2020 (Winter term 2019).................................................................................................... 46
Examination 25.07.2019 (Summer term 2019) ................................................................................................. 52
Examination 05.02.2019 (Winter term 2018).................................................................................................... 59

Seite 1
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Exercise 1

Task 1: Thermal Model of a House


In this task we use Simulink to create the thermal model of a house. This system should
model the outdoor environment, the thermal characteristic of the house and the heater.
The Simulink model of the house should look like this:

1.1 Build the submodel for the Heater. The Heater is a subsystem that has a constant air
flow rate, “M_dot”. The heater can be turned on or off by an additional input signal.
When the heater is on, it blows hot air at temperature T_Heater at a constant flow
rate of M_dot into the house. The heat flow into the room is expressed by the follow-
ing equation:

∗ ∗

with heat flow from the heater into the room.

heat capacity of air at constant pressure.


air mass flow rate through heater (kg/hr).
temperature of hot air from the heater.
current room air temperature.
Use the following numbers for the constants defined above: 3600 kg/hr; c =
1005,4 J/kg*K; 50 °C; cost = 0,30 €/kwh. Define all constants in the model
initialization function (Model properties -> Callbacks -> InitFcn).
1.2 Build the submodel for the House. The House is a subsystem that calculates room
temperature variations. It takes into consideration the heat flow from the heater and
Seite 2
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

heat losses to the environment. Heat losses and the temperature time derivative are
expressed by the following equation:

1
" #
! ∗
with ! mass of air inside the house.
equivalent thermal resistance of the house.

Use the following values for the constants above: ! 1778.4 kg;
4.27 * 10-7 K*h/J; T_inIC = 20 °C as initial value for the house temperature.

1.3 Simulate your model for a


period of 2 days (the time
axis is in hours not sec-
onds!). Visualize indoor
and outdoor temperature in
one scope by using a
testbench similar to this:
Configure the Pulse Generator to gen-
erate a pulse every 15 minutes, last-
ing for 15% of the period. The result in
the Scope should look similar to the
following picture:

Seite 3
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 2: Control the house temperature.


2.1 Replace the Pulse Generator by a Ther-
mostat Control. The Thermostat Control
is a subsystem that contains a Relay
block. The thermostat allows fluctua-
tions of 1°C above or below the desired
room temperature. If air temperature
drops below 20°C, the thermostat turns
on the heater. This gives us a behaviour
similar to the next picture:

2.2 Add a second scope to view the accumulated cost for heating the house. Change the
Setpoint to 18°C and compare the accumulated cost. How big is the financial effect
of heating with 3°C lower temperature per day? Why is the room temperature some-
times out of the specified range around the setpoint (+/- 1°C)?

Task 3: Prepare your control model for real-time control


3.1 Change your model by adding variant subsystems depending on a workspace-varia-
ble “mode”. One variant subsystem contains the parts only needed for simulation
(mode = 0), the other variant subsystem contains the parts needed for real-time con-
trol (mode = 1). Test if your model is correct by setting mode = 0 and compare the
simulated results to the results of task 2.1.
3.2 Add appropriate dSpace-Blocks to the subsystem needed for real-time control. The
temperature in the house is measured by a temperature sensor, which is connected
to an analog input channel. The measured voltage can be translated into the temper-
ature according to the following table:
Voltage 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 V
Temp. -15 -5 2 8 13 18 22 26 29 32 °C
Implement this relation with the help of a lookup-table.

Seite 4
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Exercise 2
The following exercise consists of parts originally used as examination tasks in winter term
2017/18 and summer term 2018.

Thermal Model of a House


In exercise 1 we discussed a very simplistic thermal model and the temperature control of a
house. Now, you should build up a more sophisticated model for the temperature control of
a room. In the following model, all necessary components of a heating system are modelled
in detail.
This includes a heater consisting of burner, boiler and pump. Two radiators heat the room.
Warm water from the pump drives both radiators in series. The heat flow from both radia-
tors influences the temperature in the room. The air in the room is heated according to its
thermal capacity. Heat losses are modelled as losses through windows and doors and
losses through the walls.
The following picture shows the overview of the complete model for the thermal control:

This model should be built step by step in the following tasks.


The numeric values for all constant parameters in the following tasks should be defined as
MATLAB workspace variables, for example c_water for $ . Use a MATLAB script
named ws_constant.m for the definitions.
All subsystems needed for the above model should be defined as library subsystems.
Collect all subsystems in a library called lib_heat_simulation.slx. After finishing a
subsystem, test the correct operation with a small test model. The settings for the test
models are: Stop-time 3600 (, fixed step integration method (ode4 Runge-Kutta) with a step
size of 1 (.

Seite 5
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 1: Boiler model


The model for the boiler can be derived from the following equations:

)* !
)* + ,) - . * ! * /01 $ 2

) 5678
* ! 3 4 (in [;])
9678 /:

* ! * ! 3 273 ;

With: * ! Temperature in the Boiler >°@];


:
* ! 3: Temperature in the Boiler [;];
* /01 $ Temperature of water coming back from radiators and pipes >°@];
:
,B ! : Amount of water to be heated [60 CD];
G
- : Specific heat capacity of water [4190 0H 3];
0H
,) : Water flow generated through the pump [ ];
)* + : Heat flow from the burner (constant or zero) [I];

Draw the Simulink library subsys-


tem for the boiler. Use only basic
Simulink blocks like gain, constant,
integrator, sum, … Use workspace
variables in your Simulink model for
constant parameters. The initial tem-
perature of the boiler
t_init_boiler is 310 ;.

Take into account, that above equations calculate the boiler temperature as an absolute
temperature in [K], while all other temperatures (pump, pipes, radiators, …) in the model
are in [°@]!
Test your library subsystem with a test
model Test_Boiler.slx, which
should look similar to the model to the
right. The Pulse Generator should be
configured to generate a pulse with an
amplitude of 15 kW every 10 minutes,
which lasts for 5 minutes (50 %). Provide constants set to
0H
40 °@ for the backflow temperature and a value of 2 for the
amount of water flowing back into the boiler. The result
should be similar to the adjoining picture.

Seite 6
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 2: Pump model

The model for the pump can be derived from the following equa-
tions:

∗P
,) J ∗ K ∗ L; K MN ∗ O ; J
N
∗ Q;

With: M: Radius of pipe [0.0127 ,];


0H
L: Density of water [1000 S
];
K: N
Cross section of pipe [, ];
J: Mean velocity of water flow [ ];
2
Q: angular velocity of pump motor [25 ];

Draw the Simulink library subsystem


for the pump. Use only basic Simulink
blocks like gain, constant, integrator, sum,

The temperature of the water is not influ-


enced inside the pump ( U V * ! !

Test your library subsystem with a suitable test model Test_Pump.slx.

Task 3: Pipe model


The model for a pipe assumes, that the pipe is
completely isolated. This means, that the model
for the pipe can be realized by using a variable
transport delay block from Simulink for the temper-
ature. See the excerpt from the Simulink docu-
mentation:

The time delay W can be calculated from the fol-


lowing equation:

L ∗ MN ∗ O ∗ X
W
,)

With: X: Length of the pipe [5 ,];

Seite 7
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Draw the Simulink library subsystem for the pipe. Use only basic Simulink blocks like
gain, constant, integrator, sum, … The water flow ,) through the pipe is not influenced.
Test your library subsystem with a suitable test model Test_Pipe.slx.

Task 4: Radiator model


The model of a radiator can be derived from the following equations:

)Y !
) Z+1 $
)[ 1 $
) !+H
) Z+1 $ \ ,) - Z+1 $
)[ 1 $ \ ,) - [ 1 $
) !+H C KY ! Y ! Y

) ] ^7 6
Y ! 3 4 (in [;])
] ^ /:

Y ! Y ! 3 273 ;

[ 1 $ \ Y ! _ 1 \ Z+1 $

\ 0.5 ∗ min max. e V !+ , 02 , g

With: ) : Heat power [I];


KY ! : Active area of the heat exchanger (radiator) [1.5 ,N ];
\: Factor for water flow [0 … 1], influenced by a radiator thermostat;
-
C: Coefficient of heat transmission [10 h 3];
g: Hysterisis of the radiator thermostat [2 ;];
Y ! : Temperature of radiator [°@];
Y ! 3 : Temperature of radiator [;];
Y : Room temperature [°@];
Z+1 $ : Temperature of water flowing into the radiator [°@];
[ 1 $ : Temperature of water flowing out of the radiator [°@];
e V !+ ∶ Setpoint for room temperature [22 °@];
,Y : Amount of water in radiator [5 CD];

Hint: You can use the following model for


the calculation of \ (upper limit of saturation
set to 1, lower limit set to 0):

Seite 8
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Draw the Simulink library subsystem for


the radiator. Use only basic Simulink ) !+H
blocks like gain, constant, integrator, sum, Y

… The initial temperature of the radiator


Y !
should be assumed to 310 ; (same as
boiler). Z+1 $
[ 1 $

Test your library subsystem with a suitable ,) ,)


test model Test_Radiator.slx.

Task 5: Burner model


The model for the burner delivers a constant heat flow, due to the following equation:

)* 15.000 I, kl ℎn opMqnM k( (rk ℎn sq


j
+
0 I, kl ℎn opMqnM k( (rk ℎn sll

The Burner can be switched on with the Signal t* ! from the subsystem “Room_Thermo-
stat”. It delivers a “1” to switch the burner on, a “0” to switch it off. Additionally, the burner
must be switched on, if the boiler temperature * ! is below 50 °@. The burner must be
switched off, if the temperature gets higher than 60 °@ (Hysteresis).

With: * ! : Temperature in the Boiler [°@];


t* ! : Signal from room thermostat (on/off = 0/1);
)* + : Heat flow from the burner (constant or zero) [I];

Draw the Simulink library subsystem for the


burner. Use only basic Simulink blocks like t* !
gain, constant, integrator, sum, … )* +

Test your library subsystem with a suitable test * !

model Test_Burner.slx.

Task 6: Room thermostat model


The model for the room thermostat generates an on/off signal t* ! for the burner.
Depending on Y the output of this subsystem is “1”, if the temperature is below
temp_low = 20 °@ or “0” if the temperature is above temp_high = 22 °@.

With: Y : Room temperature [°@];


t* ! : Signal from room thermostat (on/off = 0/1);

Seite 9
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Draw the Simulink library subsys-


tem for the room thermostat. Use
only basic Simulink blocks like gain, Y t* !

constant, integrator, sum, …


Test your library subsystem with a suitable test model Test_Thermostat.slx.

Task 7: Room model

The model for a room can be described by the following equations:

)Y ) !+H
)u ) !+H
)- ) -!+ $

Y 3 v
w! Y 3
)Y
xw! yY wZY
Y Y 3 273 ;

)[ ) -!+ $ _ )- _[

With: Y 3: Temperature in room [;];


Y : Temperature in room [°@];
)Y : Heat flow into / out of the room [I];
) !+H : Heat flow from the radiator to the room [I];
)u : Heat flow losses from the room to wall and windows [I];
)- : Heat flow from the room to the wall [I];
) - _[ : Heat flow from the wall to the outside [I];
) -!+ $ : Heat flow from the room to the windows (and also from the win-
dows to the outside [I];
)[ : Heat flow from wall and window to the outside [I];
~
w! : Specific gas constant for air ({ |287 •CD; €);
w! : Specific heat capacity of air (constant pressure)
~
({ |1009 •CD; €);
yY : Volume of air in the room [50 ,•];
xw! : Pressure of air [101300 ‚ƒ];
[ : Temperature outside of the house [°@];

Seite 10
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Draw and complete the Simulink li-


Y
brary subsystem for the room which [
is given in the following drawing )u
(next page!). Begin with two empty ) !+H )[
subsystems for the heat flow through
window and wall, which will be de-
scribed in the next tasks.

Use only basic Simulink blocks like gain, constant, integrator, sum, … The initial tempera-
ture of the room should be set to t_init_room = 293 ;.

Task 8: Subsystem for heat flow through window

In the above room model, two additional subsystems must be built. The heat flow through
windows can be modelled by the following equation (the heat capacity is neglected):

) -!+ $ C-!+ $ K-!+ $ Y [

With: K-!+ $ : Area of the window [4 ,N];


-
C-!+ $ : Coefficient of heat transmission [1.2 h3 ];

Draw the Simulink model for the win-


Y
dow subsystem. Use only basic Sim- ) -!+ $
ulink blocks like gain, constant, integra-
[
tor, sum, …

Seite 11
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 9: Subsystem for heat flow through wall

Next, the subsystem for the heat flow through the wall must be modelled. This subsystem
can be described by a simplified model, where the wall consists of layers of different materi-
als (plaster, bricks, isolation, …). Here, we assume a wall consisting of only two layers:
With: ): Heat flow from room to the outside [I];
Y : Temperature in room [°@];
[ : Temperature at the outside [°C];

The wall consists of a layer of massive concrete with a sec-


ond layer of isolating material (on the outside).

The following equation describes the heat flow:


) …
Y [
Y †‡ ˆ Y †h

7
The thermal resistance ‰! is defined as ‰! Š7 w]66‹
.

With: …: thickness of concrete layer [0.2 ,];


N: thickness of isolation layer [0.1 ,];
-
\… : thermal conductivity of concrete [1.1 3
];
-
\N : thermal conductivity of isolation [0.04 3
];
KY : Surface between room and outside [45 ,N ];

Draw the Simulink model for the wall


Y
)
subsystem. Use only basic Simulink
blocks like gain, constant, integrator, sum,
… [

Task 10: Testing the room model


Test your library subsystem with a suitable test model Test_Room.slx.

Seite 12
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

You may configure the Pulse Generator to create a pulse of 2000 I with a period of 250 (
and a pulse width of 10 %.

Task 11: Build and simulate the complete thermal model of the house
Now you created all library subsystems for the complete house model. Build the model and
name it House_Heat_simulation.slx. Use the screenshot from page 1 of this exercise
as a template.

Seite 13
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Exercise 3

Chemical reactor process

Two different fluids are mixed together in a chemical reactor. This mixture must be heated
to a dedicated temperature. Mixing is done by an electric motor M. The following picture de-
scribes the technical setup:

The process is described by the following steps:


• After pressing the START button, the reactor will be filled by opening the valve Q1,
as long as the level sensor S2 is not activated. Preconditions to this action are:
• the reactor is empty (S1),
• the temperature sensor S4 reports no high limit
• the pressure sensor S5 reports no high limit
• Next the mixer M must be switched on and valve Q2 must be opened.
• If the level sensor S3 is activated, valve Q2 must be closed again.
• After 5 s the heater H must be switched on and stays switched on until temperature
sensor S4 reports that the setpoint temperature is reached.
Seite 14
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

• If during the heating phase the pressure sensor S5 reports an overpressure situa-
tion, the pressure relieve valve Q4 must be opened until the overpressure is gone.
• After heating is done, the mixer runs for another 10 s. Afterwards valve Q3 must be
openend.
• If the reactor is empty again (S1), valve Q3 is closed again.
• By pressing a Reset button, the control unit can be resetted to the initial state.

The following table describes all input and output signals:


Input / Output Variable Meaning
Start button START START = 1, if buttton is pressed
Empty level S1 S1 = 1, if reactor is empty
Level 1 S2 S2 = 1, if level 1 is reached
Level 2 S3 S3 = 1, if level 2 is reached
Temperature sensor S4 S4 = 1, if temperature setpoint is reached
Pressure sensor S5 S5 = 1, if overpressure is detected
Reset button RESET RESET = 1, if button is pressed
Valve 1 Q1 Q1 = 1, then valve opens
Valve 2 Q2 Q2 = 1, then valve opens
Empty valve Q3 Q3 = 1, then valve opens
Pressure relieve valve Q4 Q4 = 1, then valve opens
Heater H H = 1, then heater is on
Mixer M M = 1, then mixer is on

Tasks:
1. Develop a control algorithm for this process by using a state chart.
2. Draw a Simulink model with all input and output signals needed for the chemical re-
actor process and implement your state chart from task 1. (Just use constant blocks
to stimulate the input signals.)
3. Simulate your model.

Design a control algorithm with Stateflow


In the aeration basin of a wastewater treatment plant, microorganisms process the ammo-
nium in the water with the help of oxygen to nitrate, water and hydrogen. In a second step,
the oxygen feed is closed. This leads to the processing of nitrate and hydrocarbons through
the microorganisms. This step produces carbon dioxide and nitrogen.

Seite 15
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

The complete process is controlled with air pipes installed at the bottom of the aeration ba-
sin. The air in the air pipes is driven by compressor units and valves. The following drawing
shows this part of the wastewater treatment plant:
Process:

(Source: Wikipedia)

Table of input and output signals:


Input / Output signals Variable Meaning
I: Start switch Start Start = 1, start of ventilation program
I: Stop switch Stop Stop = 1, stop of ventilation program
I: Operation mode OM OM = 0 activates operation mode 1
OM = 1 activates operation mode 2
O: Valve pipe 1 V1 V1 = 1, ventilation of pipe 1
O: Valve pipe 2 V2 V2 = 1, ventilation of pipe 2
O: Valve pipe 3 V3 V3 = 1, ventilation of pipe 3
O: Compressor unit 1 Q1 Q1 =1, compressor unit 1 is running
O: Compressor unit 2 Q2 Q2 = 1, compressor unit 2 is running

All variables in the above table have only binary values (“0”/”1”)!
In the above table, all available input and output signals are listed, which are necessary for
the implementation of a sequential process control. This control should realize two different
operation modes, depending on the operation mode switch OM.
In operation mode 1 only one of the three air pipes is active at the same time. The pro-
gram begins with ventilation of air pipe 1 with opening valve V1. After 5 minutes of ventila-
tion, valve V1 is closed and air pipe 2 is activated by opening valve V2. Again, after 5
Seite 16
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

minutes V2 is closed and V3 is opened in order to activate air pipe 3. 5 minutes later, V3 is
closed and the process is repeated, beginning with pipe 1.
In operation mode 2 one or two air pipes are ventilated at the same time. The program be-
gins the ventilation with air pipe 1. 3 minutes later, air pipe 2 is ventilated additionally. After
2 additional minutes, air pipe 1 is deactivated. 1 minute later, air pipe 3 is activated. 2
minutes later, air pipe 2 is deactivated. 1 minute later, air pipe 1 is activated and 2 minutes
later air pipe 3 is deactivated and the process repeats.
The process begins with activation of the start switch Start. In operation mode 1 only com-
pressor unit 1 must be activated. In operation mode 2 both compressor units must run.

1. Draw the output signals V1 to V3 for operation mode 1 into the following diagrams
(time axis is in minutes):

Assume, that the Start switch is activated at 0 minutes.

Seite 17
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

2. Draw the output signals V1 to V3 for operation mode 2 into the following diagrams
(time axis is in minutes):

Assume, that the start switch is activated at 0 minutes.


3. Draw a (top level) Simulink model with a Stateflow chart and all necessary input
and output signals.

4. Draw a state chart needed to implement the control algorithm for the aeration basin
described above. Use absolute time temporal logic where necessary.

Design a control algorithm with Stateflow


The zebra crossing of a road should be secured by an additional pedestrian light. Develop a
control algorithm for the control of the lights using a Stateflow model.
Process:

Seite 18
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

This picture shows only one half of the traffic lights. The second half for the opposing traffic
or the pedestrians from the other side of the road are controlled identically.

Table of input and output signals:


Input / Output signals Variable Meaning
I: Request switch S1 S1 = 1, pedestrian requests green light
I: Day/Night sensor S2 S2 = 1, sensor detects darkness
O: Traffic light red L1 L1 = 1, Traffic light “red“ is active
O: Traffic light yellow L2 L2 = 1, Traffic light “yellow“ is active
O: Traffic light green L3 L3 = 1, Traffic light “green“ is active
O: Pedestrian light red L4 L4 = 1, Pedestrian light “red“ is active
O: Pedestrian light green L5 L5 = 1, Pedestrian light “green“ is active

This Table lists the available input and output signals for the control algorithm. A pedestrian
can request green light with switch S1. After that, the sequence for the traffic lights begins,
as it is described in Task 1.
If the Day/Night sensor detects darkness, then the traffic lights are switched into night
mode, 2 minutes after the last active sequence. In night mode the yellow light blinks every
1.5 second (0.75 second on, 0.75 second off).

1. Complete the following diagram. The drawing needn´t be true to scale. The se-
quence, which should be implemented, consists of the following steps:

 Switch S1 starts the sequence.


 Directly after actuation of S1, the traffic light shows a green light and the pe-
destrian light shows red. This lasts for 10 seconds.
 After 10 seconds, the traffic light changes from green to yellow for 3 seconds.
Seite 19
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

 After the yellow light, the traffic light changes to red.


 2 seconds later, the pedestrian light changes from red to green.
 The green light of the pedestrian light lasts for 20 seconds.
 Then the pedestrian light changes from green to red.
 This lasts for 10 seconds, so that pedestrians have enough time to leave the
road.
 After that, the yellow light of the traffic light is switched on for 2 seconds in ad-
dition to the red light.
 Then the traffic light changes from yellow-red to green.
 30 seconds later, the traffic light is switched off, unless another request with
S1 occurs.

2. Draw a (top level) Simulink model with a Stateflow chart and all necessary input
and output signals.

3. Draw a state chart needed to implement the control algorithm for the traffic light
control described above. Use absolute time temporal logic where necessary.

4. Expand your state chart from task 3 by adding states and transitions for the night
operation.

Seite 20
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 13.07.2023 (Summer term 2023)

Task 1: Simulation of Mobile Robot


We want to simulate the kinematics of a small mobile robot with two independently driven
wheels and a third supporting wheel, according to the following picture:
Example:

Supporting Wheel

(The supporting wheel is not drawn in above draft.)


1.1 The movement of a rigid body on a plane can be described as a rotation around a mo- 10 P
mentary center point (ICR = instantaneous center of rotation). With M being the dis-
tance between ICR and robot and X being the length of the robots´ axis (Œ •. Ž •),
the forward kinematic of the robot can be described by the following equations:
•] ˆ•‘
J (Eq. 1)
N
•] ’•‘
Q (Eq. 2)
The backward kinematic is described by the next equations:
Ju QM (Eq. 3)
JY Q M_ X (Eq. 4)
J Q M _ X•2 (Eq. 5)
Open the prepared Simulink model kinematics.slx:

Implement above equation Eq. 1 and Eq. 2 in subsystem “Forward_kinematics” and


Eq. 3 to Eq. 5 in subsystem “Backward_kinematics”. (The letter “w” means Q in the
equations.) Use workspace variables for parameters like X. Define all workspace varia-
bles in the prepared Matlab script “constant.m” and run the script before simulation.
Run the simulation with the given setpoint values! If everything is correct, you
should get output values exactly matching the setpoints. How big is the radius r?

Seite 21
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Answer: Radius r = ________________________

1.2 If the robot should drive straight forward, Q must be set to 0. This would lead in the 6P
calculation of radius r in Eq. 5 to a division by zero. Copy your model kinematics.slx to
a new model kinematics2.slx. Then add in the Backward_kinematics subsystem the
following distinction of cases:

If ƒo( Q “ 0.00001 then


Ju J (Eq. 3*)
JY J (Eq. 4*)
M kql (Eq. 5*)
else
Calculation of Ju , JY , M according to Eq. 3 to Eq. 5 from task 1.1

Check the result of simulation with a w_setpoint of 0.

1.3 Next, we want to use the kinematic model to calculate position and orientation of the 8P
robot in a global (x,y) coordinate system:
The following differential equation describes
the orientation ” of the robot:

”) Q (Eq. 6)
The x- and y-position can be calculated from
the following equations:

•) J cos ” (Eq. 7)
™) J sin ” (Eq. 8)

Open the prepared Simulink model sim_trajectory.slx:

Copy the subsystem “Forward_kinematics” from your model kinematics2.slx into


sim_trajectory.slx and connect its inputs to the predefined setpoint constants on the
left side. Implement all necessary blocks to calculate the position (x,y) according to
equations Eq. 6 to Eq. 8. Connect the x- and y-signals to the corresponding inputs of
the XY Graph block on the right side.
Implement the initialization values as workspace variables in the Matlab script “con-
stant.m” from task 1.1. Use the following initialization values for the calculation of
”, • ™:
Seite 22
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

 init_theta = 5
 init_x = 2
 init_y = 2

1.4 Change the solver settings to “Fixed-step” solver “ode4” with a step size of 0.1 s and 4 P
a stop time of 6 s. Run the simulation and open the xy Graph.
What geometric figure does the robot drive in the xy-plane? (Be careful and look at the
axis scaling!)

Figure = _______________________________________________________

What are the end coordinates after 6 s simulation time?

(x,y)(t = 6 s) = __________________________________________________
(You can read out the values if you enable the “Data Cursors”.)

1.5 Next, we use our simulation models for simulation of following a straight path with a 10 P
simple control loop. Open the prepared Simulink model path_control.slx:

Copy the complete model from the file sim_trajectory.slx (without the setpoint con-
stants) into the model path_control.slx. Copy the subsystem “Backward_kinematics”
from model kinematics2.slx into model path_control.slx and connect its outputs v_l
and v_r to the inputs of subsystem Forward_kinematics. The inputs of subsystem
Backward_kinematic must be calculated from the setpoints and actual values in the
following way:
J •) V !+ (Eq. 9)
Q ;V .™ V !+ ™2 _ ;V_ ‰ ” V !+ ” (Eq. 10)
Define ;V 1 and ;V_ ‰ 1.5 as workspace variables in the file “constant.m”
from task 1.1. Furthermore, the initial values for the integrators for ”, •, ™ must be
set to different values compared to task 1.3. Define workspace variables start_orien-
tation = 0, start_x = 0 and start_y = 1 in “constant.m” and use them in the integrators
instead of the “init_...” values from task 1.3. Run the simulation. Take a screenshot
and save it in the Matlab working directory.

Seite 23
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 2: Design a control algorithm with Stateflow


In this task, you should develop a simple control algorithm, which will allow a small mobile
robot like the one from task 1 to find its way through a maze:
The starting point is in the top left corner. The
dark gray point is the mobile robot. Its task is to
find autonomously the exit, which is near the
bottom right corner. The initial orientation of the
robot is downwards the y-axis. It can only move
in x and y directions, not in diagonal direction.
The algorithm to find the way through the maze
is quite simple: Just always follow a wall on your
right side. To detect walls, the robot has three
sensors: one looking forward, one looking left
and one looking right.

2.1 Open the prepared Simulink model maze_runner.slx: 9P

The subsystem “Maze_Visualiza-


tion” includes a map visualization
and allows animation of robot
movement like in the figure
above.
In the subsystem “path_finder”,
you should implement a stateflow
chart with the control algorithm.
Table of input and output signals:
Input / Output signals Var. Meaning
I: Forward looking sensor sens_fwd sens_fwd = true, if the forward looking sensor de-
tects an obstacle.
I: Left looking sensor sens_left sens_left = true, if the left looking sensor detects an
obstacle.
I: Right looking sensor sens_right sens_right = true, if the right looking sensor detects
an obstacle.
I: Destination reached dest dest = true, if the destination point is reached
O: Make a step forward step_fwd step_fwd = true, then robot should move one step
forward in current movement direction.
O: Turn 90° to the left turn_left turn_left = true, then the robot should make a 90°-
turn to the left
O: Turn 90° to the right turn_right turn_right = true, then the robot should make a 90°-
turn to the right
All Variables in the above table have only boolean values (true/false)!
Seite 24
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Implement in subsystem “path_finder” a Stateflow chart and define all necessary in-
puts and outputs with appropriate data type. Connect inputs and outputs of the chart
to the inports and outports of the subsystem.
2.2 Draw a state chart needed to implement the path finding algorithm. The robot will 13 P
make one forward step or one turning action in each simulation step, based on the
sensor information from the previous step.
If there is a wall on the right side (sens_right == true), then step forward. If there is a
wall on the right side and a wall in front, then turn left. If there is no wall forward and
no wall left and no wall right, then turn right. If signal dest == true, then the robot has
reached its destination. Then all outputs must be set to false.
In all steps, only one output signal may be set to true. All others must be set to false.
The robot cannot move forward and turn in the same step.
(Hints: You can solve this problem with a state chart consisting of only 4 states! For
debugging your algorithm, it may be helpful to single step through the simulation and
look at the animated map at the same
time. If you just run the simulation, you
will only see the end result.) In the end,
it should look like this:
The light gray points show the path the
robot has driven.

Seite 25
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 14.07.2022 (Summer term 2022)

Task 1: PID controller


1.2 In many applications it is necessary to design a specialized PID-controller (Propor- 6P
tional – Integral – Derivative). An example of such an application is shown in the fol-
lowing picture:

The following equation represents the “usual“ PID control law in the continuous time
domain (input e(s) system deviation, output u(s) control signal) with constant parame-
ters P, I and D:

šUZ› ( ‚ _ œ _ •( with the Laplace operator (. (Eq. 1.1)
Open the prepared Simulink model pid_control1.slx and implement above equa-
tion for šUZ› ( in the subsystem “PID Controller” by using only basic blocks (Gain,
Integrator, Derivative, Sum). Do not use a transfer function or the built-in PID block
from the Simulink blocksets.Use Variables “P”, “I” and “D” instead of numerical values.

1.2 Set the values for “P” to 2.0, “I” to 1.0 and “D” to 0.3. Use the InitFcn callback func- 3P
tion to initialize the values. Run the simulation! What value can you readout for y(t) at
time t = 2 s?

y ( 2 s ) = ________________________________________

Save your model!

1.3 Equation Eq. 1.1 from task 1.1 uses constant gains for the P, I and D factors. This is 6P
sufficient, if you want to control a system only near to an operating point. If you want to
use a controller in a bigger range around an operating point, it is better to use a set of
P, I and D factors. One possibility to implement this is by using lookup tables, where
the input depends on the system deviation or some other signal.
Copy the model pid_control1.slx from task 1.1 to a new Simulink model
pid_control2.slx. Next, change the implementation of the PID controller from task 1.1
to a new implementation, where the P and I factors are given by two 1-D lookup tables
dependent on the system deviation e(s). This means that you should implement the
following formula:

Seite 26
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl


šUZ›N ( žŸ U n ( _ žŸ Z .n ( 2 _ •( (Eq. 1.2)

žŸ U means lookup table for parameter P, žŸ Z is lookup table for I.

1.4 The lookup tables for the parameters P and I 6P


should be specified in a way, that they represent
the diagrams on the right.
Configure the arrays for breakpoint and table
data for both lookup tables in your model from
task 1.3.
Explain: What is the effect of this parameteriza-
tion on the behaviour of the PID controller?

Answer:

Save your model!

1.5 Copy the model pid_control2.slx from task 1.3 to a new Simulink model 3P
pid_control3.slx.
The output of the PID controller (control signal u(s)) is limited to a lower and an upper
value because of technical restraints. Add a saturation block, representing these re-
straints, to the Simulink model. Set the upper limit of the saturation to 8.0, the lower
limit to 0.0. What value shows the output signal y(t) of the controlled system after 30 s.
y( 30 s ) = ______________________________________

1.6 With the added saturation block, the PID controller encounters a new problem. If the 2P
value of the control signal is too low because of the saturation, the setpoint may not be
reached in steady state. This means that the deviation signal e(s) will not become “0”

Seite 27
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

in steady state situations. Therefore, the integral part of the controller will compute
higher and higher values. This effect is called the “windup” effect.
Add a Scope to measure the integral part of the controller. How big is the value of the
integrator output at time t = 10 s?
Value = _________________________________________
1.7 A possible anti-windup procedure is the calculation of a new signal consisting of the 4P
difference between saturated and non-saturated output of the controller multiplied by a
gain factor. This signal must be added to the input of the integrator in the PID control-
ler (internal feedback).
Add this anti-windup procedure to your Simulink model. Set the gain factor to 50.

Task 3: Design a control algorithm with Stateflow


In a filling machine cans are filled with cream. Empty cans are delivered from the right side
with a conveyor belt. If the start switch S0 is switched on and enough cream is in the stor-
age tank (signalled by S1), the filling machine can start (Motor M1 switched on). This must
also be shown to the user by turning on lamp L1.
Process:

Seite 28
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Table of input and output signals:


Input / Output signals Variable Meaning
I: Start switch S0 S0 = true, if the switch is turned on
I: Storage tank full S1 S1 = true, if the tank is full
I: Can ready for filling B1 B1 = true, if a can is at the filling position
I: Reset key Reset Reset = true, if the counter for cans must be set to 0
O: Lamp L1 L1 = true, then lamp L1 is active.
O: Motor conveyor belt M1 M1 = true, then the conveyor belt is running
O: Filling mechanism Y1 Y1 = true, then a can is filled
O: Stopper Y2 Y2 = false, then a can is stopped on the running belt
O: Number of filled cans AW Numerical display: Number of filled cans

All Variables in the above table have only boolean values (true/false)! Exception: AW is a
numerical value.
A stop actor Y2 stops the next empty can at the filling position, if the conveyor belt is run-
ning. Sensor B1 signals, that an empty can is at the filling position. Next the conveyor belt
must stop and the filling with cream begins.
Filling is done by activating the filling mechanism Y1 for a fixed period of time (10 s). After
that, the conveyor belt starts again (M1) and the stopper Y2 is deactivated for 1 s, so that
the filled can is transported out of the filling machine. At the same time the next empty can
is fed into the filling machine from the right side and the next filling can take place.
The filling system can be turned off by switching it off with the start switch S0. Additionally,
it must also be switched off, if the storage tank is empty (S1). In both cases, the filling of the
can currently filled must be finished and this can must be transported out of the filling ma-
chine.
Every filled can must be counted. The control algorithm must provide an additional output
AW with the number of filled cans. This number is visualized on an external numerical dis-
play. An input key Reset is used to reset the counter value to zero. A reset can only be
done, if the filling machine is not running.

Seite 29
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

3.1 Complete the following drawing with the input and output signals according to the pre- 6 P
vious description. It must show at least one complete filling cycle. Add vertical dashed
lines to mark the possible states.

3.2 Open the prepared Simulink model filling.slx. It looks like this: 9P

Add a Stateflow chart in subsystem “Filling Control” and define all necessary input and
output signals with correct data type.
3.3 Draw a state chart needed to implement the control algorithm for the filling system 15 P
described above.
Seite 30
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 10.02.2022 (Winter term 2021)

Task 1: Simulation of hall temperature

The temperature ‰ inside a big heated hall should be simulated:

+•
Symbol Einheit Bedeutung
‰ ‰ °C Temperature inside the hall

+• °C Temperature of the environment
‰ W Heat flow from the heater
W Heat loss through walls and windows

Because of the big dimensions of the hall, the effects of heating on the hall temperature can
be described by the following simplified equations:

‰ +• / ‰ (Equ. 1)
)‰ ‰ – / ! ∗ ! (Equ. 2)

‰ 4 )‰ (Equ. 3)
The following table describes the mathematical symbols and values of necessary con-
stants:
Variable or constant Matlab/Simulink Symbol Value Unit
Thermal resistance of walls and windows R_therm ‰ 6.27 ∗ 10’¢ ;/I
Mass of air inside hall M_air ! 3.6 ∗ 10 • CD
Specific heat capacity of air c_air ! 1.005 ∗ 10• ~/ CD;
Temperature of environment (constant) T_env +• 15 ℃
Initial temperature in hall T_hall_0 ‰ ¤ 25 ℃
Maximum heat flow into hall Q_heat_max ‰ ¥ 50 ¦§

1.3 Open the provided template script “constant.m” in Matlab. It includes all variables 3P/
from the above table. Create a new Simulink model with the name “sim_temp.slx”.
Add a PreLoadFunction Callback (Property Inspector or context menu model proper-
ties) and use it to run constant.m. Save the model and close it. Clean the Matlab work-
space. Open it again and verify, that all constants from the script are defined as work-
space variables within Matlab. Use these workspace variables in the following
subtasks in all Simulink blocks instead of using numbers.

1.4 Next, integrate a Pulse generator, which simulates the heat flow ‰ . Configure the 6 P /
Pulse generator, so that the output has an amplitude of ‰ ¥ . This amplitude
Seite 31
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

shouldn´t be output continuously. Instead, the output should be set to this value for 15
s for each 60 s. In the rest of this period, the output is 0 kW. Furthermore, the heating

should begin after an initial delay of 30 minutes. Please see the following drawing
(not drawn to scale):
Note: The simulation time is considered to be in s.
Add a Scope to your model, set the simulation stop time to an appropriate value, so
that you can verify the correct settings of your pulse generator. Make a screenshot of
your scope window with the built in snipping tool and save this screenshot in your
working directory under the file-name screen.png.

1.5 Include all necessary blocks from the appropriate Simulink blocksets to build a simu- 7 P /
lation model for equations 1 to 3 above. Don´t forget to set the initial temperature of
the hall. Comment your model by writing at least the names of the outputs of the
equations 1 to 3 to the corresponding signals in the model. Connect the output signal
(temperature ‰ ) to a Scope block to visualize the temperature.

1.6 Configure the simulation, so that it uses the fixed-step solver ode2 (Heun). Set the 2P/
stop time to 5 hours and the step size to 1 s. Start the simulation. What temperature
is reached after 5 hours (mean value, estimated from the scope window).

Mean value: __________________________________________

1.7 This open loop feed forward control is not very comfortable. Let us try to improve it by 8P/
adding a simple discrete controller to our model implemented with Stateflow. The con-
trol-law can be described by the following textual description:
Let us assume, that we define a temperature setpoint of 23 °C. The heater must be
turned on, if the actual temperature ‰ drops more than 1 °C below this setpoint.
Turning on the heater means that it will produce a constant heat flow of 30 kW. If the
actual temperature ‰ gets higher than setpoint + 1 °C, then the heater must be
turned off. Turning off means producing a heat flow of 0 W.
Save your Simulink model sim_temp.slx under the new name control_temp.slx. Then
replace the Pulse generator by a state chart needed to implement the control algo-
rithm. The output of the chart is ‰ . If you run the simulation, what is the new
mean value of the temperature after 5 simulated hours?

Seite 32
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Mean value: __________________________________________

Task 2: Design a simulation model for PV system


In the examination of the summer term 2021, you should design the tracking control algo-
rithm for a photovoltaic (PV) system.
South

West

East Elevation
Azimuth angle angle

In this examination, you tested your tracking algorithm against a simulation model, which
provided signals for the solar sensor and simulated the two electrical motors for azimuth
and elevation angles.
This time, you should design the simulation model for the signals AZS, ELS, AZP and ELP.
Table of input and output signals:
Inputs / Outputs Var. Meaning
O: Solar sensor azimuth angle AZS Analog value, -90° … +90°, east-west-position of sun
O: Solar sensor elevation angle ELS Analog value, 0° … +90°
O: Azimuth angle of PV AZP Analog value, -90° … +90°, east-west-position of PV
O: Elevation angle of PV ELP Analog value, 0° … +90°
I: Azimuth motor pos. direction AZM+ AZM+ = true, motor is turning PV system in positive
azimuth direction
I: Azimuth motor neg. direction AZM- AZM- = true, motor is turning PV system in negative
azimuth direction
I: Elevation motor positive direc- ELM+ ELM+ = true, motor is turning PV system in positive
tion elevation direction
I: Elevation motor negative di- ELM- ELM- = true, motor is turning PV system in negative
rection elevation direction

The Simulink model pv_control.slx is already prepared as a template:

Seite 33
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

The left subsystem called “Control” contains the tracking algorithm from last examination
which is used to generate the signals AZP+, AZP-, ELM+ and ELM-. The left subsystem
“Simulation” is empty and should be filled by you. Please, keep in mind, that the simulation
time is scaled in hours with a timestep in minutes. The simulation runs for one complete
day (24 hours).
The outputs of the simulation subsystem can be described by the following formulas:
1. The earth rotates 360° around the sun in 24 hours, which defines the simulation of
the azimuth angle: K¨t 4 360•24 . (Initial value of integrator: -180°) If we as-
sume a place near Greenwich (Longitude 0°, Latitude around 50° North), we can see
the sun probably at azimuth angles between -70° up +70°. You can model this by
adding a saturation block with appropriate limits.
2. The measured elevation ELS can be calculated from the azimuth angle with the help
of this formula: ©žt 90° sin 90° _ K¨t 40°. The value of ELS should also be lim-
ited to positive values with a saturation block. Please, remember that in Matlab and
Simulink the argument of the sin-function is given in radians!
3. The azimuth motor of the PV system can move the PV system at a speed of +/- 100
degrees per hour. Therefore, we can use an integrator to model the azimuth angle
with this mathematical formula: K¨‚ 4 100K¨ ˆ 100K¨ ’ with an initial
value of -70°. This is the angle where we expect to see the sun first in the morning.
4. The elevation can be calculated from the same formula but with different input sig-
nals: ©ž‚ 4 120©ž ˆ 120©ž ’ . The initial value is 0°, meaning the PV sys-
tem points to the horizon. The elevation motor is a little bit faster with 120 °/hour.
2.1 First, add the part of the model necessary for simulating the values of the solar sen- 10 P /
sors AZS and ELS.
2.2 Next, add the part of the model necessary for simulating the values of the angles of 10 P /
azimuth and elevation motor AZP and ELP. Attention: The inputs AZM+, AZM-,
ELM+ and ELM- are boolean values, which you cannot use directly in calculations.
If your solution is correct, you will get a scope view similar to the following picture:

Seite 34
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 3: Control algorithm for a gas burner


The following picture shows the components of a gas burner together with all sensors and
actuators:

Gas streams through two magnetic valves into a nozzle, where it is mixed with air. After ig-
nition, it burns and produces continuously heat. With two control flaps the gas and air flow
is regulated. A fan blows air into the nozzle. There are several sensors for gas pressure
(PSL, PSH), air pressure difference (PD) and a flame detector (RSL). The burner is started
with a start switch and turned off with a stop switch.

Seite 35
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Table of input and output signals:


Inputs / Outputs Var. Meaning
I: Gas pressure level low PSL PSL = true, then pressure is higher than minimal limit
I: Gas pressure level high PSH PSH = true, then pressure is higher than maximal limit
I: Air pressure difference PD PD = true, then pressure difference is detected
I: Flame detector RSL RSL = true, then gas flame is detected
O: Ignition signal Z Z = true, then ignition is activated
O: Fan control signal F F = true, then fan is turned on
O: Magnetic valve 1 MV1 MV1 = true, then magnetic valve 1 is opened
O: Magnetic valve 2 MV2 MV2 = true, then magnetic valve 2 is opened
I: Start signal Start Start = true, then burner should be started
I: Stop signal Stop Stop = true, then burner should be turned off
All variables are boolean signals.
The startup procedure for the gas burner can be described by the following steps:
 The process is started, if the start signal Start is activated and the gas pressure is
between low and high limit.
 In the next step the fan F is started. Two seconds later the air pressure difference
PD is checked. If the pressure difference is too low, the starting procedure is termi-
nated.
 Next, both magnetic valves MV1 and MV2 are opened.
 One second later, ignition Z is activated.
 After additional 3 seconds, there must be a flame detected by sensor RSL. If not,
then the procedure is stopped again. The stopping procedure is done in several
steps:
o First, both magnetic valves are closed and ignition is turned off.
o 5 seconds later, the fan is stopped.
 If the flame is detected, then the procedure waits for 5 seconds until it reaches the
normal operating state. In this state the ignition is turned off.
 The normal operating state is left, if the stop signal Stop is activated or if the gas
pressure leaves the limit range or if the pressure difference drops below its limit or if
the flame is purged. In this case, the same stopping procedure as written above will
be run.

3.1 There is a Simulink model burner.slx prepared for this task. Open it! Inside the model, 14 P /
you find a Stateflow chart. Use this chart to implement the complete startup procedure
described above.

Seite 36
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 14.07.2021 (Summer term 2021)

Task 1: Simulation of hall temperature

The temperature ‰ inside a big heated hall should be simulated:

+•
Symbol Einheit Bedeutung
‰ ‰ °C Temperature inside the hall

+• °C Temperature of the environment
‰ W Heat flow from the heater
W Heat loss through walls and windows

Because of the big dimensions of the hall, the effects of heating on the hall temperature can
be described by the following simplified equations:

‰ +• / ‰ (Equ. 1)
)‰ ‰ – / ! ∗ ! (Equ. 2)

‰ 4 )‰ (Equ. 3)
The following table describes the mathematical symbols and values of necessary con-
stants:
Variable or constant Matlab/Simulink Symbol Value Unit
Thermal resistance of walls and windows R_therm ‰ 4.27 ∗ 10 ’¢ ;/I
Mass of air inside hall M_air ! 3.6 ∗ 10• CD
Specific heat capacity of air c_air ! 1.005 ∗ 10 • ~/ CD;
Temperature of environment (constant) T_env +• 10 ℃
Initial temperature in hall T_hall_0 ‰ ¤ 20 ℃
Maximum heat flow into hall Q_heater_max ‰ ¥ 50 ¦§

1.8 Open the provided template script “constant.m” in Matlab. Add variables for all 6P/
needed constants from the above table to this script, using the variable names in the
column “Matlab/Simulink” and values from the table. Don´t forget to add a short com-
ment for each constant, describing the unit and the meaning of the constant. Save
and run this script and verify, that all constants from your script are defined as work-
space variables within Matlab. Use these workspace variables in the following
subtasks in all Simulink blocks instead of using numbers.

Seite 37
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

1.9 Create a new Simulink model with the name “sim_temp.slx”. First integrate a Pulse 6P/
generator, which simulates the heat flow ‰ . Configure the Pulse generator, so
that the output has an amplitude of ‰ ¥ . This amplitude shouldn´t be output con-
tinuously. Instead the output should be set to this value for 120 s for each 600 s. In
the rest of this period, the output is 0 kW. Furthermore, the heating should begin with
a delay of 1 hour. Please see the following drawing (not drawn to scale):

Note: The simulation time is considered to be in s.


Add a Scope to your model, set the simulation stop time to an appropriate value, so
that you can verify the correct settings of your pulse generator. Make a screenshot of
your scope window with the built in snipping tool or any other screenshot tool and
save this screenshot in your working directory under the file-name screen.png.

1.10 Include all necessary blocks from the appropriate Simulink blocksets to build a simu- 7 P /
lation model for equations 1 to 3 above. Don´t forget to set the initial temperature of
the hall. Comment your model by writing at least the names of the outputs of the
equations 1 to 3 to the corresponding signals in the model. Connect the output signal
(temperature ‰ ) to a Scope block to visualize the temperature.

1.11 Configure the simulation, so that it uses the fixed-step solver ode2 (Heun). Set the 2P/
stop time to 5 hours and the step size to 1 s. Start the simulation. What temperature
is reached after 5 hours (mean value, estimated from the scope window).

Mean value: __________________________________________

1.12 Include the call of constant.m into the PreLoadFunction Callback. Close the model, 2P/
clear the Workspace and open the model again to make sure, that the Callback mech-
anism works.

1.13 This open loop feed forward control is not very comfortable. Let us try to improve it by 6P/
adding a simple closed loop proportional controller to our model. The control-law can
be described by the following formula:
-
‰ 5000 3 ∗ 25 ℃ ‰ (Equ. 4)

Seite 38
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

This means that we assume a setpoint of 25 °C and a proportional gain of 5000 W/K.
Furthermore, we must limit the value of ‰ to values between 0 and 50 kW (by us-
ing a Saturation block in Simulink).
Save your Simulink model sim_temp.slx under the new name control_temp.slx. Then
replace the Pulse generator by Simulink blocks needed to implement the control law
in Equ. 4 together with a saturation block to limit its output. If you run the simulation,
what is the new mean value of the temperature after 5 simulated hours?

Mean value: __________________________________________

Task 2: Design a control algorithm with Stateflow


In this task, you should design the tracking control algorithm for a photovoltaic (PV) system,
which is equipped with a solar sensor to follow the sun, see the following picture.
South

West

East Elevation
Azimuth angle angle

The solar sensor delivers azimuth and elevation angles of the sun. The azimuth for this
sensor is defined as 0°, if the sun is exactly in the south direction. The value is -90°, if the
sun is in the east and +90°, if the sun stands in the west. The elevation is defined as the an-
gle between horizon and sun. It is a positive value, 0° means that the sun is just hitting the
horizon, 90° means that the sun is directly on top of the PV system (which is not possible in
our country).
The PV system is mounted on a pole and can be moved in azimuth and elevation direction
by two electrical motors. Both angles are measured with special angle sensors, which pro-
vide azimuth and elevation angle of the PV system to the control algorithm. Both values are
already transformed into the coordinate system of the solar sensor.
In order to save energy, the PV system should not be moved continuously towards the
sun. Instead, it should only move, if the angles of the current orientation differs too much
from the detected position of the sun. If the difference in azimuth direction is more than +/-
5°, then the azimuth motor is switched on. The allowed difference in elevation direction is
+/- 3°. Therefore, we get a discrete control algorithm, which we can implement with State-
flow.

Seite 39
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

In addition, there is a manual mode for maintenance work, which disables the automatic
control and moves the PV system to an elevation angle of 90°. The azimuth angle stays at
the current angle until the automatic mode is switched on again. The manual mode can be
activated at any time.
Table of input and output signals:
Inputs / Outputs Var. Meaning
I: Manual mode switch S1 S1 = true, manual mode is activated
I: Solar sensor azimuth angle AZS Analog value, -90° … +90°, east-west-position of sun
I: Solar sensor elevation angle ELS Analog value, 0° … +90°
I: Azimuth sensor PV orientation AZP Analog value, -90° … +90°, east-west-position of PV
I: Elevation sensor PV orient. ELP Analog value, 0° … +90°
O: Azimuth motor pos. direction AZM+ AZM+ = true, motor is turning PV system in positive
azimuth direction
O: Azimuth motor neg. direction AZM- AZM- = true, motor is turning PV system in negative
azimuth direction
O: Elevation motor positive di- ELM+ ELM+ = true, motor is turning PV system in positive
rection elevation direction
O: Elevation motor negative di- ELM- ELM- = true, motor is turning PV system in negative
rection elevation direction

The Simulink model pv_control.slx is already prepared as a template:

The right subsystem called “Simulation” contains a simple simulation of the movement of
the sun which is used to generate the signals AZS and ELS of the solar sensor. The angle
sensors AZP and ELP are also simulated, dependent on the motor control signals. The left
subsystem “Control” is empty and should be filled by you:
2.1 First, add an empty state chart for the control system inside the subsystem “Control”. 9 P /
Define all necessary input and output signals with the appropriate datatype ac-

Seite 40
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

cording to the above table. (Use the datatype “double” for analog values.) Connect in-
puts and outputs of the chart to the already prepared inports and outports of the Sim-
ulink Subsystem Control.
2.2 Next, design the state chart for the control 14 P /
algorithm described above. Do only imple-
ment the part of the chart needed for the
automatic mode! This means, you do not
need input signal S1. If you get a warning
message regarding signal S1, you can ignore
it.
If your solution is correct, you will get a scope
view similar to the picture to the right.

2.3 In the last step, you should add the manual mode. Before you start adding the neces- 8 P /
sary parts, please use the “Save As” function from Simulink to save your model under
the new name pv_control2.slx. After that you can add the states and transitions
needed for the manual mode. Hint: The easiest way to do this is by using super-
states.

Seite 41
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 14.09.2020 (Summer term 2020)

Task 1: Simulation of an irrigation car on a ramp

The position x(t) of an irrigation car on a ramp should be simulated:

A cable connects the irrigation car with the mass mC with a counter balance weight m
through a pulley. The inclination of the ramp is given with angle α. Initial position x0 and ini-
tial velocity v0 of the car on the ramp should be assumed to be 0. The mass mC(t) is not
constant but changes in a linear way with time. It can be described by:

,ª 4
‹¬ -
Δ, (Equ. 1)
®¯

with an initial mass mC0 and an final mass mempty (tank of car empty). The loss of mass per
second is given by Δ,.
The weight FM is given by š° , ∗ D (Equ. 2), where g is the gravitational acceleration.
The grade resistance FCR of the car can be described by:
šªY ,ª ∗ D ∗ sin ± (Equ. 3).
The acceleration a(t) of both masses can be calculated by:
² ³ ²®] ’ ²´
ƒ ˆ
(Gl. 4).
³ ®

The velocity of both masses v(t) can be calculated by J 4ƒ (Equ. 5).


The position of the car x(t) can be calculated by • 4J (Equ. 6).
This irrigation systems works completely without any external power. Just by using the
gravitational energy of water and the counter balance weight with an appropriate value.

Seite 42
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

The following table describes the mathematical symbols and values of necessary con-
stants:
Variable or constant Matlab/Simulink Symbol Value Unit
Initial mass of irrigation car m_c0 ,ª¤ 1000 CD
Mass of empty irrigation car m_empty , V µ 400 CD
Mass loss per second delta_m Δ, 50 CD/(
Mass of counter balance weight m , 600 CD
Angle of ramp alpha ± 60 °
Initial velocity v_0 J¤ 0 ,/(
Initial position x_0 •¤ 0 ,
Gravitational acceleration g D 9.81 ,/( N

1.14 Open the provided template script “constant.m” in Matlab. Add variables for all 4P/
needed constants from the above table to this script, using the variable names in
the column “Matlab/Simulink” and values from the table. Don´t forget to add a
short comment for each constant, describing the unit and the meaning of the
constant. Save and run this script and verify, that all constants from your script
are defined as workspace variables within Matlab.

1.15 Create a new Simulink model with the name “carsim.slx”. Include all necessary 14 P /
blocks from the appropriate Simulink blocksets to build a simulation model for
equations 1 to 6. Do not use numeric values in your model, use the workspace
variables defined in task 1.1 instead. Comment your model by writing the
names of the outputs of the equations 1 to 6 to the corresponding signals in the
model. Connect the output signal (position x(t)) to a Scope block to visualize the
position of the car.

1.16 Configure the simulation, so that it uses the fixed-step solver ode1 (Euler). Set 2P/
the stop time to 20 s and the step size to 0.01 s.

1.17 Run the simulation with the settings from task 1.3. What is the end position of the 2P/
car after 20 s of simulation?

End position: x(20 s) = ___________________________

1.18 Of course, a negative end position is not correct! Change your model, so that the 2P/
position x(t) is limited to positive values.

Seite 43
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 2: Design a control algorithm with Stateflow


In the following picture, you can see the simplified schematics of a coffee maker.
Schematic drawing of coffee maker:

Table of input and output signals:


Inputs / Outputs Var. Meaning
I: Water level sensor S1 S1 = true, enough water is in the tank
I: Flow meter sensor S2 Analog value, amount of water flowing into pump,
scaled in [dm3]
I: Button for coffee program S3 S3 = true, User wants a cup of coffee
I: Button for tea program S4 S4 = true, User wants a cup of tea (hot water)
I: Button for cleaning program S5 S5 = true, User wants to start cleaning program
O: Pump control signal Q1 Q1 = true, pump is on; Q1 = false, pump is off
O: Heater control signal Q2 Q2 = true, heater is on; Q2 = false, heater is off
O: Water valve Q3 Q3 = true, valve is open; Q3 = false, valve is closed
O: Wastewater valve Q4 Q4 = true, valve is open; Q4 = false, valve is closed
O: Coffee program Q5 Q5 = true, start coffee program in brewing unit
O: Tea program Q6 Q6 = true, start tea program in brewing unit
O: Start cleaning program Q7 Q7 = true, start cleaning program in brewing unit
O: Start mill Q8 Q8 = true, mill is running; Q8 = false, mill is stopped
Seite 44
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

All inputs (except S2) and outputs are boolean signals (true / false) and must be imple-
mented with this datatype in the state chart.
The process for the control system of the coffee maker can be described by the following
steps:
 In the idle state the machine is active and waits for user input. The user can request
a cup of coffee (Button S3) or tea (S4) or start the cleaning process (S5).
 Each of the above sub-processes can only be started, if there is enough water in the
tank.
 If the user starts the coffee program, then the control system first activates the cof-
fee bean mill for 1 second.
 Next pump and heater are directly activated.
 0.1 s later, which are needed to provide pressure to the system, valve Q3 is opened
and the brewing unit is activated with the correct signal for coffee.
 Brewing of coffee is finished, when sensor S2 measures at least a flow of 0.15 dm3.
 After that, heater and brewing unit are turned off and valve Q4 is opened.
 For another 1.5 s cold water is pumped through pipes and brewing unit in order
clean it for the next user request.
 The tea program is a little bit easier: When the user request it, then pump and
heater are directly activated.
 After 0.1 s valve Q3 is opened and the brewing unit is activated with the correct sig-
nal for tea.
 The process ends, when sensor S2 measures at least a flow of 0.15 dm3.
 In the cleaning program, cold water is pumped through pipes and brewing unit, until
sensor S2 measures at least a flow of 0.3 dm3. The cleaning program also must acti-
vate the correct signal in the brewing unit and open valve Q4.
The Simulink model coffee_maker.slx is already prepared as a template. The prepared
blocks (constants and Pulse generators) can be used as input for your Stateflow chart. The
integrated Scope block should be connected to the outputs of your chart. The chosen pa-
rameters on the input side blocks will trigger a test run of the coffee program.
2.1 First, add an empty state chart for the control system described in above step-by- 8P/
step-description. Define all necessary input and output signals with the appropriate
data type. Connect inputs and outputs to the already prepared blocks of the Simulink
model.
2.2 Next, design the state chart for the control system, according to the above descrip- 16 P /
tion. Note: Sensor signal S2 is automatically reset, when a new user request is re-
ceived. It is not necessary to integrate this reset procedure into your chart!

Seite 45
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 27.01.2020 (Winter term 2019)

Task 1: Simulation of a hydraulic cylinder


The hydraulic system shown in the following picture should be simulated:

The pump supplies a flow with pressure x… to the system. There is a control valve 1,
which is needed to provide a constant pressure xN to the cylinder. This valve is controlled
by variable K, which is the orifice area of the valve. It divides the flow into a turbulent flow
¶…N and a laminar flow ¶ 0 back into the fluid reservoir. The flow ¶…N leads to the interme-
diate pressure xN , which undergoes a subsequent pressure drop in the line connecting it to
the control valve 2 and to the actuator cylinder. It can be assumed, that control valve 2 has
no influence on the dynamics of the hydraulic system. The cylinder pressure x• moves the
piston against a spring load, resulting in a position •.
The next table describes the mathematical symbols and values of necessary constants:
Variable or constant Matlab/Simulink Symbol Value Unit
@… 2 ∗ 10’· , •

sec ‚ƒ
Laminar flow coefficient C1

@N 3 ∗ 10’¹ ,••
sec ‚ƒ
Flow coefficient C2
Orifice discharge coefficient Cd @ 0.61
¶ 0.0015 ,••
Reflow from cylinder q_rf 1 (n
L 800 CD•
,•
Fluid density rho
Fluid bulk modulus beta º 7 ∗ 10· ‚ƒ
Cylinder cross-sectional area Ac K/ 1 ∗ 10’• ,N
; 5 ∗ 10¢ »•
Spring constant K ,
Fluid volume in the piston for x=0 V30 y•¤ 2.5 ∗ 10’¼ ,•
Initial value for x… p10 x…¤ 3.33 ∗ 10½ ‚ƒ

Seite 46
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

1.19 Open in Matlab the provided template script “constant.m”. Add variables for all 5P/
needed constants from the above table to this script, using the variable names and
values from the table. Don´t forget to add a short comment for each constant, de-
scribing the unit and the meaning of the constant. Save and run this script and ver-
ify, that all constants from your script are defined as workspace variables within
Matlab. (There are other constants already defined in this script, which are needed for
the Simulink template below.)

Next, open the Simulink template “hydraulic.slx”:

In this template the structure of the model needed for the simulation of the hydraulic system
is already given. In the following tasks, you should build the models into the empty subsys-
tems. Note: Each task can be solved independently!

1.20 Configure the simulation, so that it uses the fixed-step solver ode4 (Runge-Kutta). 2P/
Set the stop time to 0.1 s and the step size to 0.0001 s.

1.21 First, start with the pump model. It can be described by the following formulas: 3P/
¬¾‹¬ ’ ‡h
x… ªh
(Eq. 1) and ¶ 0 V V ¶…N (Eq. 2).
Build the simulation model for the equations Eq. 1 and Eq. 2 within the subsystem
“Pump”. Use the variables defined in constant.m in your model. Use only basic blocks,
like constant, gain, sum, …

1.22 Next, build the model for control valve 1 and 2. Valve 1 can be described by the fol- 8P/
lowing equation:
N
¶…N @ ∗ K ∗ (Dq x… xN ∗ ¿À ∗ |x… xN | (Eq. 3).
Above equation Eq. 3 is only valid, if the signal t of Valve 2 is true ( 1). If t is false
( 0), then the value of ¶…N 0.

Seite 47
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Build the simulation model for the equation Eq. 3 within the subsystem “Con-
trol_Valves”. Use the variables defined in constant.m in your model. Use only basic
blocks, like constant, gain, sum, sign, abs, sqrt, …

1.5 Next part is the cylinder model. The dynamic behaviour of the cylinder can be de- 12 P /
scribed by the following equations:
 w®
x•) ∗ ¶…N Kª •) (Eq. 4) with •) x•) (Eq. 5)
ÃS 3

y• y•¤ _ Kª • (Eq. 6) with • 3
x• (Eq. 7)
xN x• _ ‡h
(Eq. 8).
ª‡
As long as Ä is true, you can use ÅÆŽ calculated from Eq. 3 in task 1.4. If Ä is
false, then the you should use ÅÇÈ in Eq. 4. In order to avoid negative values for •,
you should limit the lower limit of the integrator for x• to 0.
Hint: You should first use equations Eq. 4 and Eq. 5 to calculate a differential equa-
tion for x•) .
Room for calculations:

Build the simulation model for the equations Eq. 4 up to Eq. 8 within the subsystem
“Cylinder”. Use the variables defined in constant.m in your model. Use only basic
blocks, like constant, gain, sum, integrator, …

If you now start the simulation and everything is correct, the result for the cylinder position x
should look similar to the following picture (ignore warnings about algebraic loops):

Seite 48
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 2: Design a control algorithm with Stateflow


A feeder of a production line consists of a parts magazine, a pick-and-place robot, a con-
veyor belt together with a synchronizing mechanism. The complete system should be auto-
mated with a state chart. The following picture shows the setup of the feeder
Schematic drawing of feeder components:

Table of input and output signals:


Inputs / Outputs Variable Meaning
I: Part under magazine S1 S1 = true, one part is under the magazine
I: Part ready S2 S2 = true, one part is ready for pick-off
I: Robot finished S3 S3 = true, robot finished its taught program
I: Part on table S4 S4 = true, part is on table
I: Left end of synchronizer S5 S5 = true, carriage is on the left side
I: Start point for sync. S6 S6 = true, carriage is on the start point for sync.
I: Right end of synchronizer S7 S7 = true, carriage is on the right side
O: Pneumatic cylinder Q1 Q1 = true, cylinder moves to the right
Q1 = false, cylinder moves to the left
O: Start robot program Q2 Q2 = true, robot starts its taught program (should
stay activated for at least 1 s)
O: Pneumatic cylinder Q3 Q3 = true, cylinder moves downwards
Q3 = false, cylinder moves upwards
O: Vacuum gripper Q4 Q4 = true, vacuum gripper is activated
Q4 = false, vacuum gripper is deactivated
O: Move carriage right Q5 Q5 = true, move the carriage to the right
Q5 = false, movement is stopped
O: Move carriage left Q6 Q6 = true, move the carriage to the left
Q6 = false, movement is stopped
All inputs and outputs are boolean signals (true / false) and must be used with this
datatype in the state charts.

Seite 49
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

The process can be described by the following steps:


 Parts Magazine: If there is a part detected with sensor S1 and no part at sensor S2,
the cylinder can be activated with output Q1. After that it should move back.
 Robot: If S3 states, that the robot has finished its previous action and there is no
part on the table (S4), and a part is present at position S2, then the robot should be
started by activating output Q1. Furthermore, movement of the robot is prohibited, if
the synchronizing carriage is on the far left position (S5).
 Synchronizer: The synchronizing mechanism picks up a part from the table (S4) at
the position S5. Picking is done by activating Q3 and later the vacuum gripper Q4.
There are no sensors at the initial and end positions of the cylinder or the vacuum
gripper.
 After the cylinder is moved up, the motor is activated with Q5, which moves the car-
riage to the right.
 At the position of sensor S6, the speed of the carriage should have reached the
speed of the conveyor belt. The conveyor is working continuously.
 Now the cylinder moves down again and the vacuum gripper gets deactivated after
some time.
 The cylinder moves up again while the movement of the carriage continues, until the
position of S7 is reached. Here Q5 must be deactivated.
 After that the carriage will be returned to the position of sensor S6 by activation of
output Q6. Here it waits until the next part is detected by sensor S4. Then the pro-
cess repeats.
In order to reduce the complexity, this automation task should be implemented by three in-
dependent charts, which are already prepared in the Simulink model feeder.slx. For each
chart, there is a subsystem defined. Inside the subsystem you find the chart itself along with
a Signal Editor block for stimulation of input signals and Scopes for visualization. You can
use this blocks to test the behaviour of your chart. (In order to be able to test a chart, if the
other charts are not yet implemented, it may be necessary to comment the other subsys-
tems out!)
2.1 In a first step, build the state chart for the Magazine control, according to the 6P/
above description. This needs S1 and S2 as inputs and generates the output signal
Q1, which controls the pneumatic cylinder. It must wait at least 3 s until it pushes the
next part out of the magazine.
2.2 Next, design the state chart for the Robot control, according to the above descrip- 6P/
tion.
2.3 Complete the following diagram on the next page, representing the synchronizing 8P/
mechanism. It is not necessary for the drawing to be true to scale. It must include at
least one complete synchronizing process, which is described by the above state-
ments. Draw vertical dashed lines to distinguish between states. Give each state a
unique name below the diagram.

Seite 50
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

2.4 Draw a state chart needed to implement the control algorithm for the synchronization 10 P /
mechanism as described above. Wherever you may need a time in your transitions,
use 1 second.

Seite 51
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 25.07.2019 (Summer term 2019)

Task 1: Simulation of the Lorenz system


The Lorenz system is a system of ordinary differential equations first studied by Edward
Lorenz in 1963. It is developed as a simplified mathematical model for atmospheric convec-
tion. It consists of three ordinary differential equations now known as the Lorenz equations:
Eq. 1: •) ƒ ™ •
Eq. 2: ™) • o É –™
Eq. 3: É) •™ É
The above system of three nonlinear coupled differential equations is notable for having
chaotic solutions for certain parameter values and initial conditions. In particular, the Lo-
renz attractor is a set of chaotic solutions of the Lorenz system. (Wikipedia)
The following table describes the mathematical symbols and values of necessary con-
stants:
Variable or constant Matlab/Simulink Symbol Value
Rate of convection x •
Horizontal temperature variation y ™
Vertical temperature variation z É
Parameter proportional to the Prandtl number a ƒ 10.0
Parameter proportional to the Rayleigh number b o 25.0
Parameter related to physical dimensions c 8/3
Initial value for integrator x x_init 0.1
Initial value for integrator y y_init 0.1
Initial value for integrator z z_init 0.1

1.23 Open Matlab and generate a new script “constant.m”. Add variables for all needed 4P/
constants from the above table to this script, using the variable names and values
from the table. Don´t forget to add a short comment for each constant, describing the
meaning of the constant. Run this script and verify, that all constants from your script
are defined as workspace variables within Matlab.

1.24 Open SIMULINK and generate a new model “Lorenz.slx”. Configure the simulation 2P/
so that it uses the fixed-step solver ode4 (Runge-Kutta). Set the stop time to 100 s
and the step size to 0.005 s.

Seite 52
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

1.25 Build the simulation model for the equations Eq. 1, Eq. 2 and Eq 3. Use the varia- 12 P /
bles defined in constant.m in your model. Don´t forget to set the correct initial values
for the integrators!

1.26 Next, add three “To Workspace” blocks to your model. Name them “x”, “y” and “z” 3P/
and connect them to the integrators for x, y and z. Change the “Save format” setting of
each “To workspace” block to “Array”. Start the simulation. Now you should have
three additional variables x, y and z in your Workspace.

1.5 As the last step, generate an new Matlab script “visualization.m”. As the plotting ca- 3P/
pabilities of Simulink don´t allow to generate 3D-plots, you should implement this with
the help of the “plot3”-command in a Matlab script by using the generated workspace
variables from task 1.4.

The result, when you run the script, should be similar to the following picture:

Task 2: Look-Up Tables for modelling nonlinearities


Look-Up tables may be used to model nonlinear behaviour of components. In an electronic
control unit for a car a photoresistor is used to measure the light intensity of the environ-
ment. This part of the measurement is already implemented in hardware. The change in re-
sistance is used to calculate the luminosity.

In order to get a higher precision, the environmental temperature must also be taken into
account. In the datasheet of the photoresistor we can find the following diagram, which
shows us a correction factor dependent on temperature.
Seite 53
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Correction factor (%)

2.1 Open the Simulink model “lookup.slx”:


2P/

The subsystems “Calc_luminosity” and “Calc_temperature” already include a test


model, which generates values for luminosity and temperature. You should add to the
subsystem “Correct” all necessary blocks, which are needed to generate a new lu-
minosity value “luminosity_corr”. This value is given by the following equation:

Xp,kqs(k ™/ Xp,kqs(k ™ ∗ l n,xnMƒ pMn

You can use a Look-Up table for l n,xnMƒ pMn .

2.2 Use the data import tool in Matlab to import the look-up-table data from the Excel file 3 P /
“resistor.xlsx”. Transfer the data needed for the look-up-table into two Matlab
workspace variables “factor” and “temperature”. Save this two variables with the
“save”-command to a mat-file “resistor.mat”.

Seite 54
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

2.3 Use the “Initfcn” callback function (File -> Model Properties) to load the mat-file “re- 3 P /
sistor.mat” every time, the simulation is started. Save your model and clear the work-
space. If you start your simulation now, your variables should be loaded again from
the mat-file.

2.4 Next, use the workspace variables from task 2.2 as breakpoint and table data for the 4 P /
look-up-table in your model and run the simulation. Look at the Scope window,
make a screenshot of it and save it under the filename “lookup.jpg” in jpg-format.
You can use the Windows Snipping tool for that task.

Task 3: Design a control algorithm with Stateflow


A filling station should be automated with a state chart. The following picture shows the
setup of the filling station
Schematic drawing of filling station components:

Seite 55
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

This state chart needs the following input and output signals:
Table of input and output signals:
Inputs / Outputs Variable Meaning
I: Start position of cyl. S1 S1 = true, pneumatic cylinder is in start position
I: End position of cyl. S2 S2 = true, pneumatic cylinder is in end position
I: Bottle fill sensor S3 S3 = true, bottle is full
I: Bottle position sensor S4 S4 = true, bottle is in filling position
I: Liquor storage sensor S5 S5 = true, enough liquor for filling a bottle is in storage
I: On/Off switch S6 S6 = true, filling station is on
O: Vacuum pump Q1 Q1 = true, pump is on, producing vacuum
O: Pneumatic cylinder Q2 Q2 = true, cylinder moves downwards
O: Vacuum valve V1 V1 = true, filler head and bottle get evacuated
O: Liquor fill valve V2 V2 = true, liquor is filled in bottle
O: Conveyor motor M1 M1 = true, conveyor belt moves
All inputs and outputs are boolean signals (true / false).
3.1 Complete the diagram on the next page. It is not necessary for the drawing to be true
to scale. It must include at least one filling process, which can be described by the
following statements:
 The filling station is started by pressing the On/Off-switch S6. It is only possible
to start the process, if the liquor storage sensor S5 shows, that there is enough
liquor in the storage.
 After that, the vacuum pump Q1 is activated. Vacuum valve V1 is closed. The
pump stays activated, as long as the On/Off-switch S6 is in the “On” state.
 It takes 2 s to generate the vacuum.
 Afterwards the conveyor belt begins to move by activating motor M1. The belt
moves as long as is needed to detect a bottle at the filling position by sensor
S4.
 Next, the filler head is moved downwards onto the bottle. This is done with the
help of a pneumatic cylinder by applying pressure to it with a control valve (not
included in drawing), which is actuated by signal Q2.
 Sensors S1 and S2 show the starting and end position of the cylinder.
 When the filler head is on top of the bottle (S2 is activated), the vacuum valve
V1 gets opened for 1 s and then closed again. Now, bottle and filler head are
evacuated.
 After that, the filling valve V2 gets opened. Liquor is filled into the bottle be-
cause of the vacuum. When the bottle is full, sensor S3 gets activated.
 Then V2 is closed again. The filler head is moved upwards by the pneumatic
cylinder. As the reverse movement of the cylinder is driven by a built-in spring,
this movement is activated by deactivating signal Q2.
 When the cylinder is back in its start position (S1), the conveyor belt starts to
move again and transports the next empty bottle to the filling position.

Seite 56
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

This process is repeated, as long as the switch S6 is on and enough liquor is in the liquor
storage, shown by S5.

9P/

Seite 57
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

3.2 For this task, a Simulink model named „filling.slx“ is prepared. It includes a very basic 6 P /
process model in the subsystem “Process_Simulation”. In the empty subsystem “Con-
trol” you should implement a state chart, representing the control algorithm described
by the task description and analyzed in Task 3.1. First, add a Stateflow chart and de-
fine all necessary input and output signals with the appropriate data type according
to the above table. Connect inputs and outputs of the chart to the corresponding in-
ports and outports of the subsystem.

3.3 Draw a state chart needed to implement the control algorithm as described above. 9P/
Use absolute time temporal logic where necessary. If your model is correct, you will
get an output in the prepared scope similar to the diagram in task 3.1

Seite 58
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Examination 05.02.2019 (Winter term 2018)

In this examination, you should design a simulation model for a two stage bal-
listic rocket. The following tasks guide you through the complete model build-
ing in a step-by-step process. This process is supported by some already pre-
pared files, placed in the directory created automatically at the login.

Task 1: Simulation of a single-stage rocket


In the first step, we will try to simulate a single-stage rocket (see left picture).
The velocity of such a rocket can be described by the so called “rocket equa-
tion” of the Russian teacher Konstantin Ziolkowski (published 1903):
•Ê ³
J) | ∗ ,) € _ ƒH •
]

This differential equation is based on the conservation of momentum and describes the ac-
celeration of a rocket starting in vertical direction with disregard of the aerodynamic re-
sistance. Velocity and actual mass of the rocket can be calculated with the following integral
equations:
J 4 J) ; ,Y 4 ,) ;

(A rocket burns its fuel continuously and therefore loses continuously mass, ,) is negative!)
The next table describes the mathematical symbols and values of necessary constants:
Variable or constant Matlab Symbol Value Unit
Height above ground h ℎ ,
Velocity v J , ⁄(
Gravitational acceleration a_grav ƒH • , ⁄( N
Velocity of exhaust gas from rocket nozzle v_Gas JÌ 4500 ,⁄(
Actual mass of rocket m_R ,Y CD
Mass of rocket at start time of stage 1 M_Start1 e … 123000 CD
Mass of rocket at end of combustion of stage 1 M_End1 Í+ … 35500 CD
Fuel rate combusted per second for stage 1 dM1 ,) … -2000 CD⁄(
Mass of rocket at start time of stage 2 M_Start2 e N 23000 CD
Mass of rocket at end of combustion of stage 2 M_End2 Í+ N 5500 CD
Fuel rate combusted per second for stage 2 dM2 ,) N -1000 CD⁄(
Acceleration of gravity at ground level g D -9.81 ,⁄( N
Gravitational constant G Î 6.674e-11 ,• ⁄CD( N
Mass of Earth m_E ,Í 5.972e24 CD
Radius of Earth r_E MÍ 6.371e6 ,

Seite 59
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

(The above table also includes constants, which you need for later tasks.)

1.27 Open the prepared MATLAB script “constant_declaration.m”. Add variables for all 7P/
needed constants from the above table to this script, using the variable names and
values from the table. Don´t forget to add a short comment for each constant, de-
scribing the meaning and the unit of the constant.

1.28 Open the prepared SIMULINK model “Sim_Rocket_v1.slx”: 2P/

Configure the simulation so


that it uses the fixed-step
solver ode4 (Runge-Kutta).
Set the stop time to 200 s
and the step size to 0.1 s.

The script from task 1.1 will


be loaded before you start the
simulation, because it is already included in the InitFcn-Callback. This model will cal-
culate from the acceleration of the rocket, its velocity v and its height above ground h.

1.29 The subsystem “Rocket_Stage1” from task 1.2 is empty. Inside this subsystem, you 7P/
should now implement the rocket equation. The best way to do this, is to start with the
calculation of the rocket mass ,Y . You will need an integrator block from the Sim-
ulink library. Drag this block into your subsystem and activate the “Limit output” Op-
tion in the Block Parameters dialog. Now you can also set the upper and lower satura-
tion limit (Mass of rocket stage 1 at start time and at end of combustion). Don´t forget
to set the correct initial value!
The calculation of the rocket mass is given by the following equations:

°ÏÐ^‡
,Y… 4°Ñ ,)… if signal (“ignition” is true) AND ,Y… Ò Í+ … ;

°ÏÐ^‡
,Y… 4°Ñ ‡ 0 otherwise.

You will need a switch block at the input of the integrator to implement this decision.
Use the constants defined in “constant_declaration.m” inside of constant blocks in
your model.

1.30 Next, add the calculation of the acceleration J) (output 1 of the subsystem) of the 7P/
rocket. It can be calculated from the following equation:

J) Ó ∗ ,)… Ô _ ƒH •
,Y…
Seite 60
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

In this equation, the gravitational acceleration ƒH • must be set to – D as long as the


signal (“ignition” is true) AND ,Y… Õ Í+ … , else it must be set to 0.

1.5 As the last step, add the signal for the second output of the subsystem (burnout). 2P/
This boolean signal gives a “true” value, if the actual mass of the rocket is less than or
equal to the mass at the end of combustion: opMqsp ,Y… “ Í+ … .

Now you can simulate your single-stage rocket. The result of the simulation in the pro-
vided scope should look similar to the following picture:

Seite 61
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 2: Simulation of a multi-stage rocket


2.1 Open the Simulink model “Sim_Rocket_v2.slx”: 2P/

Next, replace the subsystem “Rocket_Stage1” in this model with the subsystem
“Rocket_Stage1” from your previous model “Sim_Rocket_v1.slx” of task 1.

2.2 Replace the subsystem “Rocket_Stage2” with a copy of subsystem 4P/


“Rocket_Stage1”. This subsystem should now represent the second stage of the
rocket. Therefore you must replace every occurrence of constants with index “1” (like
“dm1”) in this subsystem by constants with index “2”, see the definitions in script “con-
stant_declaration.m”.

2.3 Because of the height above ground level this rocket can reach, it is not appropriate to 5 P /
use a constant value for the gravitational acceleration. Instead, we can calculate the
acceleration from Newton´s law of universal gravitation:

ƒH • Î∗
MÍ _ ℎ N
Implement this equation in the empty subsystem “Gravitation”. The output “gravity” of
this subsystem is ƒH • .

Seite 62
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

Task 3: Design a control algorithm with Stateflow


In the empty subsystem “Control” of model “Sim_Rocket_v2.slx” from task 2, a control al-
gorithm for the ignition of both rocket stages should be implemented using a state chart.
This state chart needs the following input and output signals:
Table of input and output signals:
Input / Output signals Variable Meaning
I: Ignition signal Ignition Ignition = 1, start of Countdown
I: Combustion end of stage 1 Burn_end1 Burn_end1 = 1, combustion of stage 1 is finished
I: Combustion end of stage 2 Burn_end2 Burn_end2 = 1, combustion of stage 2 is finished
O: Ignition of stage 1 Ign_stage1 Ign_stage1 = 1, start combustion of stage 1
O: Ignition of stage 2 Ign_stage2 Ign_stage2 = 1, start combustion of stage 2
O: Gravitation acceleration Gravity Gravity = 1, only earth´s gravity is effective, no
further acceleration
All variables in the above table have only binary values (“true”/”false”)!
The control algorithm should implement the following sequence:
 After starting the simulation, it should wait for the ignition signal.
 When the ignition signal is detected, a Countdown from 10 s to 0 s is started.
 After the end of the Countdown, stage 1 of the rocket must be started.
 When stage 1 reaches the end of combustion, stage 1 must be separated from the
rest of the rocket. There is no output action related to this separation (because this is
not yet modelled), but the control algorithm must wait for 10 s, until it can start the
second stage.
 After the above mentioned 10 s, stage 2 of the rocket must be started.
 When stage 2 reaches the end of combustion, it must also be separated from the
rest of the rocket. There is no output action related to this separation, but the control
algorithm should stay in this state. This is also the end of the control algorithm.
 The output signal “Gravity” must be set to “true” in the phases of flight, when there is
no acceleration due to a combustion, otherwise it must be set to “false”. The simula-
tion model needs this signal for correct calculation of the rocket velocity.

3.1 In subsystem “Control” of model “Sim_Rocket_v2.slx”, add a Stateflow chart and de- 7P/
fine all necessary input and output signals with the appropriate data type according
to the above table. Connect inputs and outputs of the chart to the corresponding in-
ports and outports of the subsystem.

3.2 Draw a state chart needed to implement the control algorithm for the rocket launch as 12 P /
described above. Use absolute time temporal logic where necessary. (Hint: You can
implement the Countdown with the help of a local variable, which is decremented
every second within one state.)

Seite 63
Fakultät für Ingenieurwissenschaften
Prof. Dr.-Ing. Franz Perschl

If your model is correct, you will get an output in the prepared scope similar to this picture:

Seite 64

You might also like