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) # 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]:
start_model_engee (generic function with 1 method)

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]:
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]); # 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]: