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:
Defining a function to load and run the model:
In [ ]:
function start_model_engee()
try
engee.close("mass_spring_damper_control", 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("$(@__DIR__)/mass_spring_damper_control.engee") # loading the model
end;
try
engee.run(m) # 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("$(@__DIR__)/mass_spring_damper_control.engee") # loading the model
engee.run(m) # launching the model
end
end
Out[0]:
Launching the model:
In [ ]:
try
start_model_engee() # running the simulation using the special function implemented above
catch err
end;
Output of simulation results from the simout variable:
In [ ]:
res = collect(simout)
Out[0]:
Writing results to variables:
In [ ]:
Force_Source = collect(res[16])
Damper_F = collect(res[12])
Spring_F = collect(res[2])
P = collect(res[13]); # Moving the mass
Simulation results:
In [ ]:
using Plots
plot(P[:,1], P[:,2], linewidth=3, xlabel= "Time, from", ylabel= "Displacement, m", legend=:bottomright, title="Cargo movement")
Out[0]:
In [ ]:
plot(Force_Source[:,1], Force_Source[:,2], linewidth=3, xlabel= "Time, from", ylabel= "Power, N", legend=:bottomright, label="External force")
plot!(Spring_F[:,1], Spring_F[:,2], linewidth=3, label="Spring")
plot!(Damper_F[:,1], Damper_F[:,2], linewidth=3, label="The damper", title="Forces acting on the load")
Out[0]: