Abstract
What if our models are neither continuous nor discrete? In this chapter we cover hybrid automata. Starting from a continuous setting, we introduce discrete events and look at the issues that arise in making such a transition. We analyze the issues of zero crossing and decidability; mode switching and its effect on derivatives; discrete transitions; and Zeno behavior.
Download chapter PDF
What if our models are neither continuous nor discrete? In this chapter we cover hybrid automata. Starting from a continuous setting, we introduce discrete events and look at the issues that arise in making such a transition. We analyze the issues of zero crossing and decidability; mode switching and its effect on derivatives; discrete transitions; and Zeno behavior.
1 Introduction
We begin by considering a classic example that builds on concepts that we are familiar with from modeling physical systems. Consider a ball that leaves the ground with a certain speed and at a certain angle, and determine where it lands. In all such high school and college physics questions, every story stops as soon as the ball hits its target. But what happens to the ball after it hits the ground?
A bouncing ball is a system that can be described by two different modes of behavior: falling; and bouncing or resting on the floor. How can we model a system that includes such different modes of behavior?
When the ball is falling we have only the effect of gravity, which has a constant g = 9.8 N/kg. In that case, the ball is governed by the Newtonian law of F = ma (force equals mass times acceleration). We should keep in mind that the net or “total” force on any object is the sum of all the forces applied on the object. This summation applies whether we are working in a one, two, or three dimensions. Since we have
then if the only force acting on a mass is gravity, then we also know that
By dividing both sides by m we obtain a = g. By substituting 9.8 for the value of g, we get (in the dimensionless setting, where “m/s^{2}” is ignored) that a = 9.8.
The position vector x is usually defined as the vector going from the floor level to the position of the ball. In this setting the acceleration goes in the opposite direction. Finally, as a differential equation in relation to the position x, the above equation simply means
Now let us turn to modeling the process of bouncing . One solution could be to imagine that, once the ball is in contact with the floor, it experiences another force that we will model as a spring force arising from contact with the ground. The higher the spring coefficient, the faster the bounce. To model this effect, we must return to our original equation and consider the entire situation. The total force on the object must still, as always, be equal to the mass times the acceleration. But the forces acting on the ball are now slightly different:
The gravity force and the acceleration are the same as above; but F_{floor} will be determined by Hooke’s law, generating a force − kx where we can take k to be a large coefficient. Thus, Equation (3.4) can be expressed as
Now, when solving for a we get
Now we notice that we need to specify the coefficient k. Interestingly, at this point we may also need to specify the mass (why did we not need to worry about the precise mass of the ball before?). However, we can avoid the need to specify both separately, because the equation can be further simplified to
which is can be written as
We can simply consider a situation where the ratio between k and m is high (such as 100); then we have all the information that we need for a model of a ball that can undergo simple elastic bouncing when it hits the floor. With this, we can replace the acceleration a with with x″, and k∕m with 100, to get the differential equation:
We can use Hooke’s law to model F_{floor}, i.e., to model the floor as a spring.
Now all that remains is the question of how to specify the switch between being in flight and being in the bouncing state. This can be described as follows:
Once we introduce ifstatements into our models we are no longer working with simple differential equations. Rather, we have moved into a world where our models are describing different behaviors when the system is under different modes . We can think of a mode as the domain of validity of certain conditions (such as x ≥ 0 or x ≤ 0 in the above example). More generally, we can choose to define the notion of a mode as an explicitly named state (such as “Falling” or “Bouncing”), which we treat as an explicit part of our model.
Exercise 3.1 Use Acumen to find out the effect of increasing the ratio k∕m. For example, try out the simulation with different values for the spring coefficient to validate the model. What happens when you use 1000, 10,000, or 15,000 instead 100? What happens when you use 25,000 or 50,000?
2 Hybrid Automata
Hybrid systems are systems of mathematical equations that combine both continuous and discrete dynamics. Often, they are formalized as a kind of extension to finite state machines called hybrid automata. For our purposes in this book it suffices to have an intuitive understanding of these notions. To get started, to remind ourselves of finite state machines (or finite automata), let us take the example of a simple traffic light.
Example 3.1 Mathematically speaking, we may want to model a traffic light as being, at any point in time, in one of the three states. We can think of a state as simply one of the three constants in the set {Red, Green, Yellow}. Further, we may want to model the behavior of the traffic light machine by a set of rules that determine the allowable ways in which the state of the traffic light can change from one instance to another. Rules in the case of a finite state machine are simply pairs of states written as “s1 ⇒ s2.” The first state is the one we are in and the second state is the one we can go to next. So, a typical traffic light can be modeled with the following rules:

