Engee documentation
Notebook

Simulation of a diode bridge

This example will demonstrate a solution to a classic electrical engineering problem – converting an alternating voltage to a constant one. This problem is solved with the help of rectifiers. One of the rectifier options is a bridge circuit:

rect_scheme.png

Consider the corresponding scheme in Engee (model ssc_bridge_rectifier.engee):

image.png

The rectifier is modeled here using blocks from the library of electrical components.

In [ ]:
Pkg.add(["Statistics", "CSV"])
   Resolving package versions...
  No Changes to `~/.project/Project.toml`
  No Changes to `~/.project/Manifest.toml`
In [ ]:
using Plots
using MATLAB
using CSV
using DataFrames
using Statistics

demoroot = @__DIR__;
In [ ]:
mat"start_simulink"
In [ ]:
mat"p = $demoroot; addpath(p);"
mat"p = '/user/start/examples/helper_units'; addpath(p);"

Implementation of the model launch using software control:

Loading the model:

In [ ]:
modelName = "ssc_bridge_rectifier";
model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");

Launching the uploaded model:

In [ ]:
results = engee.run( modelName )
Out[0]:
SimulationResult(
    run_id => 2,
    "AC Voltage" => WorkspaceArray{Float64}("ssc_bridge_rectifier/AC Voltage")
,
    "DC Voltage" => WorkspaceArray{Float64}("ssc_bridge_rectifier/DC Voltage")

)

Loading and visualizing the data obtained during the simulation.

Let's plot the rectified voltage graph:

In [ ]:
Bridge_Engee_t = results["DC Voltage"].time;
Bridge_Engee_d = results["DC Voltage"].value;
p_adc_da_e = plot(Bridge_Engee_t ,Bridge_Engee_d , legend = false)
plot!(title = "Результаты моделирования в Engee", ylabel = "Напряжение, В", xlabel="Время, c")
Out[0]:

Comparison with Simscape

The same scheme can be modeled in SimScape:

image.png

Running the model in Simulink and loading the results into variables:

In [ ]:
mat"run_test_model('ssc_bridge_rectifier_demo');";
sl_rect_values = mat"SysOutput.Data";
sl_rect_times = mat"SysOutput.Time";

Let's look at the simulation results in SimScape:

In [ ]:
plot(sl_rect_times, sl_rect_values, legend = false) 
plot!(title = "Результаты моделирования в Simulink", ylabel = "Напряжение, В", xlabel="Время, c")
Out[0]:

Let's compare the graphs:

In [ ]:
plot(Bridge_Engee_t ,Bridge_Engee_d, label = "Engee")
plot!(title = "Сравнение результатов моделирования")
plot!(sl_rect_times, sl_rect_values, label = "Simulink")
plot!(legend = :outertopright,ylabel = "Цифровой сигнал", xlabel="Время, c")
Out[0]:

Conclusion:

In this example, we demonstrated the simulation of a diode rectifier using command control of the model in the Engee script editor, as well as running the model from the Simulink environment. The calculations showed a minimal difference in the results when running the simulation in these two environments.