Engee documentation
Notebook

Development of algorithmic embedded code for air conditioning control system

This example is aimed at demonstrating the capabilities of Engee in the field of algorithmic software development and code generation from models. For example, a simplified model of the air conditioner control system is taken.

image_2.png

The principle of operation

This model simulates the control of the air temperature in the room due to the operation of the air conditioner. The example is simplified, but clear enough. The AddTemperature block simulates room temperature fluctuations; in this example, the fluctuations are set by a sine wave. This unit also adds the coefficient of influence of the air conditioner to the temperature value.

The air conditioner (AirCooler), in turn, is an algorithm that, depending on whether the desired temperature in the room is higher or lower, gives a positive or negative temperature increase coefficient. If there is no power supply, it does not affect the temperature in the room. The figures below show the logic of the algorithm implemented inside these blocks.

AddTemperature

AddTemperature.jpg

AirCooler

AirConditioner.jpg

Implementing the model launch and working with the recorded data

Loading and launching the model:

In [ ]:
Pkg.add(["CSV"])
In [ ]:
modelName = "conditioner_demo";
model = modelName in [m.name for m in engee.get_all_models()] ? model = engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");
engee.run();

The data obtained during the simulation is downloaded and visualized by reading csv files with room temperature readings.

In [ ]:
using CSV, DataFrames
t = Matrix(CSV.read("$(@__DIR__)/temperature.csv", DataFrame)); #загрузка данных

using Plots # Подключение библиотеки для построение графиков
plotly() # Подключение бэкэнда - метода отображения графики
plot(t[:,1], t[:,2], xlabel="Время в минутах", ylabel="температура", title="Изменение температуры в комнате") # Построение графика
[ Info: Precompiling PlotlyKaleido [f2990250-8cf9-495f-b13a-cce12b45703c]
Out[0]:

According to the results of the model, we can see that the air conditioning system successfully maintains the temperature in the room within 25 degrees.

Generating With code from a model

There are two ways to generate code: using the engee.model.generate_code command, or using the Engee GUI. Next, let's look at both options.

Consider the syntax of the command: the first argument indicates the location path of the model, the second argument indicates the path to save the generated code, and the third argument indicates the subsystem in the model from which the code is generated.

In [ ]:
if isdir("$(@__DIR__)/AirCooler") # Проверка наличия папки
    rm("$(@__DIR__)/AirCooler";force = true, recursive = true) # Удаление папки
end

engee.generate_code("$(@__DIR__)/conditioner_demo.engee", "$(@__DIR__)/AirCooler", subsystem_name="AirCooler")
[ Info: Generated code and artifacts: /user/start/examples/controls/Conditioner/AirCooler

Based on the results of the generation, we can view the generated code in the AirCooler folder.

image_2.png

The figure above shows a way to generate code using the Engee GUI. The result of the generation is presented in the demo_C_gen_AirCooler_code folder

Conclusion

We have developed a simple air conditioning control system based on logic blocks. As can be seen from the simulation results, it copes well with the task of maintaining room temperature. Based on the results of code generation, we have received readable and portable code that can be used to transfer to real hardware, for example, embedded processors or microcontrollers.