Rule 1: Red ⇒ Green.

Rule 2: Green ⇒ Yellow.

Rule 3: Yellow ⇒ Red.
This is a purely discrete model. In a synchronous model of finite state machines, we can require that transitions only happen at previously determined “clock ticks.”
The notion of a trace of a finite state machine is simply a sequence of allowable state transitions that a finite state machine can undergo. For example, the following sequences are valid traces for the machine we described above: Red ⇒ Green ⇒ Yellow, as well as the trace Green ⇒ Yellow ⇒ Red ⇒ Green. However, the sequence Green ⇒ Yellow ⇒ Green is not a valid trace because we have no rule that allows the transition Yellow ⇒ Green. Similarly, it should also be noted that in this system there are no transitions from one state to itself. So, Red ⇒ Green ⇒ Green is not a valid trace either.
Now let us consider another example.
Example 3.2 Consider another finite state machine that represents whether an airconditioning system is either cooling or on standby. In this case, we can have two simple states {Cool, Wait}. As you know, an airconditioning system cools the room for a while, then switches back to the waiting state, then reverts to cooling, and so on. So, the rules for the possible transitions in such a system are quite simple:

Rule 1: Cool ⇒ Wait.

Rule 2: Wait ⇒ Cool.
During the cooling process, the system pumps heat out of a room at a constant rate, and the temperature goes down. In addition to the standard finite state machine model of this system, we may also want to build more details into our model. In particular, we might want to specify something about the temperature of the room explicitly; we might also want to specify the rate at which the room is gaining heat from the outside environment, and the rate at which the airconditioning system is removing this heat when it is in the cooling state. Such information cannot be included in a traditional finite state machine model. However, we can extend the basic model and arrive at what is known as a hybrid automaton. This is where we can add information to each state about some continuous variables that can evolve according to certain rules over time (which itself is modeled as a dense time). For this example, all we have to do is the following: introduce a realvalued variable T to describe the current temperature of the room, and then add the following two rules about what happens to this variable when the system is in each of the two states.

While in state Cool: T′ = −1^{∘}/s.

While in state Wait: T′ = 0.1^{∘}/s.
In each of the two states there is a dynamical equation describing the rate of change of the temperature. Such equations can be much more involved than the ones considered here, and could, for example, be nonlinear. However, what is important here is that this model specifies clearly what happens to the temperature in the room (in terms of the rate at which it changes) when it is in each of these two states. In addition, we may want to go back to our rules and specify how the thermostat (the controller for the airconditioning unit) determines when it should change from one state to another. We can do this by creating an extended set of transition rules as follows:

Rule 1: Cool ⇒ Wait is a transition that must occur when T < 20.

Rule 2: Wait ⇒ Cool is a transition that must occur when T > 25.
Note that we use different temperatures to switch, to avoid alternating too quickly and potentially damaging our airconditioning system.
Exercise 3.2 Use Acumen’s strings and casestatements to express the example system above as an Acumen model. Simulate the system with a starting value for Temperature as 23^{∘}.
3 Reset Maps
Now we return to our bouncing ball example. In addition to specifying rules for how continuous variables can evolve inside a state, we can also perform a discrete change to a variable as we transition from one state to another. This allows us to perform instantaneous changes in direction without having to use, for example, a spring with a high stiffness coefficient. However it requires a further refinement to our notion of hybrid automata, namely, the introduction of reset maps. This extension simply allows us to specify that, as a transition occurs, we want to reset certain variables in our system to new values that are better suited to model the state of our system. Now we can model our bouncing ball example as follows:

