Skip to content

Commit e0de5cd

Browse files
authored
Merge pull request #62 from MiSaren/main
Refactoring (Aalto-Electric-Drives#146)
2 parents 15ca070 + 147a38b commit e0de5cd

File tree

10 files changed

+85
-133
lines changed

10 files changed

+85
-133
lines changed

examples/grid_following/plot_gfl_10kva.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from motulator.common.utils import BaseValues, NominalValues
1515
from motulator.grid import model
1616
import motulator.grid.control.grid_following as control
17-
from motulator.grid.utils import FilterPars, GridPars, plot_grid
17+
from motulator.grid.utils import FilterPars, GridPars, plot
1818
# from motulator.grid.utils import plot_voltage_vector
1919
# from motulator.common.model import CarrierComparison
2020
# import numpy as np
@@ -38,8 +38,7 @@
3838
ac_filter = model.ACFilter(filter_par, grid_par)
3939

4040
# AC grid model with constant voltage magnitude and frequency
41-
grid_model = model.ThreePhaseVoltageSource(
42-
w_g=grid_par.w_gN, abs_e_g=grid_par.u_gN)
41+
grid_model = model.ThreePhaseVoltageSource(w_g=base.w, abs_e_g=base.u)
4342

4443
# Inverter with constant DC voltage
4544
converter = VoltageSourceConverter(u_dc=650)
@@ -54,8 +53,7 @@
5453
# Configure the control system.
5554

5655
# Control configuration parameters
57-
cfg = control.GFLControlCfg(
58-
grid_par=grid_par, filter_par=filter_par, max_i=1.5*base.i)
56+
cfg = control.GFLControlCfg(grid_par, filter_par, max_i=1.5*base.i)
5957

6058
# Create the control system
6159
ctrl = control.GFLControl(cfg)
@@ -68,8 +66,8 @@
6866
ctrl.ref.q_g = lambda t: (t > .04)*4e3
6967

7068
# Uncomment lines below to simulate a unbalanced fault (add negative sequence)
71-
# mdl.grid_model.par.abs_e_g = 0.75*base.u
72-
# mdl.grid_model.par.abs_e_g_neg = 0.25*base.u
69+
# mdl.grid_model.par.abs_e_g = .75*base.u
70+
# mdl.grid_model.par.abs_e_g_neg = .25*base.u
7371
# mdl.grid_model.par.phi_neg = -np.pi/3
7472

7573
# %%
@@ -86,4 +84,4 @@
8684

8785
# Uncomment line below to plot locus of the grid voltage space vector
8886
# plot_voltage_vector(sim, base)
89-
plot_grid(sim, base, plot_pcc_voltage=True)
87+
plot(sim, base, plot_pcc_voltage=False)

examples/grid_following/plot_gfl_dc_bus_10kva.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from motulator.grid import model
1616
import motulator.grid.control.grid_following as control
1717
from motulator.grid.control import DCBusVoltageController
18-
from motulator.grid.utils import FilterPars, GridPars, plot_grid
18+
from motulator.grid.utils import FilterPars, GridPars, plot
1919

2020
# %%
2121
# Compute base values based on the nominal values.
@@ -35,12 +35,8 @@
3535
# Create AC filter with given parameters
3636
ac_filter = model.ACFilter(filter_par, grid_par)
3737

38-
# AC-voltage magnitude (to simulate voltage dips or short-circuits)
39-
abs_e_g_var = lambda t: base.u
40-
4138
# AC grid model with constant voltage magnitude and frequency
42-
grid_model = model.ThreePhaseVoltageSource(
43-
w_g=grid_par.w_gN, abs_e_g=abs_e_g_var)
39+
grid_model = model.ThreePhaseVoltageSource(w_g=base.w, abs_e_g=base.u)
4440

4541
# Inverter model with DC-bus dynamics included
4642
converter = VoltageSourceConverter(u_dc=600, C_dc=1e-3)
@@ -51,14 +47,8 @@
5147
# %%
5248
# Configure the control system.
5349

54-
# Control parameters
55-
cfg = control.GFLControlCfg(
56-
grid_par=grid_par,
57-
C_dc=1e-3,
58-
filter_par=filter_par,
59-
max_i=1.5*base.i,
60-
)
6150
# Create the control system
51+
cfg = control.GFLControlCfg(grid_par, filter_par, max_i=1.5*base.i, C_dc=1e-3)
6252
ctrl = control.GFLControl(cfg)
6353

6454
# Add the DC-bus voltage controller to the control system
@@ -86,4 +76,4 @@
8676
# By default results are plotted in per-unit values. By omitting the argument
8777
# `base` you can plot the results in SI units.
8878

89-
plot_grid(sim=sim, base=base, plot_pcc_voltage=True)
79+
plot(sim, base)

examples/grid_following/plot_gfl_lcl_10kva.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from motulator.common.utils import BaseValues, NominalValues
1515
from motulator.grid import model
1616
import motulator.grid.control.grid_following as control
17-
from motulator.grid.utils import FilterPars, GridPars, plot_grid
17+
from motulator.grid.utils import FilterPars, GridPars, plot
1818

1919
# %%
2020
# Compute base values based on the nominal values.
@@ -32,28 +32,20 @@
3232
# DC-bus parameters
3333
ac_filter = model.ACFilter(filter_par, grid_par)
3434

35-
# AC-voltage magnitude (to simulate voltage dips or short-circuits)
36-
abs_e_g_var = lambda t: grid_par.u_gN
37-
3835
# AC grid model with constant voltage magnitude and frequency
39-
grid_model = model.ThreePhaseVoltageSource(
40-
w_g=grid_par.w_gN, abs_e_g=abs_e_g_var)
36+
grid_model = model.ThreePhaseVoltageSource(w_g=base.w, abs_e_g=base.u)
4137

4238
# Inverter model with constant DC voltage
4339
converter = VoltageSourceConverter(u_dc=650)
4440

4541
# Create system model
4642
mdl = model.GridConverterSystem(converter, ac_filter, grid_model)
4743

48-
# Uncomment line below to enable the PWM model
49-
#mdl.pwm = CarrierComparison()
50-
5144
# %%
5245
# Configure the control system.
5346

5447
# Control parameters
55-
cfg = control.GFLControlCfg(
56-
grid_par=grid_par, filter_par=filter_par, max_i=1.5*base.i)
48+
cfg = control.GFLControlCfg(grid_par, filter_par, max_i=1.5*base.i)
5749

5850
# Create the control system
5951
ctrl = control.GFLControl(cfg)
@@ -74,7 +66,4 @@
7466
# %%
7567
# Plot the results.
7668

77-
# By default results are plotted in per-unit values. By omitting the argument
78-
# `base` you can plot the results in SI units.
79-
80-
plot_grid(sim, base=base, plot_pcc_voltage=True)
69+
plot(sim, base)

examples/grid_forming/plot_gfm_obs_13kva.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from motulator.common.utils import BaseValues, NominalValues
1515
from motulator.grid import model
1616
import motulator.grid.control.grid_forming as control
17-
from motulator.grid.utils import FilterPars, GridPars, plot_grid
17+
from motulator.grid.utils import FilterPars, GridPars, plot
1818
# from motulator.common.model import CarrierComparison
1919

2020
# %%
@@ -38,18 +38,14 @@
3838
ac_filter = model.ACFilter(filter_par, grid_par)
3939

4040
# Grid voltage source with constant frequency and voltage magnitude
41-
grid_model = model.ThreePhaseVoltageSource(
42-
w_g=grid_par.w_gN, abs_e_g=grid_par.u_gN)
41+
grid_model = model.ThreePhaseVoltageSource(w_g=base.w, abs_e_g=base.u)
4342

4443
# Inverter with constant DC voltage
4544
converter = VoltageSourceConverter(u_dc=650)
4645

4746
# Create system model
4847
mdl = model.GridConverterSystem(converter, ac_filter, grid_model)
4948

50-
# Uncomment the lines below to enable the PWM model
51-
# mdl.pwm = CarrierComparison()
52-
5349
# %%
5450
# Configure the control system.
5551

@@ -58,11 +54,7 @@
5854

5955
# Set the configuration parameters
6056
cfg = control.ObserverBasedGFMControlCfg(
61-
grid_par=grid_par_est,
62-
filter_par=filter_par,
63-
T_s=100e-6,
64-
max_i=1.3*base.i,
65-
R_a=.2*base.Z)
57+
grid_par_est, filter_par, max_i=1.3*base.i, T_s=100e-6, R_a=.2*base.Z)
6658

