Engee documentation
Notebook

User buses in finite automata

This project demonstrates the possibility of using custom buses in the Chart block.

Custom buses - structured signals of the type BusSignal. This type allows you to combine logically related signals into a single structure, a bus, each element of which corresponds to a specific name, data type, and dimension.

Using a macro @__DIR__ to define a path containing an interactive script:

In [ ]:
demoroot = @__DIR__;

Description of the model

Let's consider a simple model with a finite state machine implementing block logic Saturation limiting the input signal from above and below:

#[PIPE]
[PIPE][PIPE]

Input signal

[PIPE]

Output signal

[PIPE][PIPE]
[PIPE][PIPE]

Lower limit <= Input signal <= Upper limit

[PIPE]

The input signal

[PIPE][PIPE]
[PIPE][PIPE]

Input signal < Lower limit

[PIPE]

Lower limit

[PIPE][PIPE]
[PIPE][PIPE]

Input signal > Upper limit

[PIPE]

Upper limit

[PIPE][PIPE]
[PIPE]#

Let the user bus be sent to the input of the Chart block InputBus containing the signals:

  • signal the type of data Float64 - input signal;
  • limits the type of data LimitBus (embedded bus):
    • upper the type of data Float64 - upper limit;
    • lower the type of data Float64 - the lower limit.

And at the output of the Chart block, a custom bus is formed. OutputBus containing the signals:

  • signal the type of data Float64 - output signal;
  • is_saturated the type of data Bool - a sign of saturation.
buses_chart--1790945236851.png

Define custom buses in the workspace:

In [ ]:
LimitBus = BusSignal((:upper, :lower), (Float64, Float64), ((), ()), :LimitBus);
InputBus = BusSignal((:signal, :limits), (Float64, LimitBus), ((), ()), :InputBus);
OutputBus = BusSignal((:signal, :is_saturated), (Float64, Bool), ((), ()), :OutputBus);

And specify the correct data types in the Bus Creator block settings (LimitBus and InputBus) and Bus Selector (OutputBus):

image.png

Let's go to the Chart block and create the input and output signals in the model data editor (on the "Finite Automata" tab).:

image.png

We will set the data types using custom buses as follows:

image.png

We will represent the block logic in the form of a transition graph.:

buses_chart--1790945920417.png

To access the bus elements inside the Chart block, a dot entry is used, for example:

  • InputBus.signal > InputBus.limits.upper
  • OutputBus.is_saturated = true

Running the simulation

Loading the model buses_chart.engee:

In [ ]:
buses_chart_model = engee.load("$demoroot/buses_chart.engee");

And let's run her simulation.:

In [ ]:
simulation_results = engee.run(buses_chart_model);

We will close the model after the end of the simulation:

In [ ]:
engee.close(buses_chart_model, force = true);

Simulation results

Importing the simulation results:

In [ ]:
buses_chart_model_signal_t = simulation_results["signal"].time;
buses_chart_model_signal_y = simulation_results["signal"].value;
In [ ]:
buses_chart_model_is_saturated_t = simulation_results["is_saturated"].time;
buses_chart_model_is_saturated_y = simulation_results["is_saturated"].value;

And let's build graphs:

In [ ]:
plot(buses_chart_model_signal_t, buses_chart_model_signal_y, label = "Output signal")
plot!(buses_chart_model_is_saturated_t, buses_chart_model_is_saturated_y, label = "A sign of saturation")
Out[0]:

Conclusions

This project demonstrates the use of custom buses in the development of models based on the Finite Automata library:

  • Tire declaration in the workspace;
  • Setting up the characters of the Chart block;
  • Accessing user buses in the state machine.