States = {Flying}.

While in Flying: x″ = −9.8.

Transition 1: Flying ⇒ Flying, if x = 0 and x′ < 0 then x′ ⇐ − 0.9 x′.
Note that in this system we only have a single state, “Flying.” The second bullet specifies the dynamics while in this state, namely, falling with a constant, negative acceleration. For this system, one state is actually enough because the work needed to model bouncing can be done in the transition from this state to itself, and in particular, in the reset map applied in the transition from this state to itself. The reset map is what is described by the part that says x′⇐ − 0.9x′, and it means that we want the x′ value (which is the speed of the bouncing ball) to be reset to a new value after the transition. That value will be the result of multiplying the value of x′ before the transition by 0.9. Furthermore, we will switch the sign of the speed, thus changing its direction, so that the ball that was falling down before the transition will be going upwards after the transition. Note that, as a result of the sudden change to the speed that occurs at that transition point, the acceleration will not be a welldefined notion at that instance.^{Footnote 1}
Exercise 3.3 Write out such a model in Acumen, and simulate the system starting from a height of 10 and an initial speed of 0. How well does your model work? Make a note of any unexpected behavior that your simulation might exhibit.
A finite state machine or an automata is deterministic if its behavior is always uniquely defined when it is in any given state. If this is not the case, then the system is said to be nondeterministic. Most simulation tools only simulate deterministic systems.
4 ZeroCrossing
Using precise tests (such as x = 0) for transitioning from one state to another is generally quite challenging for simulation tools built on traditional numerical methods. This is because real numbers are generally represented in computers as floating points, and functions that change over time are represented as a sequence of floating point values defined at specific points in time, represented also by floating point values. For our purposes in this book, and to keep things simple, we will try to always express our models with more robust conditions such as x ≤ 0 even though we really do not intend to model the possibility of x being less than 0.
5 Zeno Behavior
Zeno’s paradox is a phenomenon that can happen in a hybrid system (a system that exhibits both continuous and discrete dynamic behavior). The hybrid automaton model of the bouncing ball exhibits this phenomenon. In particular, the consecutive bounces form a geometric series that can be shown to end in a finite time (which we call the Zeno point), even if the number of bounces that takes place beyond that point is unbounded.
To understand what is going on here for yourself, consider the situation where the ball is at height zero but is moving up. Calculate the time (based on the initial upward speed) until it hits the ground again. What is that ratio between the speed and the time it takes to hit the ground? Now note that there is a welldefined ratio between the upward speed at the start of this problem, and the upward speed of the ball after the bounce. Convince yourself that this ratio also determines a ratio between the current jump and the next jump. Convince yourself further that this ratio will be the same between any two consecutive jumps. Write out the formula for the time at which the ball will stop jumping, giving some initial parameters.
6 Modeling Elastic Collision
Note : While this topic is discussed here only briefly, it is an important example of discontinuity in physical models (and therefore an example of why we need hybrid systems to model physical systems). Also, it is important for understanding the ping pong model.
Collisions in basic mechanics are a simple class of problems involving time. Their characteristic is that there is a discontinuity in one of the derivatives. Consider the situation in Figure 3.1, where we have two colinear masses that experience a collision where energy and momentum are conserved. How do we determine the speeds after the collision?
Let the velocity of the two balls be u _{1} and u _{2} before the collision and v _{1} and v _{2} after the collision, respectively. Conservation of momentum means that
whereas conservation of energy means that
By using (3.5) and (3.6) together we can solve for v _{1} and v _{2} in terms of u _{1} and u _{2}. The solution is
This tells us the speeds for both objects after the collision. When kinetic energy is conserved, we says that the collision is elastic, and inelastic when it is not conserved. The speed of each particle after an inelastic collision can be determined in the same way as above, but with the energy equation modified appropriately. Often, energy loss is specified in terms of a coefficient of restitution, which is the ratio between relative speeds before and after the collision.
The relative speed between two objects is the speed of the first measured from the second and vice versa. If two cars travel in the same direction at 100 and 120 km/h, respectively, the relative speed will be 20 km/h; if the two cars travel at the same speeds but at opposite directions, the relative speed will be 220 km/h.
7 Chapter Highlights