6759
# Create the control system
6860
ctrl = control.ObserverBasedGFMControl(cfg)
@@ -71,19 +63,18 @@
7163
# Set the references for converter output voltage magnitude and active power.
7264

7365
# Converter output voltage magnitude reference
74-
ctrl.ref.v_c = lambda t: grid_par.u_gN
66+
ctrl.ref.v_c = lambda t: base.u
7567

7668
# Active power reference
77-
ctrl.ref.p_g = lambda t: ((t > .2)*(4.15e3) + (t > .5)*(4.15e3) + (t > .8)*
78-
(4.2e3) - (t > 1.2)*(12.5e3))
69+
ctrl.ref.p_g = lambda t: ((t > .2)/3 + (t > .5)/3 + (t > .8)/3 -
70+
(t > 1.2))*nom.P
7971

8072
# Uncomment line below to simulate operation in rectifier mode
81-
# ctrl.ref.p_g = lambda t: ((t > .2) - (t > .7)*2 + (t > 1.2))*12.5e3
73+
# ctrl.ref.p_g = lambda t: ((t > .2) - (t > .7)*2 + (t > 1.2))*nom.P
8274

8375
# Uncomment lines below to simulate a grid voltage sag with constant ref.p_g
84-
# mdl.grid_model.par.e_g_abs = lambda t: (
85-
# 1 - (t > .2)*(0.8) + (t > 1)*(0.8))*grid_par.u_gN
86-
# ctrl.ref.p_g = lambda t: 12.5e3
76+
# mdl.grid_model.par.abs_e_g = lambda t: (1 - (t > .2)*.8 + (t > 1)*.8)*base.u
77+
# ctrl.ref.p_g = lambda t: nom.P
8778

