forked from Aalto-Electric-Drives/motulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate_sensorless.py
53 lines (45 loc) · 1.79 KB
/
simulate_sensorless.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
53
# 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 configuration data for the controller and the model
# You can use the existing config files as templates and modify them
from config.ctrl_sensorless_vector_pmsm_2kW import ctrl, mdl, base
# from config.ctrl_sensorless_vector_syrm_7kW import ctrl, mdl, base
# from config.ctrl_sensorless_vector_im_2kW import ctrl, mdl, base
# from config.ctrl_sensorless_vector_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)