Engee documentation
Notebook

DC motor

This example will demonstrate the DC motor models created in Engee (model ssc_dcmotor.engee) and in Simulink (model ssc_dcmotor_demo.slx). The process of launching models from the script development environment using command control and comparing the simulation results will be shown. In the simulation, an alternating torque acts on the shaft of the electric motor.

General view of the models

The Engee model:
image.png

The Simulink model:
image.png

Launching the model using software control

In [ ]:
Pkg.add(["Statistics", "CSV"])
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using Plots
using MATLAB
using CSV
using DataFrames
using Statistics

demoroot = @__DIR__

mat"start_simulink"
mat"p = $demoroot; addpath(p);"
mat"p = /user/start/examples/helper_units; addpath(p);"
 p = /user/start/examples/helper_units; addpath(p);;
     |
{Invalid use of operator.
} 

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");

Launching the uploaded model:

In [ ]:
results = engee.run( modelName )
Out[0]:
SimulationResult(
    "omega" => WorkspaceArray{Float64}("ssc_dcmotor/рад/c в об/omega")

)

Simulation results:

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

Visualization of results

Output of a graph of the dependence of the engine speed on time:

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

Launching the Simulink model:

In [ ]:
mat"run_test_model('ssc_dcmotor_demo');";

Output of a graph of the dependence of the engine speed on time:

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 management of the model were used, and therefore the Engee and Simulink models were launched from the script. The simulation results were saved to csv files, uploaded, visualized, and analyzed using interactive graphs from the Plots library. A visual analysis of the results showed that the models of electric cars created in both Engee and Simulink are identical.