Engee documentation
Notebook

Development of algorithmic embed code for air conditioner 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 this example we take a simplified model of an air conditioner control system.

image_2.png

Principle of operation

This model simulates the control of the air temperature in a room through the operation of an air conditioner. The example is simplified but sufficiently illustrative. The AddTemperature block simulates room temperature fluctuations; in this example the fluctuation is a sine wave. This block also adds an air conditioner influence factor to the temperature value.

The air conditioner (AirCooler), in turn, is an algorithm that gives a positive or negative temperature gain coefficient depending on whether the desired room temperature is higher or lower. In case of no power supply, it has no effect on the room temperature. The figures below show the algorithm logic implemented inside these units.

*AddTemperature

addtemperature.jpg

  • AirCooler *

airconditioner.jpg

Realisation of the model run and work with recorded data

Loading and running 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 simulation data is loaded and visualised 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 simulation we see that the air conditioning system successfully maintains the temperature in the room within 25 degrees.

Generating C code from the model

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

Let's look at the syntax of the command: the first argument specifies the model location path, the second argument specifies the path to save the generated code, the third argument specifies 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

At the end of the generation we can view the generated code in the AirCooler folder.

image_2.png

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

Conclusion

We have developed a simple logic block based air conditioner control system. As we can see from the simulation results, it copes well with the task of maintaining room temperature. Based on the code generation results, we obtained a readable and portable code that can be used for porting to real hardware such as embedded processors or microcontrollers.