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:

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