Engee documentation
Notebook

Mass-spring-damper model with control system

This example shows the modelling of a mass-spring-damper system with a control system. In the model, the force applied to the mass is adjusted to match the position of the mass to the setpoint signal. The initial velocity of the mass is 10 metres per second. The control system determines the force applied by the force source so that the movement of the system matches the step changes in the input signal.

Schematic of the model:

mass_spring_damper_control_1734001884047.png

Define the 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)

Running the model:

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

Output the results of the simulation from the simout variable:

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

Writing results to variables:

In [ ]:
Force_Source = collect(res[22])
Damper_F = collect(res[17])
Spring_F = collect(res[3])
P = collect(res[18]); # Перемещение массы

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]: