Prototyping MPC For PMSM
Prototyping MPC For PMSM
In this report we describe a setup for fast prototyping of model predictive control (MPC)
algorithms for motion control with permament magnet synchronous motors (PMSM). In
particular, we focus on the methods of finite set model predictive control (FS-MPC), which
impose quite some stringent implementation requirements on the hardware and software.
The intended use is hybrid position and force control in robotics. We give both detailed
instructions on how to use the setup and comments on some experiments already conducted
with this setup.
1
a Star configuration. b Delta configuration.
Figure 1: Model of electrical part of PMSM (the voltage arrows are oriented toward the reference point).
va ia ea sin (npp θ)
iabc = ib , eabc = eb = −npp ωΨm sin npp θ − 2π
vabc = vb , , (4)
3
2π
vc ic ec sin npp θ + 3
cos 2 npp θ − π3 cos 2 npp θ + π3
Ls −Ms −Ms cos 2 (npp θ)
−Ms + Lg cos 2 npp θ − π3 cos 2 npp θ − 2π
L = −Ms Ls cos 2 (npp θ) , (5)
3
cos 2 npp θ + π3 cos 2 npp θ + 2π
−Ms −Ms Ls cos 2 (npp θ) 3
∂L
L0 = . (6)
∂θ
2
The model is then
diαβ
Lαβ = −Rs iαβ − ωL0αβ iαβ − eαβ + vαβ , (8)
dt
dω 3 3 T
J = iT L0 iαβ + i eαβ − Bω + τcog + τex , (9)
dt 4 αβ αβ 2ω αβ
dθ
= ω, (10)
dt
where
h iT
iαβ = iα iβ = K̃iabc , (11)
h iT
vαβ = vα vβ = K̃vabc , (12)
h iT
eαβ = eα eβ = K̃eabc , (13)
and
" "# #
Ls + Ms 0 3 cos(2npp θ) sin(2npp θ)
Lαβ = + Lg , (14)
0 Ls + Ms 2 sin(2npp θ) − cos(2npp θ)
" #
− sin(2npp θ) cos(2npp θ)
L0αβ = 3npp Lg , (15)
cos(2npp θ) sin(2npp θ)
h iT
eαβ = −npp ωΨm sin(npp θ) − cos(npp θ) . (16)
didq ˜ i −e +v ,
Ldq = −Rs idq − ω L̃ dq dq dq dq (18)
dt
dω 3 3 T
J = iT L̃dq idq + i edq − Bω + τcog + τex , (19)
dt 4 dq 2ω dq
dθ
= ω, (20)
dt
where
h iT
idq = id iq = R̃ (npp θ) iαβ , (21)
h iT
vdq = vd vq = R̃ (npp θ) vαβ , (22)
h iT
edq = ed eq = R̃ (npp θ) eαβ , (23)
and
" #
Ls + Ms + 23 Lg 0
Ldq = , (24)
0 Ls + Ms − 23 Lg
3
" #
0 Lg
L̃dq = 3npp , (25)
Lg 0
" #
˜ 0 − Ls + Ms − 32 Lg
L̃dq = npp (26)
Ls + Ms + 32 Lg 0
h iT
edq = npp ωΨm 0 1 . (27)
The cogging torque and the external torque are not considered in this model. The linear DQ model is
obtained by making a two assumptions and approximations, which simplify the nonlinear model into a
linear one. Firstly, the reluctance torque is neglected as it is usually small compared to the synchronous
torque. Secondly, it is assumed that ω does not change too much during controller sampling period, or
over the prediction horizon in case of MPC. This justifies one to consider ω a constant parameter in the
nonlinear terms npp ωLq iq and npp ωLd id . This gives linear time-varying model
Rs Lq
1
− npp ω 0 0 0
Ld Ld Ld
Ld Rs Kb
1
−npp ω − − 0
0
Ac = Lq L q L q , Bc = Lq
(39)
3 Kb B
0 − 0
0 0
2 J J
0 0 1 0 0 0
parametrized by ω. Matrix Dc = 0 is zero matrix and Cc is chosen based on the control objective. Such
linearized model was also used in [2].
4
2.6 Discretization
Discrete-time linear model of PMSM with sampling period Ts
xk+1 = Ad xk + Bd uk , (40)
yk = Cd xk + Dd uk (41)
is obtained from the continuous-time model assuming constant inputs over the sampling period, which
results in
Ad = eTs Ac , (42)
τ =T
Z s
Bd = eτ Ac dτ Bc , (43)
τ =0
Cd = Cc , (44)
Dd = Dc . (45)
When the discrete-time state-space matrices are to be computed online within a limited amount of time,
Euler approximation
Ad ≈ I + Ts Ac , (46)
Bd ≈ Ts Bc (47)
can be used.
2.7 Constraints
The current constraints in the DQ variables are approximated by
This nonlinear constraint is further approximated by set of linear constraints. Specifically, octagon is
used as the approximated feasible region in a similar way as in [3]. The octagon is in fig. 2a and is
described by
Px x ≤ p x , (49)
where
√
+√2 − 1 0
+1 0 I
max
+1 −√ 2 + 1 0 0 I
−1
+√2 − 1 0 0
max
Imax
−1 − 2+1 0 0 Imax
Px = √ , px =
Imax .
(50)
+√2 − 1 +1 0 0 I
+√2 − 1
−1 0 0
max
Imax
−√ 2 + 1 +1 0 0
Imax
− 2+1 −1 0 0
Pu u ≤ p u , (52)
5
a Aprroximated constraints on DQ currents. b Approximated constraints on DQ voltages.
where
√
+√2 − 1
+1 V
max
+1 −√ 2 + 1 V
−1
+√2 − 1
max
Vmax
−1 − 2 + 1 Vmax
Pu = √ , pu =
Vmax .
(53)
+√2 − 1 +1 V
+√2 − 1
−1
max
Vmax
−√ 2 + 1 +1
Vmax
− 2+1 −1
where weighting matrix Q is symmetric and positive semidefinite, weighting matrix R is symmetric and
positive definite, and N is the prediction horizon. In this formulation, the control horizon is the same as
6
prediction horizon. The controller operates with sampling period Ts and the control law is as follows. At
time t, state x(t) is measured and system matrix A is obtained by discretization of the linear continuous-
time state-space matrix, which is parametrized by ω. Matrices B and C stay fixed. The controller then
finds optimal sequence z, from which only ∆u0 is taken to compute u0 = u−1 + ∆u0 . The voltage
vector u0 is then applied to the motor and saved for the next sampling period. If the reference output r
is given for the next sampling period r(t + Ts ) only, constant reference over the whole prediction horizon
is assumed, i.e. rk+1 = r(t + Ts ).
where matrices H, F , G, W , S are derived in appendix [1]. To obtain solution, this formulation can be
easily plugged into standard QP solvers. Choice of matrix C determines reference outputs to be tracked.
z = −H −1 (F a + Gy). (59)
s.t. y ≥ 0, (62)
or
7
s.t. y ≥ 0, (64)
which is a convex QP. The dual problem in this case satisfies strong duality, i.e. the optimal value of the
dual problem equals the optimal value of the primal problem and the duality gap is zero. This can be
proven e.g. by showing that the Slater’s condition is satisfied, i.e. that the problem is strictly feasible.
The dual problem is rewritten as
1 T
min y Qy + dT y (65)
y 2
s.t. y ≥ 0, (66)
−1 T
Q = GH G , (67)
−1
d = W + Sx0 + GH Fa . (68)
such that
quickly converges to the minimum. Due to the projection to the feasible set, y k at every iteration is
dual feasible. However, the choice of λ is subtle and affects the rate of convergence. The fast proximal
gradient is as follows (todo). The optimal solution to the primal QP is obtained from (59).
8
x0 = x(t), (73h)
u−1 = u(t − Ts ), (73i)
rk+1 = r(t + kTs ). (73j)
The main difference is that constraints on uk are replaced such that now uk belongs to a finite set of
vectors, where each vector describes one switching combination in the inverter. Each element of the
vectors corresponds to one phase-leg in the inverter, where +1/2 means it is connected to +vdc /2 and
-1/2 means it is connected to −vdc /2. Matrix B is therefore obtained by discretizing Bc R̃K̃vdc , which
is the continuous-time input matrix multiplied by the reduced Park and Clarke transformation matrices
2
and by DC-bus voltage. In this formulation, the 2-norm squared k∆uk k2 is equal to the number of
switching transitions that happen during step from time k − 1 to k. As there is usually no reason to
penalize some switches of the inverter more than others, one usually chooses R = λI, where λ is a scalar
weighting parameter. This parameter penalizes the switching events and, thus, it can be used to tune
the average steady-state switching frequency. This problem can be solved by enumerating all possible
sequence of the input vector. However, number of such sequences is 8N , which makes the exhaustive
search a feasible option only for very short prediction horizons.
FCS-MPC can also be expressed in a condensed form as
1 T T
min z Hz + xT 0 uT
−1 r1
T
r2T . . . T
rN F z (74a)
z 2
s.t. Gz ≤ W + Sx0 , (74b)
T
z = uT 0 uT
1 . . . uN −1T , (74c)
uk ∈ U, (74d)
x0 = x(t), (74e)
u−1 = u(t − Ts ), (74f)
rk = r(t + kTs ), k = 1, 2, . . . , N, (74g)
where the definition of some matrices slightly differs from CCS-MPC. In [4], the following formulation
is ... (todo)
9
Figure 3: ZedBoard and AD-FMCMOTCON2-EBZ with two coupled PMSM.
• MATLAB, Simulink, HDL Coder, Embedded Coder (available within the student MATLAB license)
• The following MATLAB add-ons:
– MinGW-w64 (MATLAB Support for MinGW-w64 C/C++ Compiler)
– Embedded Coder Support Package for Xilinx Zynq Platform
– HDL Coder Support Package for Xilinx Zynq Platform
Each of the designs is in its own directory and consists of multiple files. In all cases the files are almost
the same.
simulink_design
pmsm_pl.slx
pmsm_ps.slx
init.m
sources
libs
HDLReferenceDesigns
pmsm_lc_lib.slx
10
Figure 4: pmsm_pl.slx
Figure 5: pmsm_ps.slx
Figure 6: LV board
11
Figure 7: MZ split board
9 Experiments
9.1 Instructions for running the experiments
12
Figure 11: Top bar in pmsm_ps.slx
10 Conclusions
10.1 What was achieved
10.2 What remains to do
• Automatic calibration/identification.
• Better way to find zero angle (angle offset).
• Field weakening MPC.
References
[1] Lukáš Černý. “Algorithms for Advanced Motion Control Using Permanent Magnet Synchronous Mo-
tors and Brushless DC Motors”. Master’s Thesis. Faculty of Electrical Engineering, Czech Technical
University in Prague, Aug. 2020.
[2] K. Belda. “Study of predictive control for Permanent Magnet Synchronous Motor drives”. In: 2012
17th International Conference on Methods Models in Automation Robotics (MMAR). 2012, pp. 522–
527. doi: 10.1109/MMAR.2012.6347831.
[3] G. Cimini, D. Bernardini, A. Bemporad, et al. “Online model predictive torque control for Permanent
Magnet Synchronous Motors”. In: 2015 IEEE International Conference on Industrial Technology
(ICIT). Mar. 2015, pp. 2308–2313. doi: 10.1109/ICIT.2015.7125438.
[4] Tobias Geyer. Model Predictive Control of High Power Converters and Industrial Drives. John Wiley
& Sons, 2017. isbn: 978-1-119-01086-9.
13