Skip to content

Commit 58274d5

Browse files
authored
Merge pull request #282 from upb-lea/274-add-some-automated-model-predictive-current-control-to-gem-control
274 automated finite control set current control for PMSM and SynRM is available but runs not with superimposed controllers.
2 parents c2c6e20 + 54094ee commit 58274d5

14 files changed

Lines changed: 1222 additions & 404 deletions

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
## Changed
1010
## Fixed
1111

12-
## [3.0.3] - unreleased
12+
## [3.0.3] - 2025-12-19
1313
## Added
1414
- Automated testing of the existing examples
1515
- Automated testing of the electric motors
1616
- 2x3 phase PMSM environment with tests and documentation
17+
- finite-control-set MPC example
18+
- finite-control-set model predicitve current control as base current control in gem-control for PMSM and SynRM (Currently working not with superimposed speed and/or torque control)
19+
- merged gem-control documentation into the gem docs
1720
## Changed
1821
- Changed minimal required gymnasium version to 0.29.1.
19-
- updated the code of gem-control to be compatible with gymnasium v1.0.0
22+
- Updated the code of gem-control to be compatible with gymnasium v1.0.0
2023
## Fixed
2124
- Updated syntax in the classic_controllers to run with gymnasium v1.0.0
22-
- #263 updated the sb3, mpc and gem-control examples to run with gymnasium v1.0.0
25+
- #263 updated the sb3, mpc and gem-control examples to run with gymnasium v1.0.0
26+
- exchanged widget to ipympl in the examples to run the visualization in visual studio code
2327

2428
## [3.0.2] - 2024-11-19
2529
## Added

