Engee documentation
Notebook

DC motor with electrical and mechanical parameters

This example will demonstrate a model of a DC motor with electrical and mechanical parameters. The process of launching the model from the script development environment using command control, as well as visualization of 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:

dc_motor_default--1715613166000.png

Defining the function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("dc_motor_default", force=true) # closing the model
        catch err # if there is no model to close and engee.close() is not executed, it will be loaded after catch.
            m = engee.load("/user/start/examples/physmod/dc_motor_default/dc_motor_default.engee") # loading the model
        end;

    try
        engee.run(m, verbose=true) # launching the model
        catch err # if the model is not loaded and engee.run() is not executed, the bottom two lines after catch will be executed.
            m = engee.load("/user/start/examples/physmod/dc_motor_default/dc_motor_default.engee") # loading the model
            engee.run(m, verbose=true) # launching the model
        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() # loading and launching the model
    catch err
    end;
sleep(5)
# data1 = collect(simout) # extracting data from the simout variable describing collector current and collector-emitter voltage
# Vce = collect(data1[2]) # writing collector-emitter voltage data to a variable
# Ic1 = collect(data1[3]); # writing collector current data to a variable
Building...
Progress 0%
Progress 8%
Progress 40%
Progress 95%
Progress 100%
Progress 100%

Writing signals to the data variable:

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

Recording data on the current and torque on the motor shaft in the variables current and torque:

In [ ]:
torque = collect(data[1])
current = collect(data[3]);

Visualization of results

Output of graphs of the dependence of current and torque on time:

In [ ]:
p1 = plot(current[:,1], current[:,2], label="Current", color="red")
p2 = plot(torque[:,1], torque[:,2], label="The torque", color="green")
plot(p1, p2, layout=(2,1))
Out[0]:
No description has been provided for this image

Conclusions:

In this example, tools for command management of the model were used. The simulation results using simout were recorded in the corresponding variables, as well as visualized using interactive graphs from the Plots library.