Working with data in finite automata
|
Page in progress. |
An Engee finite state machine is an independent entity that controls logic, transitions, and states, but is isolated from the usual one. block libraries Engee
and, as a result, the possibilities of building classical models.
In order for the state machine to exchange data with external blocks, block data is used. Chart and its corresponding ports. For example:
-
When creating output data, an output port appears automatically in the Chart block, which can be connected to other elements of the model.
-
Similarly, when creating input data, an input port appears for receiving information from the outside.
-
Local data exists only inside the state machine (inside the Chart block) and does not create ports.
Consequently, data acts as a connecting interface between the finite automaton and the rest of the model: without them, the automaton model remains a separate entity, but with them it becomes a full-fledged part of the system.
To work with finite state machine data in Engee, the window "Signals" — it allows you to centrally manage all the data of the finite state machine model. With its help, they are combined:

-
List of all state machine data;
-
Data categories (input, output, parameter);
-
Settings for data types, dimensions, and complexity.
The one-window approach for all state machine data simplifies debugging and makes the model more transparent: all definitions are concentrated in one place, rather than scattered around states
and transitions
.
Data categories
In the window "Signals" the following data categories are supported:

-
Input — data entering the state machine from an external model.
-
Output — data that the state machine exports to the outside.
-
Local — data available only inside the state machine (inside the Chart block). They are used to store intermediate calculations and control the logic of states and transitions.
-
Parameter Data — fixed values (parametric data) that are copied from the workspace variable of the same name when the simulation is started and does not change during the simulation.
|
Data from the Chart block is not displayed in variable window For example, if a Parameter is set in Chart with the name If you assign a value to a variable
|
Creating data
To create new data:
-
Open the window "Signals»;
-
Click the button
; -
Enter the name and characteristics of the data in the window that opens, then click "Add»:

Data names in the window "Signals" must match the names of these data in the finite state machine model.
The Symbol Assistant
When running the simulation
or compilations
Engee verifies the correctness of the finite state machine model. If there is undefined data in it, then it opens "Symbol Wizard". In it you can:
-
View the found undefined names;
-
Assign a category to them (for example, "Exit");
-
Confirm the addition to the list of Signals.

Setting data types
Each data type must be specified. This determines how it will be stored and used during the simulation. Types consistent with the Julia language type system are supported.:
-
Inherit: auto— data type inheritance; -
Int8,Int16,Int32,Int64,Int128— signed integers; -
UInt8,UInt16,UInt32,UInt64,UInt128— unsigned integers; -
Float16,Float32,Float64— floating point numbers; -
Bool— logical type; -
Fixed-point— fixed point (to optimize calculations).
Let’s say in the panel "Signals" the Chart block you have created the output data , , , . Then inside the state you can write like this:
# The code executed during the active state (entry / during / exit)
s = [1, 2, 3, 4, 5] # vector of length 5
a = [1, 2, 3, 4, 5, 6, 7] # vector of length 7
# Assigning parts of arrays to output ports
q = s[1:4] # q == [1, 2, 3, 4]
w = a[1:4] # w == [1, 2, 3, 4]
# Two-dimensional output (2×3)
M = reshape(collect(1:6), 2, 3) # the 2×3 matrix
# If desired, you can specify the type:
# M = Float32.(reshape(collect(1:6), 2, 3))
If you want to create a matrix of a given type/size without initialization, then use explicit array creation.:
B = Array{Float64,2}(undef, 3, 3) # 3×3 matrix with uninitialized values (arbitrary memory contents)
# Before using it, be sure to assign values, for example:
B .= 0.0
# Or create an initialized array immediately.:
# B = zeros(Float64, 3, 3)
# B = fill(1.0, 3, 3)
undef does not fill the array with zeros. The contents depend on the previously used memory, so such an array must be initialized before reading its elements.
|
The result is the following model of a finite state machine:
-
Inside the Chart block:

-
The Engee model (outside the Chart block):

Dimension and complexity
In addition to the data type, you can set the dimension (scalar, vector, or array) and complexity.
-
Dimension — is indicated in the window "Signals" as a sequence of integers separated by commas:
-
-1(default value) — the dimension is not fixed and is determined automatically.:-
For input/output, it is taken from the connected port of the external model;
-
For the parameter, it is taken from the workspace variable of the same name (workspace, outside Chart);
-
For local data, it is taken from the values actually assigned in the chart code.
This mode is convenient if the shape can change.
-
-
The explicit form is to enter numbers separated by commas.:
-
n— a vector fromnelements; -
n, m— the matrixn×m; -
n, m, k— three-dimensional arrayn×m×k.Sequence
n[, m[, k…]]in the Dimension field, it corresponds to the numeric arguments of the Julia array constructors. For example,n, m→Matrix{Float32}(undef, n, m)(=Array{Float32,2}(undef, n, m)).
-
-
-
Complexity — determines whether the data can contain complex values.:
-
Inherit: auto — the value is inherited automatically from the associated variable or signal in the external model. For example, if a complex type is used in the workspace or in the input block, then the data in the state machine will be complex.
-
Off — inheritance is disabled, the data is always valid.
-
On — inheritance is disabled, data is always complex.
-
Recommendations for use
-
Use "Input" and "Output" to connect a finite state machine to an external model.
-
Explicitly specify the data type. This increases the predictability of the state machine and helps avoid errors.
-
Apply "Parameter Data" for constants and coefficients to make the model more readable.
-
When working with complex numbers, enable the "Complexity": enabled.

