forked from Aalto-Electric-Drives/motulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate_vhz.py
52 lines (44 loc) · 1.59 KB
/
simulate_vhz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# pylint: disable=C0103
'''
(c) Aalto Electric Drives (contact: [email protected])
motulator: Open-Source Simulator for Motor Drives and Power Converters
'''
# %% Imports
from time import time
from model.interfaces import solve
# %%
# Import the controller and the model. The base values are imported for
# plotting the results.
from config.ctrl_vhz_im_2kW import ctrl, mdl, base
# from config.ctrl_vhz_im_45kW import ctrl, mdl, base
# %%
def main():
"""
Run the digital controller and solve the continuous-time system model.
"""
while mdl.t0 <= mdl.t_stop:
# Sample the phase currents and the DC-bus voltage
i_s_abc_meas = mdl.motor.meas_currents()
u_dc_meas = mdl.converter.meas_dc_voltage()
# Get the speed reference
w_m_ref = mdl.speed_ref(mdl.t0)
# Run the digital controller
d_abc_ref, T_s = ctrl(w_m_ref, i_s_abc_meas, u_dc_meas)
# Model the computational delay
d_abc = mdl.delay(d_abc_ref)
# Simulate the continuous-time system model over the sampling period
solve(mdl, d_abc, [mdl.t0, mdl.t0+T_s])
# %% Main program
if __name__ == '__main__':
# Start computing the execution time
start_time = time()
# Run the model
main()
# Print the execution time
print('\nExecution time: {:.2f} s'.format((time() - start_time)))
# Post-process and plot
mdl.datalog.post_process(mdl)
ctrl.datalog.post_process()
ctrl.datalog.plot(mdl, base)
# ctrl.datalog.plot_latex(mdl, base)
ctrl.datalog.plot_extra(mdl, base)