1.
Hybrid Systems

(a)
Mix continuous and discrete systems

Area of much of the research in formal analysis and verification of CPS today


(b)
Provide a natural model of cyberphysical system

(c)
Are also a more natural model of purely physical systems

Impacts and discontinuities are naturally modeled as discrete events


(d)
Cyber systems have not only discrete but also continuous aspects

Time, energy, timetofailure, radiation, relativistic effects


(a)

2.
Finite State Machines

(a)
Traffic light

(b)
States: Red, Green, and Yellow

(c)
Transitions

Untimed

Adding a timer and a reset map


(a)

3.
Thermostat Example

(a)
States: Heating, Cooling

(b)
Equations: Heat equations

(c)
Guards: Leave a gap in between

(a)

4.
Bouncing Ball Example

(a)
States: Falling, and Bouncing?

(b)
Equation: Falling

(c)
Guards: Hitting Zero (with refinement)

(d)
Zenobehavior?

(a)

5.
Computing the Zeno point for a Bouncing Ball

(a)
Equation for flight

(b)
Time in flight

(c)
Flight in terms of max height

(d)
Time in terms of coefficient

(e)
The limit of a series

(a)
8 Avoid Common Mistakes
These are remarks intended to help you avoid some common points of confusion:

A state in a finite state machine has no memory (or additional state) inside it. When you are designing or specifying a finite state machine, if it looks like you need one with “memory,” split it into multiple states.

A hybrid system is not just a finite state machine. So, for example, the preceding remark does not apply

Nondeterministic is not the same as probabilistic. Probabilistic systems require much stronger assumptions about frequency in the longer term (probabilities or probability distributions). Nondeterminism just means that you do not know exactly what the behavior will be (although you know exactly what set of behaviors is possible).

Deterministic, nondeterministic, and probabilistic models are all mathematical objects.
9 Study Problems

1.
Model the example illustrated in Figure 11 in Branicky’s paper (also mentioned below in the To Probe Further list) in Acumen. Include the following in your completed assignment: (a) your complete Acumen model, (b) the plot figure, and (c) an explanation of why Acumen cannot correctly simulate the system beyond the 4s point.

2.
Model the two systems illustrated in Figure 15 in Branicky’s paper in Acumen. Assume that f _{0}(x) = 10 − x and f _{1}(x) = 40 − x. A complete solution would include: (a) your complete Acumen model, (b) the plot figures (for both systems), and (c) an analysis in your own words of how well this simulation supports the point made in the paper about hysteresis.

3.
Consider the situation where you are designing a futuristic traffic light.

(a)
Represent each move by an output of the name of the color (“Red,” “Orange,” “Blue,” or “Green”). Draw a state machine that shows the number of states needed for a traffic light that outputs a signal that carries red, then orange, then red, and then goes to blue, then red, and repeats this process.

(b)
Assume that the light stays in the red and green states for 60 s, and in all the other states only for 10 s. Write an Acumen object class My_Light that models this functionality. The only required field in this object is a signal my_choice which can be “R,” “O,” “B,” or “G” depending on the first letter of the color. Make sure that the object is selfcontained and do not assume any inputs from the outside.

(a)