docs/parts_gc/api_documentation/gem_control.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GEM Control API Documentation
99
pi_current_controller
1010
torque_controller
1111
pi_speed_controller
12+
mpc_current_controller
1213
gem_adapter
1314
reference_plotter
1415
utils
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
Finite-Control-Set Model Predictive Control (FCS-MPC)
2+
******************************************************
3+
4+
We apply a finite-control set (FCS) model predictive control (MPC) approach to realize
5+
current control of a permanent magnet synchronous motor (PMSM) and Synchronous Reluctance
6+
Motor (SRM) in rotor field-oriented coordinates. Unlike continuous-control set (CCS) MPC,
7+
FCS-MPC directly evaluates a finite set of switching states to optimize the control input
8+
based on a cost function over a prediction horizon.
9+
10+
.. figure:: ../../plots/mpc_structure.png
11+
12+
13+
.. figure:: ../../plots/mpc_scheme.png
14+
15+
16+
With the help of the system model, the output variables are predicted for each possible
17+
switching state in the finite control set. The optimizer evaluates a cost function
18+
(typically the quadratic control error) for all possible switching combinations over
19+
the prediction horizon. The switching state that minimizes the cost function is
20+
selected and applied to the system in the next time step.
21+
22+
Unlike CCS-MPC, FCS-MPC does not require an iterative numerical solver or barrier
23+
functions to handle constraints, as the voltage limits are inherently respected by
24+
evaluating only the physically realizable switching states of the converter.
25+
The computational efficiency of FCS-MPC comes from the direct enumeration and evaluation
26+
of the finite number of possible switching states, rather than solving an optimization
27+
problem with constraints.
28+
29+
30+
MPC Current Controller
31+
======================
32+
33+
.. autoclass:: gem_controllers.mpc_current_controller.MPCCurrentController
34+
:members:
35+
:undoc-members:
36+
:inherited-members:
37+
:show-inheritance:
38+
:member-order: groupwise
39+
40+
41+
Example Usage
42+
=============
43+
44+
The following example demonstrates how to apply the :class:`MPCCurrentController` to
45+
control a permanent magnet synchronous motor (PMSM) using a finite-control-set MPC approach
46+
within the ``gym-electric-motor`` simulation environment.
47+
48+
.. code-block:: python
49+
50+
import numpy as np
51+
import matplotlib
52+
matplotlib.use('Qt5Agg')
53+
from gem_controllers import GemController
54+
import gym_electric_motor as gem
55+
from gym_electric_motor.envs.motors import ActionType, ControlType, Motor, MotorType
56+
from gym_electric_motor.physical_systems import ConstantSpeedLoad
57+
from gym_electric_motor.reference_generators import (
58+
MultipleReferenceGenerator, SwitchedReferenceGenerator,
59+
TriangularReferenceGenerator, SinusoidalReferenceGenerator,
60+
StepReferenceGenerator
61+
)
62+
from gym_electric_motor.visualization.motor_dashboard import MotorDashboard
63+
64+
motor_parameter = dict(r_s=15e-3, l_d=0.37e-3, l_q=1.2e-3, psi_p=65.6e-3, p=3, j_rotor=0.06)
65+
limit_values = dict(i=160 * 1.41, omega=12000 * np.pi / 30, u=450)
66+
nominal_values = {key: 0.7 * limit for key, limit in limit_values.items()}
67+
68+
q_generator = SwitchedReferenceGenerator(
69+
sub_generators=[
70+
SinusoidalReferenceGenerator(reference_state='i_sq', amplitude_range=(0, 0.3), offset_range=(0, 0.2)),
71+
StepReferenceGenerator(reference_state='i_sq', amplitude_range=(0, 0.5)),
72+
TriangularReferenceGenerator(reference_state='i_sq', amplitude_range=(0, 0.3), offset_range=(0, 0.2))
73+
],
74+
super_episode_length=(500, 1000)
75+
)
76+
77+
d_generator = SwitchedReferenceGenerator(
78+
sub_generators=[
79+
SinusoidalReferenceGenerator(reference_state='i_sd', amplitude_range=(0, 0.3), offset_range=(0, 0.2)),
80+
StepReferenceGenerator(reference_state='i_sd', amplitude_range=(0, 0.5)),
81+
TriangularReferenceGenerator(reference_state='i_sd', amplitude_range=(0, 0.3), offset_range=(0, 0.2))
82+
],
83+
super_episode_length=(500, 1000)
84+
)
85+
86+
reference_generator = MultipleReferenceGenerator([d_generator, q_generator])
87+
88+
visu = MotorDashboard(state_plots=['i_sq', 'i_sd', 'u_sq', 'u_sd'], update_interval=10)
89+
90+
motor = Motor(
91+
MotorType.PermanentMagnetSynchronousMotor,
92+
ControlType.CurrentControl,
93+
ActionType.Finite
94+
)
95+
96+
#physical_system_wrapper = [DeadTimeProcessor(steps=1)] # Dead time processor with 1 step delay
97+
#uncomment the above line to activate the DeadTimeProcessor
98+
env = gem.make(
99+
motor.env_id(),
100+
visualization=visu,
101+
load=ConstantSpeedLoad(omega_fixed=1000 * np.pi / 30),
102+
reference_generator=reference_generator,
103+
reward_function=dict(
104+
reward_weights={'i_sq': 1, 'i_sd': 1},
105+
reward_power=0.5,
106+
),
107+
supply=dict(u_nominal=400),
108+
motor=dict(
109+
motor_parameter=motor_parameter,
110+
limit_values=limit_values,
111+
nominal_values=nominal_values
112+
),
113+
#physical_system_wrappers=physical_system_wrapper,
114+
#uncomment the above line to activate the DeadTimeProcessor
115+
)
116+
117+
visu.initialize()
118+
119+
controller = GemController.make(
120+
env=env,
121+
env_id=motor.env_id(),
122+
base_current_controller="MPC",
123+
block_diagram=False,
124+
prediction_horizon=1,
125+
w_d=0.5,
126+
w_q=2.0
127+
)
128+
129+
(state, reference), _ = env.reset()
130+
cum_rew = 0
131+
132+
for i in range(10000):
133+
env.render()
134+
action = controller.control(state, reference)
135+
(state, reference), reward, terminated, truncated, _ = env.step(action)
136+
cum_rew += reward
137+
if terminated:
138+
(state, reference), _ = env.reset()
139+
controller.reset()
140+
141+
print('Reward =', cum_rew)
142+
env.close()
143+
144+
Simulation Results
145+
==================
146+
147+
The following figures illustrate the performance of the FCS-MPC controller in current control of the PMSM under varying reference trajectories.
148+
The controller accurately tracks both the d- and q-axis current references while ensuring smooth control actions.
149+
150+
.. figure:: ../../plots/MPC_Time_Plots.png
151+
152+
FCS-MPC current tracking of *i<sub>d</sub>* and *i<sub>q</sub>*.
153+
154+
The results show that the finite-control-set MPC effectively minimizes the current tracking error within each sampling period while satisfying the converter switching
155+
constraints. Compared to conventional PI controllers, the FCS-MPC achieves faster dynamic response and improved steady-state performance without overshoot.

docs/plots/MPC_Time_Plots.png

115 KB
Loading

docs/plots/mpc_scheme.png

52.7 KB
Loading

docs/plots/mpc_structure.png

25.8 KB
Loading

0 commit comments

Comments
 (0)