discrete control - real-time systems, lecture 14 · discrete control real ... system: chapter 12]...
TRANSCRIPT
![Page 1: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/1.jpg)
Discrete Control
Real-Time Systems, Lecture 14
Karl-Erik Arzen
2 March 2017
Lund University, Department of Automatic Control
![Page 2: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/2.jpg)
Content
[Real-Time Control System: Chapter 12]
1. Discrete Event Systems
2. State Machine Formalisms
3. Statecharts
4. Grafcet
5. Petri Nets
6. Implementation
1
![Page 3: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/3.jpg)
Discrete Event Systems
![Page 4: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/4.jpg)
Discrete Event Systems
A Discrete Event System (DES) is a discrete-state, event-driven system,
that is its state evolution depends entirely on the occurrence of
asynchronous discrete events over time.
Sometimes Discrete Event Dynamic Systems (DEDS) is used to
emphasize the dynamic nature of a DES.
2
![Page 5: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/5.jpg)
Discrete Event Systems
Discrete Event Systems:
• The state space is a discrete set.
• The state transition mechanism is event-driven.
• The events need not to be synchronized by, e.g., a clock.
Continuous Systems:
• Continuous-state systems (real-valued variables)
• The state-transition mechanism is time-driven.
Continuous discrete-time systems x(k + 1) = Ax(k) + Bu(k) can be
viewed as an event-driven system synchronized by clock events.
3
![Page 6: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/6.jpg)
Continuous Systems
State trajectory is the solution of a differential equation
x(t) = f (x(t), u(t), t)
x(t)
t
X = R
4
![Page 7: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/7.jpg)
Discrete Event System
State trajectory (sample path) is piecewise constant function that jumps
from one value to another when an event occurs.
x(t)
t
X = (s1, s2, s3, s4, s5, s6)
s1
s2
s3
s4
s5
s6
t1 t2 t3 t4 t5 t6 t7
e1 e2 e3 e4e5 e6 e7 5
![Page 8: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/8.jpg)
Discrete Control Systems
All processes contain discrete elements:
• continuous processes with discrete sensors and/or actuators;
• discrete processes:
• manufacturing lines, elevators, traffic systems;
• mode changes:
• manual/auto, startup/shutdown,
• production (grade) changes;
• alarm and event handling.
6
![Page 9: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/9.jpg)
Discrete Logic
• Larger in volume than continuous control;
• Very little theoretical support:
• verification, synthesis;
• formal methods beginning to emerge;
• still not widespread in industry.
7
![Page 10: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/10.jpg)
Basic Elements
• Boolean (binary) signals – 0, 1,
false, true, a, a
• Expressionsa
a or b (a + b)
a and b (a b)
Boolean algebra
Truth valuesTruth value tables
• Events
a
^a
a
8
![Page 11: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/11.jpg)
Logic Nets
• Combinatorial nets
• outputs = f(inputs)
• interlocks, ”forreglingar”
• Sequence nets
• newstate = f(state,inputs)
• outputs = g(state,inputs)
• state machines
• automata
Asynchronous nets or synchronous (clocked) nets
Logic net
Inputs Outputs
New stateState
Delay
9
![Page 12: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/12.jpg)
State Machine Formalisms
![Page 13: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/13.jpg)
State Machine
Formal properties ⇒ analysis possible in certain cases
Using state machines is often a good way to structure code.
Systematic ways to write automata code often not taught in
programming courses.
10
![Page 14: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/14.jpg)
Moore Machine
State−0 State−1
State−2
Out−a
Out−c
In−a
In−a
In−b
In−c
In−b
In−a
Out−b
State transitions in response to input events
Output events (actions) associated with states
11
![Page 15: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/15.jpg)
Mealy Machine
State−0 State−1
State−2
Out−a
In−b
In−a
Out−b
In−c
Out−c
In−b
Out−a
In−a
Out−b
In−c
Out−c
Output events (actions) associated with input events
12
![Page 16: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/16.jpg)
State Machine Extensions
Ordinary state machines lack structure so extensions are needed to make
them practically useful:
• hierarchy;
• concurrency;
• history (memory).
13
![Page 17: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/17.jpg)
Statecharts
![Page 18: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/18.jpg)
Statecharts
D. Harel, 1987: Statecharts are state machines with hierarchy,
concurrency and history.
XOR superstates
D
A
C
B
c (P)
a / e
b
d
XOR Superstate
Input event
Output event
State
Condition"guard"
14
![Page 19: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/19.jpg)
Statecharts
AND superstates
Y
A D
B
C
E
G
Fa b (in G)
c
d
a
g
Y is the orthogonal product of A and D
When in state (B,F) and event a occurs, the system transfers
simultaneously to (C,G).
15
![Page 20: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/20.jpg)
Statecharts
History states
Alarm
Off
On
d d
H
a
On event ‘a’ the last visited state within D becomes active.
16
![Page 21: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/21.jpg)
Statecharts
Interfaces for AND and superstates
A D
B
C
E
G
F
JH
K L
H
ν δ η(in B)
ǫβθαω
17
![Page 22: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/22.jpg)
Statecharts
• δ exit from J ⇒ (B,E )
• α exit from K ⇒ (C ,F )
• ν exit from J ⇒ (B,F )
• β exit from L ⇒ (C ,most recently visited state in D)
• ω exit from (B,G) ⇒ K
• η exit from (B,F ) ⇒ H
• θ exit from (C ,D) ⇒ K
• ǫ exit from (A,D) ⇒ L
18
![Page 23: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/23.jpg)
Statecharts tools
Statecharts popular for modeling, simulation, and code generation. Used
to represent state-transition diagrams in UML tools (Rational/Rose,
Rhapsody). Stateflow for Matlab/Simulink.
19
![Page 24: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/24.jpg)
Statecharts semantics
Unfortunately, Harel only gave an informal definition of the semantics. As
a results a number of competing semantics were defined.
In 1996, Harel presented his semantics (the Statemate semantics) of
Statechart and compared with 11 other semantics.
The lack of a single semantics is still the major problem with Statecharts.
Each tool vendor defines his own.
20
![Page 25: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/25.jpg)
Grafcet
![Page 26: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/26.jpg)
Grafcet
Extended state machine formalism for implementation of sequence
control.
Industrial name: Sequential Function Charts (SFC).
Defined in France in 1977 as a formal specification and realization
method for logical controllers.
Part of IEC 61131-3 (industry standard for PLC controllers).
21
![Page 27: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/27.jpg)
Basic Elements
• Steps: active or inactive
S1
S1.x = 1 when active
S1.T = number of time units since the step last became active
Initial step
• Transitions (”overgang”)
condition true and/or event occurred +previous step active
22
![Page 28: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/28.jpg)
Basic Elements
• Alternative paths: branch
a a
mutually exclusive
• Alternative paths: repetition
23
![Page 29: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/29.jpg)
Basic Elements
• Parallel paths:
join (synchronization)
split
24
![Page 30: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/30.jpg)
Basic Elements
Legal GrafcetIllegal Grafcet
25
![Page 31: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/31.jpg)
Semantics
1. The initial step(s) is active when the function chart is initiated.
2. A transition is fireable if:
• all steps preceding the the transition are active (enabled);
• the receptivity (transition condition and/or event) of the transition is
true.
A fireable transition must be fired.
3. All the steps preceding the transition are deactivated and all the
steps following the transition are activated when a transition is fired.
4. All fireable transitions are fired simultaneously.
5. When a step must be both deactivated and activated it remains
activated without interrupt.
26
![Page 32: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/32.jpg)
Semantics
a = 1 or 0 a = 0
a = 1
a) Not enabled b) Enabled but not firable
c) Firable d) After the change from c)
27
![Page 33: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/33.jpg)
Semantics
Unreachable grafcet
28
![Page 34: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/34.jpg)
Semantics
Unreachable grafcet
29
![Page 35: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/35.jpg)
Semantics
Unreachable grafcet
30
![Page 36: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/36.jpg)
Semantics
Unreachable grafcet
31
![Page 37: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/37.jpg)
Semantics
Unsafe grafcet
32
![Page 38: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/38.jpg)
Semantics
Unsafe grafcet
33
![Page 39: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/39.jpg)
Semantics
Unsafe grafcet
34
![Page 40: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/40.jpg)
Semantics
Unsafe grafcet
35
![Page 41: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/41.jpg)
Semantics
Unsafe grafcet
?
36
![Page 42: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/42.jpg)
Actions
Action block
Action types:
• Standard Action (Level Action)
S1V
S1
V
S1V
V
V
S1
S2S2
37
![Page 43: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/43.jpg)
Actions
Action types:
• Stored Action (Impulse Action, local assignment)
S1
S2
1 Unstable situation (stored actions performed)
S V = 1
S V = 0
38
![Page 44: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/44.jpg)
Summary
S1
t
V Standard
action
S1
t
V
Conditional
actionS1
t
condition
S1
cond.
t
V
S1
S2
t1
t2
S1
t1
V
S2
t2
Stored
action
C V
S V = 1
S V = 0
39
![Page 45: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/45.jpg)
Summary
S1
t
S1
t
V
S1
t
S1
t
V
Time−limitedaction L V 8 s.
8
Time−delayedaction
D V 5s.
5
40
![Page 46: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/46.jpg)
Grafcet: macro steps
Hierarchy and macro steps
S1
S2
S3
S21
S22
S23
41
![Page 47: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/47.jpg)
Grafcet: editors
A large number of graphical IEC 1131-3 editors are available. Generates
PLC code or C-code.
42
![Page 48: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/48.jpg)
Laboratory 2
Sequential Control: bead sorter process
JGrafchart - Lund University
• Grafcet/SFC graphical editor
• Grafcet/SFC run-time system
43
![Page 49: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/49.jpg)
Jgraphchart
44
![Page 50: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/50.jpg)
Process
Solenoid 1 Solenoid 2
Solenoid 3
Solenoid 4
ColourSensor
BeadSensor
SORTER
Black bead compartment Yellow bead compartment
45
![Page 51: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/51.jpg)
Petri Nets
![Page 52: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/52.jpg)
Petri Nets
C.A Petri, TU Darmstadt, 1962.
A mathematical and graphical modeling method.
Describe systems that are:
• concurrent,
• asynchronous or synchronous,
• distributed,
• nondeterministic or deterministic.
46
![Page 53: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/53.jpg)
Petri Nets
Can be used at all stages of system development:
• modeling,
• analysis,
• simulation/visualization (“playing the token game”),
• synthesis,
• implementation (Grafcet).
47
![Page 54: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/54.jpg)
Petri Nets
Application areas:
• communication protocols,
• distributed systems,
• distributed database systems,
• flexible manufacturing systems,
• logical controller design,
• multiprocessor memory systems,
• dataflow computing systems,
• fault tolerant systems.
48
![Page 55: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/55.jpg)
Petri Nets
A Petri net is a directed bipartite graph consisting of places P and
transitions T .
Places are represented by circles.
Transitions are represented by bars (or rectangles).
Places and transitions are connected by arcs.
In a marked Petri net each place contains a cardinal (zero or positive
integer) number of tokens of marks.
49
![Page 56: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/56.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
50
![Page 57: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/57.jpg)
Petri Nets: Firing Rules
1. A transition t is enabled if each input place contains at least one
token.
2. An enabled transition may or may not fire.
3. Firing an enabled transition t means removing one token from each
input place of t and adding one token to each output place of t.
The firing of a transition has zero duration.
The firing of a sink transition (only input places) only consumes tokens.
The firing of a source transition (only output places) only produces
tokens.
51
![Page 58: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/58.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
52
![Page 59: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/59.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
53
![Page 60: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/60.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
54
![Page 61: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/61.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
55
![Page 62: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/62.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
56
![Page 63: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/63.jpg)
Petri Nets
P1
P2
P3 P4
P5 P6
P7
T1
T2
T3 T4
T5
T6
57
![Page 64: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/64.jpg)
Petri Nets
Typical interpretations of places and transitions:
Input Places Transition
Preconditions
Input data
Input signals
Resources needed
Conditions
Buffers
Event
Computation step
Signal processor
Task or job
Clause in logic
Processor
Output Places
Postconditions
Output data
Output signals
Resources needed
Conclusions
Buffers
58
![Page 65: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/65.jpg)
Generalized Petri Nets
2
2
P1 P2
P3
T1
Firing rules:
1. A transition t is enabled if each input place p of t contains at least
w(p,t) tokens
2. Firing a transition t means removing w(p,t) tokens from each input
place p and adding w(t,q) tokens to each output place q.
59
![Page 66: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/66.jpg)
Generalized Petri Nets
2
2
P1 P2
P3
T1
Firing rules:
1. A transition t is enabled if each input place p of t contains at least
w(p,t) tokens
2. Firing a transition t means removing w(p,t) tokens from each input
place p and adding w(t,q) tokens to each output place q.
60
![Page 67: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/67.jpg)
Petri Net Variants
Timed Petri Nets:
Times associated with transitions or places.
High-Level Petri Nets:
Tokens are structured data types (objects).
Continuous & Hybrid Petri Nets:
The markings are real numbers instead of integers.
Mixed continuous/discrete systems.
61
![Page 68: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/68.jpg)
Petri Nets: Analysis
• Live: No transitions can become unfireable.
• Deadlock-free: Transitions can always be fired.
• Bounded: Finite number of tokens.
62
![Page 69: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/69.jpg)
Petri Nets: Analysis methods
Analysis methods:
• Reachability methods:
• exhaustive enumeration of all possible markings.
• Linear algebra methods:
• describe the dynamic behaviour as matrix equations.
• Reduction methods:
• transformation rules that reduce the net to a simpler net while
preserving the properties of interest.
63
![Page 70: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/70.jpg)
Petri Nets: The classical real-time problems
Dijkstra’s classical problems:
• mutual exclusion problem,
• producer-consumer problem,
• readers-writers problem,
• dining philosophers problem.
All can be modeled by Petri Nets.
64
![Page 71: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/71.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
65
![Page 72: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/72.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
66
![Page 73: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/73.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
67
![Page 74: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/74.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
68
![Page 75: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/75.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
69
![Page 76: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/76.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
70
![Page 77: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/77.jpg)
Petri Nets: Mutual Exclusion
Waiting forcritical section
Waiting forcritical section
Executinginsidecriticalsection
Executinginsidecriticalsection
Executingoutsidecriticalsection
Executingoutsidecriticalsection
Process A Process B
Mutexsemaphore
71
![Page 78: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/78.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
72
![Page 79: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/79.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
73
![Page 80: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/80.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
74
![Page 81: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/81.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
75
![Page 82: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/82.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
76
![Page 83: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/83.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
77
![Page 84: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/84.jpg)
Petri Nets: Producer Consumer
Producer processes
Consumerprocesses
BufferRead
Write
78
![Page 85: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/85.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
79
![Page 86: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/86.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
80
![Page 87: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/87.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
81
![Page 88: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/88.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
82
![Page 89: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/89.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
83
![Page 90: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/90.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
84
![Page 91: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/91.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
85
![Page 92: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/92.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
86
![Page 93: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/93.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
87
![Page 94: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/94.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
88
![Page 95: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/95.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
89
![Page 96: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/96.jpg)
Petri Nets: Producer Consumer with Bounded Buffer
Producer processes
Consumerprocesses
Buffer
Read
Write
Freeplaces
Fullplaces
90
![Page 97: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/97.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
91
![Page 98: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/98.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
92
![Page 99: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/99.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
93
![Page 100: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/100.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
94
![Page 101: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/101.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
95
![Page 102: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/102.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
96
![Page 103: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/103.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
97
![Page 104: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/104.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
98
![Page 105: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/105.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
99
![Page 106: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/106.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
100
![Page 107: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/107.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
101
![Page 108: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/108.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
102
![Page 109: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/109.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
103
![Page 110: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/110.jpg)
Petri Nets: Reader and Writer
AccessControl
Ready to write
WritingReading
Readyto read
3
3
Writers processes Readers processes
104
![Page 111: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/111.jpg)
Petri Nets: Dining Philosopers
105
![Page 112: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/112.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 106
![Page 113: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/113.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 107
![Page 114: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/114.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 108
![Page 115: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/115.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 109
![Page 116: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/116.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 110
![Page 117: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/117.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 111
![Page 118: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/118.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 112
![Page 119: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/119.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 113
![Page 120: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/120.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 114
![Page 121: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/121.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 115
![Page 122: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/122.jpg)
Petri Nets: Dining Philosopers
Thinks
Picksleft fork
Picks right fork
Eats
Dropsleft fork
Dropsright fork
Fork
Fork
Philosopher 116
![Page 123: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/123.jpg)
Petri Nets: Dining Philosopers
Thinks
Eats
Leftfork
Right fork
117
![Page 124: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/124.jpg)
Implementation
![Page 125: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/125.jpg)
Implementation (Not covered in the lecture – Homework)
Using state machines is often a good way to structure code.
Systematic ways to write automata code often not taught in
programming courses.
Issues:
• active or passive object
• Mealy vs Moore machines
• states with timeout events
• states with periodic activities
Often convenient to implement state machines as periodic processes with
a period that is determined by the shortest time required when making a
state transition.
118
![Page 126: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/126.jpg)
Example: Passive State Machine
The state machine is implemented as a synchronized object.
1 public class PassiveMealyMachine {
2 private static final int STATE0 = 0;
3 private static final int STATE1 = 1;
4 private static final int STATE2 = 2;
5 private static final int INA = 0;
6 private static final int INB = 1;
7 private static final int INC = 2;
8 private static final int OUTA = 0;
9 private static final int OUTB = 1;
10 private static final int OUTC = 2;
11 private int state;
12 PassiveMealyMachine() {
13 state = STATE0;
14 }
15 private void generateEvent(int outEvent) {
16 // Do something
17 }
119
![Page 127: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/127.jpg)
Example: Passive State Machine
1 public synchronized void inputEvent(int event) {
2 switch (state) {
3 case STATE0 : switch (event) {
4 case INA : generateEvent(OUTA); state = STATE1; break;
5 case INB : generateEvent(OUTB); break;
6 default : break;
7 }; break;
8 case STATE1 : switch (event) {
9 case INC : generateEvent(OUTC); state = STATE2; break;
10 default : break;
11 }; break;
12 case STATE2 : switch (event) {
13 case INA : generateEvent(OUTB); state = STATE0; break;
14 case INC : generateEvent(OUTC); break;
15 default : break;
16 }; break;
17 }
18 }
19 }
120
![Page 128: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/128.jpg)
Example: Active State Machine
The state machine could also be implemented as an active object (thread)
The thread object would typically contain an event-buffer (e.g., an
RTEventBuffer).
The run method would consist of an infinite loop that waits for an
incoming event (RTEvent) and switches state depending on the event.
121
![Page 129: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/129.jpg)
Example: Active State Machine
An activity is an action that is executed periodically while a state is
active.
More natural to implement the state machine as a thread.
122
![Page 130: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/130.jpg)
Example: Active State Machine 1
1 public class ActiveMachine1 extends Thread {
2 private static final int STATE0 = 0;
3 private static final int STATE1 = 1;
4 private static final int STATE2 = 2;
5 private int state;
6
7 ActiveMachine1() { state = STATE0; }
8
9 private boolean cond0() {
10 // Returns true if condition 0 is true
11 }
12 private boolean cond1() { }
13 private boolean cond2() { }
14
15 private void action0() {
16 // Executes action 0
17 }
18 private void action1() { }
19 private void action2() { }
123
![Page 131: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/131.jpg)
Example: Active State Machine 1
1 public void run() {
2 long t = System.currentTimeMillis();
3 long duration;
4
5 while (true) {
6 switch (state) {
7 case STATE0 : {
8 action0(); t = t + 20;
9 duration = t - System.currentTimeMillis();
10 if (duration > 0) {
11 try { sleep(duration);
12 } catch (InterruptedException e) {}
13 }
14 if (cond0()) { state = STATE1; }
15 } break;
16 case STATE1 : {
17 // Similar as for STATE0. Executes action1,
18 // waits for 50 ms, checks
19 // cond1 and then changes to STATE2
20 }; break;
124
![Page 132: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/132.jpg)
Example: Active State Machine 1
1 case STATE2 : {
2 // Similar as for STATE0. Executes action2,
3 // waits for 10 ms, checks
4 // cond2 and then changes to STATE0
5 }; break;
6 } } } }
• Conditions tested at a frequency determined by the activity
frequencies of the different states.
• sleep() spread out in the code.
125
![Page 133: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/133.jpg)
Example: Active State Machine 2
The thread runs at a constant (high) base frequency. Activity frequencies
multiples of the base frequency. Conditions tested at the base frequency.
1 public void run() {
2 long t = System.currentTimeMillis();
3 long duration;
4 int counter = 0;
5 while (true) {
6 counter++;
7 switch (state) {
8 case STATE0 : {
9 if (counter == 4) { counter = 0; action0(); }
10 if (cond0()) { counter = 0; state = STATE1; }
11 }; break;
12 case STATE1 : {
13 // Similar as for STATE0. Executes action1
14 // if counter == 10. Changes to STATE2 if
15 // cond1() is true
16 }; break;
126
![Page 134: Discrete Control - Real-Time Systems, Lecture 14 · Discrete Control Real ... System: Chapter 12] 1. Discrete Event Systems 2. ... mechanism is time-driven. Continuous discrete-time](https://reader031.vdocuments.site/reader031/viewer/2022020303/5b1497697f8b9a3e7c8daf88/html5/thumbnails/134.jpg)
Example: Active State Machine 2
1 case STATE2 : {
2 // Similar as for STATE0. Executes action2
3 // if counter == 12. Changes to STATE0 if
4 // cond2() is true
5 }; break;
6 }
7 t = t + 5; // Base sampling time
8 duration = t - System.currentTimeMillis();
9 if (duration > 0) {
10 try { sleep(duration);
11 } catch (InterruptedException e) {}
12 } } }
• Polled time handling.
• Complicated handling of counter.
• Conditions tested at a high rate.
127