Engee documentation
Notebook

DC motor with electrical and mechanical parameters

This example will demonstrate a DC motor model with electrical and mechanical parameters. The process of running the model from the script development environment using command control and the visualisation of the simulation results will be shown. In the simulation, a variable torque is applied to the motor shaft.

General view of the models

Engee model:

dc_motor_default_1715613166000.png

Define the function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("dc_motor_default", force=true) # закрытие модели 
        catch err # в случае, если нет модели, которую нужно закрыть и engee.close() не выполняется, то будет выполнена её загрузка после catch
            m = engee.load("/user/start/examples/physmod/dc_motor_default/dc_motor_default.engee") # загрузка модели
        end;

    try
        engee.run(m, verbose=true) # запуск модели
        catch err # в случае, если модель не загружена и engee.run() не выполняется, то будут выполнены две нижние строки после catch
            m = engee.load("/user/start/examples/physmod/dc_motor_default/dc_motor_default.engee") # загрузка модели
            engee.run(m, verbose=true) # запуск модели
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Loading, running the model and recording the results

In [ ]:
try
    start_model_engee() # загрузка и запуск модели
    catch err
    end;
sleep(5)
#data1 = collect(simout) # выделение из переменной simout данных, описывающих ток коллектора и напряжение коллектор-эмиттер
#Vce = collect(data1[2]) # запись данных о напряжении коллектор-эмиттер в переменную
#Ic1 = collect(data1[3]); # запись данных о токе коллектора в переменную
Building...
Progress 100%

Write signals to the variable data:

In [ ]:
data = collect(simout)
Out[0]:
7-element Vector{WorkspaceArray}:
 WorkspaceArray("dc_motor_default/Inertia.flange.T")
 WorkspaceArray("dc_motor_default/Крутящий момент")
 WorkspaceArray("dc_motor_default/Inertia.T")
 WorkspaceArray("dc_motor_default/Сила тока")
 WorkspaceArray("dc_motor_default/Напряжение")
 WorkspaceArray("dc_motor_default/Inertia.flange.w")
 WorkspaceArray("dc_motor_default/Inertia.w")

Write current and torque data on the motor shaft to the variables current and torque:

In [ ]:
torque = collect(data[2])
current = collect(data[4]);

Visualising the results

Plots of current and torque versus time:

In [ ]:
p1 = plot(current[:,1], current[:,2], label="Ток", color="red")
p2 = plot(torque[:,1], torque[:,2], label="Крутящий момент", color="green")
plot(p1, p2, layout=(2,1))
Out[0]:

Conclusions:

In this example, tools for command control of the model were used. The results of the simulation using simout were recorded in the appropriate variables, and visualised, using the interactive plots of the Plots library.