4.
Compute the Zeno point for the basic bouncing ball example when the ball is dropped from a height of 10 m, taking gravity at 9.8, and a coefficient of restitution of 90%.

5.
Consider the situation where you are designing a paper/rock/scissors player.

(a)
Represent each move by an output of the first letter (“P,” “R,” or “S”). Draw a state machine that shows the number of states needed for a simple player that repeatedly outputs a signal that carries paper, then rock, then paper, then scissors, and then repeats this sequence.
em[(b)] Assume that the machine must output each move for 0.75s. Write an Acumen object class My_PRS that models this functionality. The only required field in this object is a signal my_choice which can be “P,” “R,” or “S.” Make sure the object is selfcontained, and do not assume any inputs from the outside.

(a)

6.
Consider the situation where two cars are about to collide, and their speeds and masses are depicted in Figure 3.2.

(a)
Assume a coefficient of restitution of C. Write a formula for w _{1} and w _{2}, the speeds after impact, measured in the same direction.

(b)
If both masses are the same (m _{1} = m _{2}) and m _{2} is static (v _{2} = 0), by what fraction does the speed w _{2} increase if the speed v _{1} is increased by 10%? If the answer is not a simple fraction, you may write a formula.

(c)
If m _{1} is half the mass of m _{2} and m _{2} is static (v _{2} = 0), by what fraction does the speed w _{2} increase if the speed v _{1} is increased by 10%?

(a)

7.
Consider Figure 3.3 indicating the “before collision” (above) and “after collision” (below) speeds for a collision between two masses (represented as cars).

(a)
Write down the equation for conservation of momentum. This is the equation that relates the “before” and “after” speeds.

(b)
Calculate the coefficient of restitution “c”’in this collision.

(c)
Assume that m _{2} = 100. What is the energy lost in this collision?

(d)
Assume that m _{2} = 100. How much is m _{1}?

(a)

8.
Consider the diagram in Figure 3.4 depicting the “before” and “after” situation for a collision between two masses. The first object has mass m and the second has twice that mass. The second object is static before collision, and both objects are attached after the collision.

(a)
Calculate the coefficient of restitution c in this collision.

(b)
Write down the conservation of momentum equation relating “before” and “after” speeds.

(c)
What speed must v _{1} be in order to have v′ equal to 1000?

(d)
Assume that m = 1000. What is the energy lost in the collision of part c?

(a)

9.
Consider the diagram in Figure 3.5. This type of diagram is called a state diagram , and is widely used to express finite state machine models in an intuitive manner. According to this diagram, the initial state is S _{1} because it has an arrow that has no explicit source, possible transitions are indicated by arrows going between states (sometimes the same state), and whenever there is a transition the digit indicated on the arrow is assigned to the variable Output.

(a)
Starting from the initial state, what state is the machine in after it has assigned to Output the values 0, 0, 1, 0 in that order? Write out the state of the machine after each of these four outputs individually.

(b)
Assume that the system has an input called Input, and that both states take the 0 transition if Input is less than or equal to 5, and take the 1 transition if Input is greater than five. Assume further that the system makes a transition decisions and actions together, and does so every 1 s. Describe this situation using the Acumen language in one model that has Input and Output as parameters.

