Engee documentation
Notebook

Electric car window lift

In this example we will describe how to describe the logic of the power window lifter using the Chart block of the finite automata library.


Operating logic for raising and lowering the window

Create a state transition diagram to model the power window lift system in a car according to the following requirements.

One input (u) is the direction in which the window should move.

  • -1 - the window is lowered
  • 0 - the window remains stationary
  • 1 - the window rises.

One output (pos) - the current position of the window.

  • pos = 0 - Window fully open
  • pos = 20 - Window fully closed

The Chart block diagram must have the following characteristics:

  • If it is indicated that the window is closing (u = 1), but it is not completely closed, pos should be increased by 1.
  • If the window is down (u = -1) and it is not fully open, pos should be decreased by 1.
  • If the window is programmed to remain stationary (u = 0), the value of pos must not be changed.
  • The window position must start with the window fully closed (pos = 20).
  • The graph must be displayed every 0.1 seconds.
  • The graph must contain three states - Up, Down and Stop.

The obtained model is located in a folder called power_window_simple.engee. You can open it and study it in detail. But it is also possible to run the model with the code and get the results.

In [ ]:
# Подключение вспомогательной функции запуска модели.
function run_model( name_model, path_to_folder )
    
    Path = path_to_folder * "/" * name_model * ".engee"
    
    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end

    return model_output
end
Out[0]:
run_model (generic function with 1 method)
In [ ]:
run_model("power_window_simple",@__DIR__) # Запуск модели.
Building...
Progress 0%
Progress 100%
Progress 100%
Out[0]:
SimulationResult(
    "u" => WorkspaceArray{Float64}("power_window_simple/u")
,
    "pos" => WorkspaceArray{Float64}("power_window_simple/pos")

)
In [ ]:
# Считывание из simout залогированных сигналов
Pos = simout["power_window_simple/pos"];
Pos = collect(Pos);
In [ ]:
using Plots
plot(Pos.time, Pos.value)
Out[0]:

Now you can complicate the model and take into account the case when something is caught between the glass and the window frame when lifting the glass.

Logic of operation taking into account the sensor

Let's modify the model to take into account the pinch sensor. The following requirements apply to the logic of operation of the power window with the sensor:

  • If the pinch sensor detects a pinch (pinch signal greater than 0), the window must not move at all for 3 seconds;
  • Afterwards, if the signal from the sensor is 0, normal operation is resumed. Otherwise, the window will not move until the obstacle is removed.

Let's complete the model from the previous paragraph. Adding the state CannotMove, which is responsible for the possibility of moving the window. That is, the transition to this state occurs when the variable pinched is greater than 0. The assembled model is shown below and the file with the model is located in the folder named power_window.engee.

power_window_1718904216220.png

In [ ]:
run_model("power_window",@__DIR__) # Запуск модели.
Building...
Progress 0%
Progress 100%
Progress 100%
Out[0]:
SimulationResult(
    "Сигнал с датчика.1" => WorkspaceArray{Float64}("power_window/Сигнал с датчика.1")
,
    "u" => WorkspaceArray{Float64}("power_window/u")
,
    "pos" => WorkspaceArray{Float64}("power_window/pos")

)
In [ ]:
# Считывание из simout залогированных сигналов
Pos = simout["power_window/pos"];
Pos = collect(Pos);
In [ ]:
plot(Pos.time, Pos.value)
Out[0]:

Conclusions

Thus, we have considered the case when an object is pinched when the window is raised. We can further complicate the model, taking into account various difficulties when closing the window. You can also see other examples of using Chart block in Finite automata.

Blocks used in example