8879
# %%
8980
# Create the simulation object and simulate it.
@@ -94,7 +85,4 @@
9485
# %%
9586
# Plot the results.
9687

97-
# By default results are plotted in per-unit values. By omitting the argument
98-
# `base` you can plot the results in SI units.
99-
100-
plot_grid(sim=sim, base=base, plot_pcc_voltage=False)
88+
plot(sim, base)

examples/grid_forming/plot_gfm_rfpsc_13kva.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from motulator.common.utils import BaseValues, NominalValues
1313
from motulator.grid import model
1414
import motulator.grid.control.grid_forming as control
15-
from motulator.grid.utils import FilterPars, GridPars, plot_grid
15+
from motulator.grid.utils import FilterPars, GridPars, plot
1616

1717
# %%
1818
# Compute base values based on the nominal values.
@@ -35,8 +35,7 @@
3535
ac_filter = model.ACFilter(filter_par, grid_par)
3636

3737
# Grid voltage source with constant frequency and voltage magnitude
38-
grid_model = model.ThreePhaseVoltageSource(
39-
w_g=grid_par.w_gN, abs_e_g=grid_par.u_gN)
38+
grid_model = model.ThreePhaseVoltageSource(w_g=base.w, abs_e_g=base.u)
4039

4140
# Inverter with constant DC voltage
4241
converter = VoltageSourceConverter(u_dc=650)
@@ -49,11 +48,7 @@
4948

5049
# Control configuration parameters
5150
cfg = control.RFPSCControlCfg(
52-
grid_par=grid_par,
53-
filter_par=filter_par,
54-
T_s=100e-6,
55-
max_i=1.3*base.i,
56-
R_a=.2*base.Z)
51+
grid_par, filter_par, max_i=1.3*base.i, T_s=100e-6, R_a=.2*base.Z)
5752

5853
# Create the control system
5954
ctrl = control.RFPSCControl(cfg)
@@ -62,10 +57,10 @@
6257
# Set the references for converter output voltage magnitude and active power.
6358

6459
# Converter output voltage magnitude reference
65-
ctrl.ref.v = lambda t: grid_par.u_gN
60+
ctrl.ref.v_c = lambda t: base.u
6661

6762
# Active power reference
68-
ctrl.ref.p_g = lambda t: ((t > .2)*(1/3) + (t > .5)*(1/3) + (t > .8)*(1/3) -
63+
ctrl.ref.p_g = lambda t: ((t > .2)/3 + (t > .5)/3 + (t > .8)/3 -
6964
(t > 1.2))*nom.P
7065

7166
# %%
@@ -77,7 +72,4 @@
7772
# %%
7873
# Plot the results.
7974

80-
# By default results are plotted in per-unit values. By omitting the argument
81-
# `base` you can plot the results in SI units.
82-
83-
plot_grid(sim, base=base, plot_pcc_voltage=True)
75+
plot(sim, base)

motulator/common/control/_control.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ class ComplexPIController:
294294
2DOF synchronous-frame complex-vector PI controller.
295295
296296
This implements a discrete-time 2DOF synchronous-frame complex-vector PI
297-
controller, based on a disturbance observer structure. The complex-vector
298-
gain selection is based on [#Bri2000]_. The addition of the feedforward
299-
signal is based on [#Har2009]_. The continuous-time counterpart of
300-
the controller is::
297+
controller [#Bri2000]_. The continuous-time counterpart of the controller
298+
is::
301299
302300
u = k_t*ref_i - k_p*i + (k_i + 1j*w*k_t)/s*(ref_i - i) + u_ff
303301
@@ -330,11 +328,9 @@ class ComplexPIController:
330328
"""
331329

332330
def __init__(self, k_p, k_i, k_t=None):
333-
# Gains
334331
self.k_p = k_p
335332
self.k_t = k_t if k_t is not None else k_p
336333
self.alpha_i = k_i/self.k_t # Inverse of the integration time T_i
337-
# States
338334
self.v, self.u_i = 0, 0
339335

340336
def output(self, ref_i, i, u_ff=0):

0 commit comments

Comments
 (0)