motulator-export 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- motulator_export-0.7.0/.gitignore +30 -0
- motulator_export-0.7.0/LICENSE +21 -0
- motulator_export-0.7.0/PKG-INFO +96 -0
- motulator_export-0.7.0/README.md +61 -0
- motulator_export-0.7.0/motulator_export/__init__.py +13 -0
- motulator_export-0.7.0/motulator_export/c/README.md +60 -0
- motulator_export-0.7.0/motulator_export/c/common.c +546 -0
- motulator_export-0.7.0/motulator_export/c/common.h +237 -0
- motulator_export-0.7.0/motulator_export/c/drive.c +266 -0
- motulator_export-0.7.0/motulator_export/c/drive.h +97 -0
- motulator_export-0.7.0/motulator_export/c/gfl_current_vector.c +226 -0
- motulator_export-0.7.0/motulator_export/c/gfl_current_vector.h +158 -0
- motulator_export-0.7.0/motulator_export/c/gfm_observer.c +251 -0
- motulator_export-0.7.0/motulator_export/c/gfm_observer.h +180 -0
- motulator_export-0.7.0/motulator_export/c/gradnet.c +144 -0
- motulator_export-0.7.0/motulator_export/c/gradnet.h +60 -0
- motulator_export-0.7.0/motulator_export/c/grid.c +198 -0
- motulator_export-0.7.0/motulator_export/c/grid.h +74 -0
- motulator_export-0.7.0/motulator_export/c/im_current_vector.c +463 -0
- motulator_export-0.7.0/motulator_export/c/im_current_vector.h +201 -0
- motulator_export-0.7.0/motulator_export/c/im_flux_vector.c +262 -0
- motulator_export-0.7.0/motulator_export/c/im_flux_vector.h +156 -0
- motulator_export-0.7.0/motulator_export/c/native.c +48 -0
- motulator_export-0.7.0/motulator_export/c/native_gfl.c +196 -0
- motulator_export-0.7.0/motulator_export/c/native_gfm.c +199 -0
- motulator_export-0.7.0/motulator_export/c/native_im.c +294 -0
- motulator_export-0.7.0/motulator_export/c/native_sm.c +252 -0
- motulator_export-0.7.0/motulator_export/c/sim.c +859 -0
- motulator_export-0.7.0/motulator_export/c/sim.h +295 -0
- motulator_export-0.7.0/motulator_export/c/sm_control_loci.c +155 -0
- motulator_export-0.7.0/motulator_export/c/sm_control_loci.h +37 -0
- motulator_export-0.7.0/motulator_export/c/sm_flux_vector.c +521 -0
- motulator_export-0.7.0/motulator_export/c/sm_flux_vector.h +210 -0
- motulator_export-0.7.0/motulator_export/c/sm_machine.c +91 -0
- motulator_export-0.7.0/motulator_export/c/sm_machine.h +54 -0
- motulator_export-0.7.0/motulator_export/c/sm_parameters.c +106 -0
- motulator_export-0.7.0/motulator_export/c/sm_parameters.h +55 -0
- motulator_export-0.7.0/motulator_export/matlab/README.md +40 -0
- motulator_export-0.7.0/motulator_export/matlab/common.m +537 -0
- motulator_export-0.7.0/motulator_export/matlab/gfl_current_vector.m +78 -0
- motulator_export-0.7.0/motulator_export/matlab/gfm_observer.m +68 -0
- motulator_export-0.7.0/motulator_export/matlab/gradnet.m +117 -0
- motulator_export-0.7.0/motulator_export/matlab/im_current_vector.m +178 -0
- motulator_export-0.7.0/motulator_export/matlab/im_flux_vector.m +94 -0
- motulator_export-0.7.0/motulator_export/matlab/sm_control_loci.m +137 -0
- motulator_export-0.7.0/motulator_export/matlab/sm_flux_vector.m +185 -0
- motulator_export-0.7.0/motulator_export/matlab/sm_machine.m +69 -0
- motulator_export-0.7.0/motulator_export/matlab/sm_parameters.m +89 -0
- motulator_export-0.7.0/motulator_export/native/__init__.py +11 -0
- motulator_export-0.7.0/motulator_export/native/_build.py +72 -0
- motulator_export-0.7.0/motulator_export/native/_drive.py +126 -0
- motulator_export-0.7.0/motulator_export/native/_grid.py +184 -0
- motulator_export-0.7.0/motulator_export/native/_im.py +152 -0
- motulator_export-0.7.0/motulator_export/native/_simulation.py +224 -0
- motulator_export-0.7.0/motulator_export/native/_sm.py +157 -0
- motulator_export-0.7.0/motulator_export/native/_system.py +343 -0
- motulator_export-0.7.0/motulator_export/plecs/__init__.py +11 -0
- motulator_export-0.7.0/motulator_export/plecs/_common.py +932 -0
- motulator_export-0.7.0/motulator_export/plecs/_control.py +1300 -0
- motulator_export-0.7.0/motulator_export/plecs/_drive.py +380 -0
- motulator_export-0.7.0/motulator_export/plecs/_export.py +91 -0
- motulator_export-0.7.0/motulator_export/plecs/_grid.py +461 -0
- motulator_export-0.7.0/motulator_export/plecs/_grid_control.py +918 -0
- motulator_export-0.7.0/motulator_export/plecs/_im.py +340 -0
- motulator_export-0.7.0/motulator_export/plecs/_im_control.py +656 -0
- motulator_export-0.7.0/motulator_export/plecs/_im_vhz_control.py +556 -0
- motulator_export-0.7.0/motulator_export/plecs/_netlist.py +1050 -0
- motulator_export-0.7.0/motulator_export/plecs/_render.py +182 -0
- motulator_export-0.7.0/motulator_export/plecs/_rpc.py +66 -0
- motulator_export-0.7.0/motulator_export/plecs/_schematic.py +378 -0
- motulator_export-0.7.0/motulator_export/plecs/_sm.py +574 -0
- motulator_export-0.7.0/motulator_export/plecs/_sm_control.py +782 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add.m +4 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_control_system.m +54 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_converter.m +22 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_mechanics.m +33 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_mfunction.m +40 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_netlist.m +98 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_outputs.m +41 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_pwm.m +34 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/add_step.m +28 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/align.m +6 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/compile.m +9 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/connect.m +4 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/new_model.m +40 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/num.m +8 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/port_pos.m +6 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/port_y.m +5 -0
- motulator_export-0.7.0/motulator_export/simulink/+blocks/route.m +23 -0
- motulator_export-0.7.0/motulator_export/simulink/README.md +114 -0
- motulator_export-0.7.0/motulator_export/simulink/__init__.py +12 -0
- motulator_export-0.7.0/motulator_export/simulink/_common.py +341 -0
- motulator_export-0.7.0/motulator_export/simulink/_drive.py +133 -0
- motulator_export-0.7.0/motulator_export/simulink/_export.py +94 -0
- motulator_export-0.7.0/motulator_export/simulink/_grid.py +108 -0
- motulator_export-0.7.0/motulator_export/simulink/_im.py +78 -0
- motulator_export-0.7.0/motulator_export/simulink/_mfunction.py +505 -0
- motulator_export-0.7.0/motulator_export/simulink/_render.py +341 -0
- motulator_export-0.7.0/motulator_export/simulink/_sfunction.py +220 -0
- motulator_export-0.7.0/motulator_export/simulink/_sm.py +120 -0
- motulator_export-0.7.0/motulator_export/simulink/build_drive.m +319 -0
- motulator_export-0.7.0/motulator_export/simulink/build_grid.m +221 -0
- motulator_export-0.7.0/pyproject.toml +80 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Byte-compiled files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
|
|
5
|
+
# Distribution
|
|
6
|
+
*.egg-info/
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
|
|
10
|
+
# Environments
|
|
11
|
+
.venv
|
|
12
|
+
|
|
13
|
+
# PLECS autosave files and temporary models of the comparison scripts
|
|
14
|
+
*.autosave
|
|
15
|
+
*_tmp.plecs
|
|
16
|
+
|
|
17
|
+
# Simulink models, compiled S-functions, and caches built by the generated scripts
|
|
18
|
+
examples/simulink/*.slx
|
|
19
|
+
*.mex*
|
|
20
|
+
*.slxc
|
|
21
|
+
slprj/
|
|
22
|
+
|
|
23
|
+
# Sphinx documentation (the build, the API reference, and the gallery)
|
|
24
|
+
docs/build/
|
|
25
|
+
docs/source/autoapi/
|
|
26
|
+
docs/source/examples/
|
|
27
|
+
docs/source/sg_execution_times.rst
|
|
28
|
+
|
|
29
|
+
# macOS specific
|
|
30
|
+
.DS_Store
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aalto Electric Drives
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: motulator-export
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: Export motulator drive and grid converter systems to PLECS and Simulink, and simulate them natively
|
|
5
|
+
Project-URL: Homepage, https://github.com/Aalto-Electric-Drives/motulator-export
|
|
6
|
+
Project-URL: Documentation, https://aalto-electric-drives.github.io/motulator-export/
|
|
7
|
+
Project-URL: motulator, https://github.com/Aalto-Electric-Drives/motulator
|
|
8
|
+
Author-email: Marko Hinkkanen <marko.hinkkanen@aalto.fi>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: PLECS,Simulink,control,converter,motor,simulation
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: C
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Requires-Dist: motulator<0.16,>=0.15.2
|
|
18
|
+
Requires-Dist: numpy
|
|
19
|
+
Requires-Dist: tqdm
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pip-audit; extra == 'dev'
|
|
22
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
23
|
+
Requires-Dist: pyright; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
26
|
+
Provides-Extra: doc
|
|
27
|
+
Requires-Dist: myst-parser; extra == 'doc'
|
|
28
|
+
Requires-Dist: numpydoc; extra == 'doc'
|
|
29
|
+
Requires-Dist: sphinx; extra == 'doc'
|
|
30
|
+
Requires-Dist: sphinx-autoapi; extra == 'doc'
|
|
31
|
+
Requires-Dist: sphinx-book-theme; extra == 'doc'
|
|
32
|
+
Requires-Dist: sphinx-copybutton; extra == 'doc'
|
|
33
|
+
Requires-Dist: sphinx-gallery; extra == 'doc'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# motulator-export
|
|
37
|
+
|
|
38
|
+
Export [*motulator*](https://github.com/Aalto-Electric-Drives/motulator) drive systems and grid converter systems to [PLECS](https://www.plexim.com/products/plecs) and [Simulink](https://www.mathworks.com/products/simulink.html), and simulate them natively in C.
|
|
39
|
+
|
|
40
|
+
**Documentation:** https://aalto-electric-drives.github.io/motulator-export/
|
|
41
|
+
|
|
42
|
+
Build the system in *motulator* as usual, then:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from motulator_export import native, plecs, simulink
|
|
46
|
+
|
|
47
|
+
plecs.write_model("drive.plecs", mdl, ctrl, t_stop=1.2) # PLECS model
|
|
48
|
+
simulink.write_model("drive.slx", mdl, ctrl, t_stop=1.2) # Simulink model
|
|
49
|
+
res = native.Simulation(mdl, ctrl).simulate(t_stop=1.2) # Native simulation
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
<picture>
|
|
53
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aalto-Electric-Drives/motulator-export/main/docs/source/images/plecs_drive_black.png">
|
|
54
|
+
<img alt="PLECS model of a 2.2-kW IPMSM drive" src="https://raw.githubusercontent.com/Aalto-Electric-Drives/motulator-export/main/docs/source/images/plecs_drive.png">
|
|
55
|
+
</picture>
|
|
56
|
+
|
|
57
|
+
*PLECS model of a 2.2-kW IPMSM drive with sensorless flux-vector control, written by [examples/ipmsm_2kw_fvc.py](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/examples/ipmsm_2kw_fvc.py).*
|
|
58
|
+
|
|
59
|
+
- **One control code everywhere.** The control algorithms of *motulator* are ported to C. The same code runs in PLECS, in Simulink, and in the native simulation.
|
|
60
|
+
- **The structure of *motulator*.** Each class of the control system is a masked block with the arguments of its class, nested as in *motulator*. The parameters are set as in a *motulator* script, and they can be changed without Python.
|
|
61
|
+
- **Verified.** The PLECS and Simulink models agree with *motulator* to about 1e-6 relative to the signal magnitudes, and the native simulation to the rounding errors.
|
|
62
|
+
- **Fast.** The native simulation is 30 to 40 times faster than *motulator*, which is useful, e.g., for parameter sweeps.
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
Python 3.12 or later. Install the package in a virtual environment, which also installs *motulator* 0.15.2 or a later 0.15 release:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
python -m venv .venv
|
|
70
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
71
|
+
python -m pip install motulator-export
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The examples are in the repository. To run them, clone the repository and install the package from it:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git clone https://github.com/Aalto-Electric-Drives/motulator-export
|
|
78
|
+
cd motulator-export
|
|
79
|
+
python -m pip install -e .
|
|
80
|
+
python examples/ipmsm_2kw_fvc.py
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Then open the model `examples/ipmsm_2kw_fvc.plecs` in PLECS. See the [documentation](https://aalto-electric-drives.github.io/motulator-export/guide/getting_started.html) for the requirements of PLECS, Simulink, and the native simulation.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
Install the package with `pip install -e .[dev]` and run the tests with `pytest` (requires gcc). The implementation is described in the developer notes:
|
|
88
|
+
|
|
89
|
+
- [examples/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/examples/README.md): the structure of the PLECS models and their agreement with *motulator*
|
|
90
|
+
- [motulator_export/simulink/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/motulator_export/simulink/README.md): the structure of the Simulink models and their agreement with *motulator*
|
|
91
|
+
- [motulator_export/c/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/motulator_export/c/README.md): the C port of the control algorithms
|
|
92
|
+
- [motulator_export/matlab/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/motulator_export/matlab/README.md): the MATLAB port
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
[MIT](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/LICENSE)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# motulator-export
|
|
2
|
+
|
|
3
|
+
Export [*motulator*](https://github.com/Aalto-Electric-Drives/motulator) drive systems and grid converter systems to [PLECS](https://www.plexim.com/products/plecs) and [Simulink](https://www.mathworks.com/products/simulink.html), and simulate them natively in C.
|
|
4
|
+
|
|
5
|
+
**Documentation:** https://aalto-electric-drives.github.io/motulator-export/
|
|
6
|
+
|
|
7
|
+
Build the system in *motulator* as usual, then:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from motulator_export import native, plecs, simulink
|
|
11
|
+
|
|
12
|
+
plecs.write_model("drive.plecs", mdl, ctrl, t_stop=1.2) # PLECS model
|
|
13
|
+
simulink.write_model("drive.slx", mdl, ctrl, t_stop=1.2) # Simulink model
|
|
14
|
+
res = native.Simulation(mdl, ctrl).simulate(t_stop=1.2) # Native simulation
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
<picture>
|
|
18
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Aalto-Electric-Drives/motulator-export/main/docs/source/images/plecs_drive_black.png">
|
|
19
|
+
<img alt="PLECS model of a 2.2-kW IPMSM drive" src="https://raw.githubusercontent.com/Aalto-Electric-Drives/motulator-export/main/docs/source/images/plecs_drive.png">
|
|
20
|
+
</picture>
|
|
21
|
+
|
|
22
|
+
*PLECS model of a 2.2-kW IPMSM drive with sensorless flux-vector control, written by [examples/ipmsm_2kw_fvc.py](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/examples/ipmsm_2kw_fvc.py).*
|
|
23
|
+
|
|
24
|
+
- **One control code everywhere.** The control algorithms of *motulator* are ported to C. The same code runs in PLECS, in Simulink, and in the native simulation.
|
|
25
|
+
- **The structure of *motulator*.** Each class of the control system is a masked block with the arguments of its class, nested as in *motulator*. The parameters are set as in a *motulator* script, and they can be changed without Python.
|
|
26
|
+
- **Verified.** The PLECS and Simulink models agree with *motulator* to about 1e-6 relative to the signal magnitudes, and the native simulation to the rounding errors.
|
|
27
|
+
- **Fast.** The native simulation is 30 to 40 times faster than *motulator*, which is useful, e.g., for parameter sweeps.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Python 3.12 or later. Install the package in a virtual environment, which also installs *motulator* 0.15.2 or a later 0.15 release:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m venv .venv
|
|
35
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
36
|
+
python -m pip install motulator-export
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The examples are in the repository. To run them, clone the repository and install the package from it:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/Aalto-Electric-Drives/motulator-export
|
|
43
|
+
cd motulator-export
|
|
44
|
+
python -m pip install -e .
|
|
45
|
+
python examples/ipmsm_2kw_fvc.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then open the model `examples/ipmsm_2kw_fvc.plecs` in PLECS. See the [documentation](https://aalto-electric-drives.github.io/motulator-export/guide/getting_started.html) for the requirements of PLECS, Simulink, and the native simulation.
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
Install the package with `pip install -e .[dev]` and run the tests with `pytest` (requires gcc). The implementation is described in the developer notes:
|
|
53
|
+
|
|
54
|
+
- [examples/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/examples/README.md): the structure of the PLECS models and their agreement with *motulator*
|
|
55
|
+
- [motulator_export/simulink/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/motulator_export/simulink/README.md): the structure of the Simulink models and their agreement with *motulator*
|
|
56
|
+
- [motulator_export/c/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/motulator_export/c/README.md): the C port of the control algorithms
|
|
57
|
+
- [motulator_export/matlab/README.md](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/motulator_export/matlab/README.md): the MATLAB port
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
[MIT](https://github.com/Aalto-Electric-Drives/motulator-export/blob/main/LICENSE)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Export motulator systems to PLECS and Simulink, and simulate them natively.
|
|
3
|
+
|
|
4
|
+
The subpackages `plecs` and `simulink` write the models of a system built in
|
|
5
|
+
motulator, and `native` simulates the system in C. All of them run the same C port of
|
|
6
|
+
the control algorithms of motulator.
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from motulator_export import native, plecs, simulink
|
|
11
|
+
from motulator_export.plecs._common import StepSignal
|
|
12
|
+
|
|
13
|
+
__all__ = ["StepSignal", "native", "plecs", "simulink"]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# C port
|
|
2
|
+
|
|
3
|
+
C port of the *motulator* control algorithms and models, run in the C-Script blocks of the PLECS models, in the S-functions of the Simulink models, and in the libraries of the native simulation (`motulator_export.native`).
|
|
4
|
+
The code follows the Python code of *motulator* closely, including the order of the state updates, and each header lists its Python counterparts.
|
|
5
|
+
Optional parameters (`None` in *motulator*) are represented by `NAN`, and their defaults are resolved in the C code, as in *motulator*.
|
|
6
|
+
|
|
7
|
+
Each class is a type with its functions (e.g., `FluxObserver` with `flux_observer_init`, `flux_observer_compute_output`, and `flux_observer_update`), which the blocks of the classes of the control systems run.
|
|
8
|
+
The measurements, the feedback signals, and the references between the blocks are signal vectors (meas, fbk, and ref), whose layouts are defined in the headers of the control methods (e.g., `MEAS_WIDTH` and `FBK_w_M` in `sm_flux_vector.h`) with their pack and unpack functions.
|
|
9
|
+
The whole-system functions (e.g., `vector_control_system_compute_output`) run the control system in one block; they are used by the reference control systems of the tests.
|
|
10
|
+
Their gate enable (`ControlSystem.set_enable` of *motulator*) selects the standby output of the controllers (e.g., `flux_vector_ctrl_compute_standby_output`) with the measured converter voltage, as in *motulator*; in the blocks of the classes, the block `compute_standby_output` of each controller selects the references.
|
|
11
|
+
|
|
12
|
+
| File | Contents |
|
|
13
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
14
|
+
| `common.c` | `PIController`, `ComplexPIController`, `SpeedController`, `SpeedObserver`, `CurrentLimiter`, `PowerReferenceLimiter`, `RateLimiter`, `PWM` (MPE or MME overmodulation, double or single update) (with the duty-ratio error model `InverterNonlinearity` of the dead time and the threshold voltage, the current direction given by `np.sign` or `tanh(i/i_0)`), the discretization of the observers (`hold_equivalent` and `matched_pole`), root finding (`brentq`), and utility functions |
|
|
15
|
+
| `gradnet.c` | GradNet inference (`FluxMap`, `CurrentMap`, and `CurrentMapWithHarmonics`) |
|
|
16
|
+
| `sm_parameters.c` | `SynchronousMachinePars` and `SaturatedSynchronousMachinePars` (flux linkage, incremental inductances, and current iteration) |
|
|
17
|
+
| `sm_control_loci.c` | `ControlLoci` (MTPA, MTPV, and current-limit loci) |
|
|
18
|
+
| `sm_flux_vector.c` | `FluxObserver`, `SpeedFluxObserver`, `ReferenceGenerator`, `FluxTorqueController`, `FluxVectorController`, and `VectorControlSystem` for synchronous machines |
|
|
19
|
+
| `sm_machine.c` | `SynchronousMachine` with `SpatialSaturatedSynchronousMachinePars` and `MechanicalSystem` |
|
|
20
|
+
| `im_current_vector.c` | `FluxObserver`, `SpeedFluxObserver`, `CurrentReferenceGenerator`, `CurrentController`, `CurrentVectorController`, and `VectorControlSystem` for induction machines |
|
|
21
|
+
| `im_flux_vector.c` | `FluxTorqueController`, `ReferenceGenerator`, `ObserverBasedVHzController` (including open-loop V/Hz control with `L_M = inf`), and `VHzControlSystem` with the `RateLimiter` of the speed reference for induction machines |
|
|
22
|
+
| `gfl_current_vector.c` | Grid-following `CurrentVectorController` (`PLL`, `CurrentController`, and the current and power references) and `GridConverterControlSystem` |
|
|
23
|
+
| `gfm_observer.c` | Disturbance-observer-based grid-forming control (the discrete-time `Observer` and `ObserverBasedGridFormingController`) and `GridConverterControlSystem` |
|
|
24
|
+
| `sim.c` | Native simulation: `Simulation` (the simulation loop, a single model and control system, the gates enabled) with the RK45 solver of scipy, the computational delay (`Delay`), the PWM models `ZOH` and `CarrierComparison`, `VoltageSourceConverter` with a constant DC-bus voltage or a DC-bus model (`DCBus` or `DiodeBridgeDCBus`), `StepSignal`, and the logs of the results |
|
|
25
|
+
| `drive.c` | Native simulation: `Drive` with `SynchronousMachine` (`SynchronousMachinePars` or `SpatialSaturatedSynchronousMachinePars` with a GradNet current map with spatial harmonics) or `InductionMachine` (constant parameters), and `MechanicalSystem` |
|
|
26
|
+
| `grid.c` | Native simulation: `GridConverterSystem` with `LFilter` or `LCLFilter` and `ThreePhaseSource` |
|
|
27
|
+
| `native_sm.c` | Native simulation: the library of synchronous machine drives with flux-vector control (`sm_flux_vector.c` and `drive.c`), with its API for Python |
|
|
28
|
+
| `native_im.c` | Native simulation: the library of induction machine drives with current-vector control or observer-based V/Hz control (`im_current_vector.c`, `im_flux_vector.c`, and `drive.c`) |
|
|
29
|
+
| `native_gfl.c` | Native simulation: the library of grid converter systems with grid-following control (`gfl_current_vector.c` and `grid.c`) |
|
|
30
|
+
| `native_gfm.c` | Native simulation: the library of grid converter systems with grid-forming control (`gfm_observer.c` and `grid.c`) |
|
|
31
|
+
| `native.c` | Native simulation: the helpers of the libraries (the limited voltage reference and the settings of the PWM) |
|
|
32
|
+
|
|
33
|
+
## Native simulation
|
|
34
|
+
|
|
35
|
+
The libraries of the native simulation (`native_<name>.c`) combine the C port of a control system with C models of the system, which `sim.c` simulates as the simulation of *motulator* (`Simulation.simulate`): the control system is run at its sampling instants, the duty ratios pass through the computational delay and the PWM model, and the states are integrated between the sampling and switching instants by a port of the RK45 solver of scipy, taking the same steps.
|
|
36
|
+
A model (`Model` in `sim.h`) and a control system (`ControlSystem`) are interfaces of function pointers, embedded as the first members of the concrete types (e.g., `Drive` in `drive.h`).
|
|
37
|
+
The API functions setting the converter, its DC bus, and its modulator are in `sim.c`, those of the models in `drive.c` and `grid.c`, and those of the control systems in the libraries.
|
|
38
|
+
The states are complex and in the order of *motulator*, and the control system logs the signal groups of *motulator* (`ref` and `fbk`), described by a string of their fields (e.g., `FVC_FIELDS` in `native_sm.c`), so that the Python module fills the time series of the *motulator* objects and post-processes them as *motulator* does.
|
|
39
|
+
A new type of system needs its C model (e.g., a machine in `drive.c`), a library combining the model with the C port of its control system, and a Python module setting the parameters (e.g., `motulator_export/native/_im.py`).
|
|
40
|
+
|
|
41
|
+
The native simulation takes the same solver steps as *motulator*, so the results agree to the rounding errors: about 1e-12 relative to the signal magnitudes, also with the GradNet models, see `tests/test_native.py`.
|
|
42
|
+
With the carrier comparison (`pwm=True`), a rounding error can change a quantized duty ratio and thereby a switching instant, after which the solutions differ more; with a fine quantization (`CarrierComparison(N=2**24)`), they agree to about 1e-7.
|
|
43
|
+
Similarly, the diode bridge (`DiodeBridgeDCBus`) clamps its inductor current at zero, which makes the step sizes sensitive to the rounding errors (differences of about 1e-7 to 1e-5, depending on the system and the simulated time).
|
|
44
|
+
The closed-loop simulations of *motulator* itself are equally sensitive to the rounding errors.
|
|
45
|
+
|
|
46
|
+
## Tests
|
|
47
|
+
|
|
48
|
+
The tests in `tests/` compile the C sources with gcc and compare the results with *motulator* step by step, without PLECS.
|
|
49
|
+
They run in GitHub Actions on every push and weekly against the main branch of *motulator*, to detect changes in *motulator* that must be mirrored here.
|
|
50
|
+
|
|
51
|
+
## GradNets
|
|
52
|
+
|
|
53
|
+
Both *motulator* and the C port evaluate the GradNets in double precision, and the incremental inductances are computed from the analytic Jacobian of the flux map in both, so the tests compare the C port with *motulator* using the relative tolerance of 1e-9.
|
|
54
|
+
The sizes of the networks are limited by `GRADNET_MAX_IN_DIM` and `GRADNET_MAX_EMBED_DIM` in `gradnet.h`, which are checked both when a model is written and at the start of the simulation.
|
|
55
|
+
|
|
56
|
+
## Portability
|
|
57
|
+
|
|
58
|
+
The C port uses the C99 complex type (`complex.h`) in double precision, mirroring the complex space vectors of *motulator*.
|
|
59
|
+
It compiles with gcc, clang, MinGW-w64 (e.g., for `mex` in MATLAB), and the compiler bundled with PLECS, but not with MSVC, and embedded compilers may lack `complex.h`.
|
|
60
|
+
A conversion to a custom complex type or to single precision is straightforward with the C-port tests, but it is left until a concrete embedded target exists.
|