(a)
10 Lab: Discrete Bouncing
The purpose of this lab is to introduce you to hybridsystems modeling constructs and to connect the ideas discussed in this chapter to project activities.
Taking as a starting point the models you developed for the previous lab, compare and relate those models to the following model sketch:
Next, note that bouncing in the original model worked by pretending there is a spring that gets activated when the ball is below ground level. Consider the possibility of creating a model where the bounce occurs instantaneously. Build and test a model that works in this way.
Once you are done with this exercise, compare your model to the following one.
The model above has a curious feature. After the ball “reaches zero height,” it starts to slip down below level zero. That is because we are actually allowing gravity to be in effect in the case that x< = 0 and x’ > 0. This creates a cycle of small computational steps where the ball starts below the ground with a positive speed but is subjected to gravity, at the end of the cycle it has a small negative speed and has lost height, and impact condition is detected and the speed is set to positive half again, and the process repeats, but the ball is still losing height.
A better model is the following one, where we ensure that when the ball is below the ground but is on the rise it maintains this speed and is not subject to any additional forces:
Compare your model to this one as well, and make note of the points that you found required extra care to be able to model instantaneous bouncing when you tried to build it yourself. While arriving at a simple and clear model of an instantaneously bouncing ball is challenging, it is representative of the frequently occurring situations where a dynamic within a continuous domain reaches a welldefined boundary that it is being pushed against, and where the dynamic of the boundary is to push back the object into the domain.
11 Project: SpeedBased Player for Ping Pong Robot
This chapter’s project activity is to develop a ping pong player that can outperform the other player, and at the very least, the default player. In this activity, your model controls the player by sending a speed signal to move the bat. Be careful, because the larger the speed you use, the faster you will run out of energy! Basically, the default player works by computing a bat speed and predicting two key points on the future trajectory of the ball. The first point (p1) is where the ball will hit the table. This is calculated by using the velocity of the ball. The second point (p2) is the highest point in the air that the ball will reach after it bounces on the table. This is calculated from the predicted speed after bouncing. Then, the bat moves to hit the ball at the highest point (pH) of the ball after it has bounced. It is important to note that the bat loses energy (maxE) whenever it moves and hits the ball, and that each player starts with a fixed energy level. Your modified player must consume less energy than the default player and also predict the second point better than the default player. You will need to develop your own strategy to make the bat move less or improve the velocity of the bat.
If you are using this textbook as part of a course, be sure to check with your instructor about whether there is a special edition of the model you are expected to use.
An important skill that good scientists and engineers need in order to complete projects faster and better is debugging. In essence, you need this skill to determine how to go from a system that is not quite doing what you want to one that is. The key to successful debugging is to work systematically to isolate and localize problems. Scientists and engineers that solve real problems seem to apply this skill extensively. Check out this article on this topic.
Designing any interesting system also involves accumulation of a lot of knowledge. Our memory is only one way of collecting knowledge, and it often does not work as well as we think it does. Documenting the result of each of your project activities is a good way to organize the knowledge that you accumulate. Therefore, think of them not only as something you write for the instructor, but also for yourself, and review them constantly during the process. Another very powerful way of accumulating knowledge is test cases. Build your own test cases and use them to automatically test your player as you are developing it. You can develop test cases by making alternative players that play with different strategies.
In future project activities, make sure that your player avoids each of the pitfalls that you discovered during this activity. We recommend that you share the players that you have developed among yourselves, as this will help you improve player development for the next activity, and increase your chances of winning at the finals.
12 To Probe Further

Articles on Momentum and Coeflcient of Restitution.

Background on engineering, finite state machines, hybrid systems, and theory of computation.

Online hybrid systems textbook by Lygeros, Tomlin, and Sastry.

Branicky’s introduction to hybrid systems.

Very cool video by VSause about Zeno behavior and other paradoxes.
Notes
 1.
In situations like this it may be possible to use more advanced mathematical notions such as impulse functions (or Dirac delta function), but this discussion is outside the scope of this book.
Author information
Authors and Affiliations
Rights and permissions
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Copyright information
© 2021 The Author(s)
About this chapter
Cite this chapter
Taha, W.M., Taha, AE.M., Thunberg, J. (2021). Hybrid Systems. In: CyberPhysical Systems: A ModelBased Approach. Springer, Cham. https://doi.org/10.1007/9783030360719_3
Download citation
DOI: https://doi.org/10.1007/9783030360719_3
Published:
Publisher Name: Springer, Cham
Print ISBN: 9783030360702
Online ISBN: 9783030360719
eBook Packages: Computer ScienceComputer Science (R0)