You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-2
Original file line number
Diff line number
Diff line change
@@ -93,14 +93,44 @@ type AwaitEvent = enum
93
93
-[References](#references)
94
94
95
95
## Commented example: Water phases
96
+
97
+
The example below gives you a short overview of how to build your state machine.
98
+
99
+
Recipe:
100
+
- A state enum (called `Phase` in the example)
101
+
- An event/trigger/condition enum (called `Event`)
102
+
- Declaring a state machine
103
+
- Declaring prologue, epilogue, initial state, terminal state. SOme are optional
104
+
- Implement your events. Those are boolean tests.
105
+
Events have visibility on variables declared
106
+
- in the prologue
107
+
- in `onEntry`
108
+
- and the synthesized function parameters (here `tempFeed`).
109
+
```Nim
110
+
synthesize(waterMachine):
111
+
proc observeWater(tempFeed: var seq[float])
112
+
```
113
+
- Implement common setup and teardown on state entry and exit if needed
114
+
- Describe behaviours (i.e. state to state transition):
115
+
- Transition without condition
116
+
- Conditional transition due to an event
117
+
- "Interrupt" which is a conditional transition that shortcuts regular control flow
118
+
and allow handling exceptional cases, for example reaching the end of the `tempFeed` sequence.
119
+
- Synthesize the state machine
120
+
- Run it
121
+
- ...
122
+
- Profit!
123
+
96
124
```Nim
97
125
type Phase = enum
98
126
## States of your automaton.
99
127
## The terminal state does not need to be defined
100
128
Solid
101
129
Liquid
102
130
Gas
103
-
Plasma # Plasma is almost unused
131
+
# Plasma is unused. On the graph display, it will not be reachable from the InitialState.
132
+
# The graph will also show that transitions out of the Plasma state are undefined via an `unreachable` transition.
133
+
Plasma
104
134
105
135
type Event = enum
106
136
## Named events. They will be associated with a boolean expression.
@@ -283,7 +313,8 @@ Output of the waterMachine
283
313
284
314

285
315
286
-
Alternative to Graphviz can be used on the `.dot` files if the output is unsatisfactory. Remember that graph node placement is usually an NP-complete task and requires heuristics to be solved that may not be optimal for your specific graph. In that case consider splitting your finite state machine hence building hierarchical state machines.
316
+
Alternatives to Graphviz can be used on the `.dot` files if the output is unsatisfactory. Remember that graph node placement is usually an NP-complete task and requires heuristics to be solved that may not be optimal for your specific graph.
317
+
In that case consider splitting your finite state machine hence building hierarchical state machines.
0 commit comments