Engee documentation
Notebook

Model mass-spring-damper with control system

This example shows a simulation of a mass-spring-damper system with a control system. In the model, the force applied to the mass is adjusted so that its position corresponds to the setpoint signal. The initial velocity of the mass is 10 meters per second. The control system determines the force exerted by the force source so that the movement of the system corresponds to the stepwise changes in the input signal.

Model diagram:

mass_spring_damper_control--1734001884047.png

Defining a function to load and run the model:

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

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

Launching the model:

In [ ]:
try
    start_model_engee() # запуск симуляции с помощью специальной функции, реализованной выше
    catch err
    end;

Output of simulation results from the simout variable:

In [ ]:
res = collect(simout)
Out[0]:
16-element Vector{WorkspaceArray}:
 WorkspaceArray{Float64}("Translational Damper.case_flange.v")
 WorkspaceArray{Float64}("Translational Spring.F")
 WorkspaceArray{Float64}("Translational Spring.delta_v")
 WorkspaceArray{Float64}("Ideal Force Source.F_in")
 WorkspaceArray{Float64}("Translational Spring.delta_p")
 WorkspaceArray{Float64}("Ideal Force Source.delta_v")
 WorkspaceArray{Float64}("Ideal Force Source.rod_flange.v")
 WorkspaceArray{Float64}("Translational Damper.delta_v")
 WorkspaceArray{Float64}("Translational Damper.power_dissipated")
 WorkspaceArray{Float64}("Translational Damper.rod_flange.v")
 WorkspaceArray{Float64}("Translational Spring.case_flange.v")
 WorkspaceArray{Float64}("Translational Damper.F")
 WorkspaceArray{Float64}("mass_spring_damper_control/Ideal Translational Motion Sensor.2")
 WorkspaceArray{Float64}("Ideal Force Source.case_flange.v")
 WorkspaceArray{Float64}("Translational Spring.rod_flange.v")
 WorkspaceArray{Float64}("Ideal Force Source.F")

Writing results to variables:

In [ ]:
Force_Source = collect(res[16]) 
Damper_F = collect(res[12]) 
Spring_F = collect(res[2]) 
P = collect(res[13]); # Перемещение массы

Simulation results:

In [ ]:
using Plots
plot(P[:,1], P[:,2], linewidth=3, xlabel= "Время, с", ylabel= "Перемещение, м", legend=:bottomright, title="Перемещение груза")
Out[0]:
In [ ]:
plot(Force_Source[:,1], Force_Source[:,2], linewidth=3, xlabel= "Время, с", ylabel= "Сила, Н", legend=:bottomright, label="Внешнее усилие")
plot!(Spring_F[:,1], Spring_F[:,2], linewidth=3, label="Пружина")
plot!(Damper_F[:,1], Damper_F[:,2], linewidth=3, label="Демпфер", title="Силы, действующие на груз")
Out[0]: