Engee documentation
Notebook

DC motor

This example will demonstrate DC motor models created in Engee (model ssc_dcmotor.engee) and in Simulink (model ssc_dcmotor_demo.slx). The process of running the models from the script development environment using command control and comparing 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: image.png

Simulink Model: image.png

Running the model with software control

In [ ]:
Pkg.add(["Statistics", "CSV"])
In [ ]:
using Plots
using MATLAB
using CSV
using DataFrames
using Statistics

plotlyjs();

mat"start_simulink"
mat"p = genpath('/user/start/examples'); addpath(p);"
[ Info: Precompiling MATLAB [10e44e05-a98a-55b3-a45b-ba969058deb6]

Loading the model:

In [ ]:
modelName = "ssc_dcmotor";
dcmotor_model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");

Running a loaded model:

In [ ]:
results = engee.run( modelName )
Out[0]:
Dict{String, DataFrame} with 1 entry:
  "omega" => 2001×2 DataFrame

Modelling results:

In [ ]:
W_en_t = results["omega"].time;
W_en_w = results["omega"].value;

Visualisation of results

Output a graph of the time dependence of the motor speed:

In [ ]:
plot(W_en_t , W_en_w, legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Скорость вращения двигателя, об/мин", xlabel="Время, c")
Out[0]:

Running the Simulink model:

In [ ]:
mat"run_test_model('ssc_dcmotor_demo');";
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"

Output a graph of the time dependence of the motor speed:

In [ ]:
W_sim_w = mat"SysOutput.Data";
W_sim_t = mat"SysOutput.Time";
plot(W_sim_t, W_sim_w, legend = false) 
plot!(title = "Результаты моделирования в Simulink", ylabel = "Скорость вращения двигателя, об/мин", xlabel="Время, c")
Out[0]:

Let's compare the simulation results in Engee and Simulink. To do this, let's compare the speed values.

In [ ]:
plot(W_en_t , W_en_w, label = "Engee")
plot!(title = "Сравнение результатов моделирования")
plot!(W_sim_t,W_sim_w, label = "Simulink")
plot!(ylabel = "Скорость вращения двигателя, об/мин", xlabel="Время, c")
Out[0]:

Conclusions:

In this example, tools for command control of the model were used, therefore Engee and Simulink models were run from the script. The results of the simulations were saved to csv files, downloaded, visualised, using interactive Plots library plots, and analysed. Visual analysis of the results showed that the electric machine models created in both Engee and Simulink were identical.