2.6 Creating a Hybrid Model in the WSM Package …
83
behavior of the model. The if statement or expression remains active as long as the
conditional expression is true. If a statement or expression containing if contains an
else operator, then any branch will always be active.
For more information about the when operator, see [4].
2.6.2 An Example of Using Modelica Language Tools:
Bouncing Ball
Let us now consider the simplest hybrid model using the example of a bouncing ball.
The model should describe the vertical movement of the ball, which falls due to
gravity and bounces off the floor. The acceleration of gravity is constant and equal
to g = 9.8 m/s
2 . The height above the floor from which the ball begins to move is h.
The speed of the ball is denoted as v.
The origin is placed on the floor. Coordinate of the ball above the floor is positive.
The speed of the ball is positive when it moves up. The following system of two
equations describes the free vertical movement of the ball:
dh
dt
= v
dv
dt
= −g
These are continuous equations.
The initial position and speed of the ball will be denoted, respectively, by h 0 and
v 0 . The ball bounces up when it touches the floor. It is assumed that in this case the
direction of the speed of the ball is reversed and its value decreases by 20%; that is,
when hitting the floor, the ball loses some of the stored energy. Suppose that before
contact with the surface the speed of the ball was equal to v b , and after the rebound
from the surface it became v a . The processes occurring at the time of the rebound
can be neglected, that is, assume that the rebound occurs instantly. This means that
a discrete action is performed at the time of the bounce.
v a = 0.8v b
For example, if the speed of the ball before the rebound is −10 m/s, then after
the rebound it is 8 m/s. A negative speed sign indicates that the ball is falling, and a
positive sign indicates that it is moving up after a rebound.
We already know how to write continuous equations in WSM. Let us consider in
detail how to describe a discrete event. This can be done using the when statement
and the override function reinit(), as shown below.
when h ≤ 0, then;
reinit (v, -0.8 · v);
83
behavior of the model. The if statement or expression remains active as long as the
conditional expression is true. If a statement or expression containing if contains an
else operator, then any branch will always be active.
For more information about the when operator, see [4].
2.6.2 An Example of Using Modelica Language Tools:
Bouncing Ball
Let us now consider the simplest hybrid model using the example of a bouncing ball.
The model should describe the vertical movement of the ball, which falls due to
gravity and bounces off the floor. The acceleration of gravity is constant and equal
to g = 9.8 m/s
2 . The height above the floor from which the ball begins to move is h.
The speed of the ball is denoted as v.
The origin is placed on the floor. Coordinate of the ball above the floor is positive.
The speed of the ball is positive when it moves up. The following system of two
equations describes the free vertical movement of the ball:
dh
dt
= v
dv
dt
= −g
These are continuous equations.
The initial position and speed of the ball will be denoted, respectively, by h 0 and
v 0 . The ball bounces up when it touches the floor. It is assumed that in this case the
direction of the speed of the ball is reversed and its value decreases by 20%; that is,
when hitting the floor, the ball loses some of the stored energy. Suppose that before
contact with the surface the speed of the ball was equal to v b , and after the rebound
from the surface it became v a . The processes occurring at the time of the rebound
can be neglected, that is, assume that the rebound occurs instantly. This means that
a discrete action is performed at the time of the bounce.
v a = 0.8v b
For example, if the speed of the ball before the rebound is −10 m/s, then after
the rebound it is 8 m/s. A negative speed sign indicates that the ball is falling, and a
positive sign indicates that it is moving up after a rebound.
We already know how to write continuous equations in WSM. Let us consider in
detail how to describe a discrete event. This can be done using the when statement
and the override function reinit(), as shown below.
when h ≤ 0, then;
reinit (v, -0.8 · v);
