A Microcontroller Implementation of Constrained Model Predictive Control
A Microcontroller Implementation of Constrained Model Predictive Control
International Scholarly and Scientific Research & Innovation 5(8) 2011 878 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
benefit from the power features and the flexibility of the Here Hp is the prediction horizon, Hc is the control horizon,
STM32F103xB devices. The STM32 keil starter kit based on a λ11 is the weighting factor, y(k + j|k) is described in equation
JTAG interface and the STM32 board was used to implement 3, w(k +j) denotes the set-point at time k +j, umin and umax
the proposed constrained MPC firmware. Since the conversion are respectively the low and the high levels of the control
from m files (Matlab) to C file decreases the performance of action and Δumin and Δumax are are respectively the low
the execution time, in this work, we choose to develop all and the high levels of the control increments.
the proposed framework with Keil development tools designed It is easier to use the matrix form. Therefore, the output
for ARM processor-based microcontroller devices working sequence on Hp prediction horizon can be written as follows:
with C/C++ language. In order to test the effectiveness of
our proposed constrained MPC software, the PID antiwindup Y = LΔU + M x(k) (6)
was also implemented in the STM32 and compared with the
in which:
proposed constrained MPC software.
The rest of this paper is organized as follows: in section
II, a theoretical background which consists of a review of Y = [
y (k + 1|k), y(k + 2|k), . . . , y(k + Hp |k)]T ,
the MPC method as well as the interior point method are ΔU = [Δu(k), Δu(k + 1), . . . , Δu(k + Hc − 1)]T ,
presented. Section III states the hardware and the software
It is assumed that there is no control action after time k +
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
Hp
Hc where :
2 2
J1 = (
y (k+j|k)−w(k+j)) +λ11 Δu(k+j−1) (4)
j=1 j=1 Q = 2(LT L + Λ) ,
subject to linear inequality constraints on the system inputs: Λ1 = λ11 Ic ,
c = (L M x − L W ).
T T
International Scholarly and Scientific Research & Innovation 5(8) 2011 879 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
where mc is the number of constraints (in our case mc = Algorithm 1: the unfeasible Interior Point method
4Hc since only the constraints on the control and the control Step 1 Given (v 0 , λ0 , t0 ) with (λ0 , t0 ) > 0.
increment are considered).
Step 2 At the k-th iteration step, solve the increments
(Δv k, Δλk , Δtk ) as follows:
k
Q JT Δv k r1
=
J −(Λk )T k ) Δλk r2k
and
Δtk = −tk + (Λk )−1 (σ k μk e − T k Δλk ),
B. The interior point method
where:
r1k = −Qv k − J T λk − c,
)−1 e,⎤
r2k⎡= −Jv k + g − σ k⎤μk (Λk⎡
The connections between optimization and control theory
λ1
k
1
have been explored by many researchers and optimization ⎢ . ⎥ ⎢ . ⎥
algorithms have been applied with success to optimal control Λ =⎣
k .. ⎦, e = ⎣ .. ⎦ .
[21]. λkmc ⎤ 1
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
⎡
tk1
In this paper, we apply the unfeasible interior point method ⎢ .. ⎥
in the proposed constrained MPC software microcontroller Tk = ⎣ . ⎦,
implementation. The special case of the optimality conditions tkmc
that must be satisfied by solutions of linear program problems for some σk ∈ (0, 1) which is often confined to
of equations 8 and 9 are knwown as the Karush Kuhn Tucker the range [10−3 , 0.8].
(KKT) conditions [20]:
Remark: The increments (Δv k , Δλk ) can also
be solved using these equations:
A. STM32F103RB microcontroller
The steps of the unfeasible interior point method for solution First of all, we have to clarify why the choice of a micro-
of equations 8 and 9 are listed in algorithm 1. controller? Most of the proposed works of the implementation
International Scholarly and Scientific Research & Innovation 5(8) 2011 880 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
of the predictive control method use only the FPGA or the •MCBSTM32 Evaluation Board which includes:
PLC. – STM32F103 with 72 MHz maximum Cortex-M3
May be this is due to the complexity of use of the microcon- processor based MCU with 128KB Flash, 20KB
troller and the huge amount of time needed to implement such RAM, and 49 GPIO.
method above all when incorporating constraints. However, by – USART, CAN, USB Interfaces and SD/MMC card
proposing an optimized algorithm with a reducing size of code slot.
and by choosing a low cost microcontroller with a low power – 16x2 LCD panel, 8 LED’s, 3 push buttons, and
consumption, one can takes advantages of such miniaturized scratchpad area.
device. • A JTAG interface supporting Cortex-M3 Serial Wire
Moreover, the choice to adopt STM32 is based on trade Debugger (SWD) and Serial Wire Viewer (SWV) modes.
offs between price (since the STM32 discovery costs few
In order to load the program into the STM32 device, the
dollars), performance and low power consumption. Indeed,
ULINK-ME is used. Moreover, test data and test results can
the STM32F103RB performance line family incorporates the
be transferred between STM32 and the PC through the RS232
high-performance ARM Cortex-M3 32-bit RISC core operat-
serial link via the USART communication protocol.
ing at a maximum of 72 MHz frequency, high-speed embedded
memories (Flash memory of 128 Kbytes size and SRAM of
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
20 Kbytes size), and an extensive range of enhanced I/Os and C. Keil development tools
peripherals connected to two APB buses [22]. Furthermore, Keil is a software developement tools. It makes C/C++
it has 12-bit ADCs, three general purpose 16-bit timers plus compilers, debuggers, integrated environments, middleware,
one PWM timer, as well as standard and advanced com- real-time kernels, simulation models, and evaluation boards
munication interfaces: two I2Cs and SPIs, three Universal for ARM, Cortex-M processor families. The used version is
synchronous asynchronous receiver transmitter USARTs, an the μVision 4. The μVision 4 screen provides a menu bar for
USB and a CAN peripherals. In addition, the STM32F103RB command entry, a tool bar where can select command buttons,
has configurable and flexible power management features. The and windows for source files, dialog boxes, and information
power consumption or hardware can be managed to match displays. This version has two operating modes:
the system’s requirements. Power management is provided • Build Mode: Allows to translate all the application files
via clock control to the CPU and individual peripherals. and to generate executable programs.
This device supports the following three global power control • Debug Mode: Provides a debugger for testing the appli-
modes. cation.
The STM32F10xxx devices feature three low-power modes: This tool has the ability to communicate information to the
sleep mode (CPU clock off, all peripherals including Cortex- serial port of the PC monitor.
M3 core peripherals like NVIC, SysTick, etc. are kept run-
ning), stop mode (all clocks are stopped) and the standby IV. F IRMWARE DEVELOPMENT
mode (1.8V domain powered-off). In addition, the power
consumption in run mode can be reduced by one of the In the proposed algorithm, the constrained Model Predictive
following means: slowing down the system clocks, gating the Control is implemented (see Fig. 2).
clocks to the APB and AHB peripherals when they are unused.
This is obviously an attractive property to industry as saving
power and CPU high frequency can be a very costly affair
indeed.
International Scholarly and Scientific Research & Innovation 5(8) 2011 881 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
TABLE III
we choose to implement all the predictive control algorithm M ATRIX P RODUCT FUNCTION DESCRIPTION
in C/C++ code. In spite of its complexity, this method will be
Function name Matrix Product
more optimized. Function prototype void Matrix Product(float *P1 , float *P2 ,
In order to use the MPC controller software, some steps float *P3 , int n1 , int p1 , int m1 )
should be followed: Behavior description Compute the product of two matrices
Input P1 : the first left matrix,
1) define the number of states, the number of iterations, the P2 : the second right matrix,
prediction horizon, the control horizon and the weighting P3 : the product matrix,
n1 : the number of lines of P1 ,
factor λ1 , p1 : the number of lines of P2 ,
2) define the state matrix, the input matrix and the output m1 : the number of columns of P2 .
matrix of the model, Output None
3) fix the initial values of the control signal and the state,
TABLE IV
4) solve the minimization problem of equations 8 and 9 M ATRIX S UM FUNCTION DESCRIPTION
and find the optimal control action using the unfeasible
Function name Matrix Sum
interior point method, Function prototype void Matrix Sum(float *S1 , float *S2 , float
5) Test the convergence of the interior point algorithm, if it *S3 , int nl , int nc )
converges inject the control action in the plant in order to Behavior description Compute the sum of two matrices
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
International Scholarly and Scientific Research & Innovation 5(8) 2011 882 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
TABLE VII
M ATRIX I NVERSE FUNCTION DESCRIPTION A. A First order plant
Function name Matrix Inverse The first example is a simple first order system which has
Function prototype void Matrix Inverse(float *M, float *Inver, the following discrete time model:
int nlines)
Behavior description Compute the inverse of a matrix 0.09516z −1
M : the input matrix,
y(k) = u(k)
Input 1 − 0.9048z −1
Inver: the inverted matrix,
nlines: the number of lines of M . The closed loop simulation results are obtained with the
Output None following constrained MPC and anti windup PID parameters:
Hp = 5, Hc = 1, λ1 = 6, Kp = 5.7, Ki = 0.1 and
Kd = 0.25, starting from: u(0) = u(1) = 0.1 and x0 = [0 0]T .
flash memory. In order to allow the implementation of such The PID gains are computed using the Takahashi method. In
a computationally expensive controller on chip, we propose addition, the following constraints are considered : 0.07 ≤
reducing the frequency of the STM32 CPU to 24MHz while u(k) ≤ 3.2 for the MPC and the PID and −2 ≤ Δu(k) ≤ 2
maintaining good performance. This value is the maximum for the MPC.
frequency of STM32 discovery which is characterized by a The Fig. 3 presents the closed loop simulation results of the
very low price and additional peripherals comparing with the first order system.
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
(b)
in which:
1 Kp N
ud (k) = ud (k − 1) − , Fig. 3. Closed-loop simulation results for the first order plant
1 + Kd Ts 1 + Kd N
Ts
u0 (k) = Kp ε(k) + ui (k) + Kp ε(k − 1) + ud (k),
Ti B. A second order plant
ε(k) = w(k) − y(k), In this second example, we consider a classical angular
Ts Td positioning system. The system is consisted of a rotating
Ti = , Kd = ,
Ki Ts antenna at the origin of the plane, driven by an electric motor.
The control problem is to use the input voltage to the motor
and N ≥ 5 and Ts is the sampling time.
to rotate the antenna so that it is always points in the direction
In this work, we found that solving the QP problem as in
of a moving object in the plane [3].
8 and 9 as it is commented in [14] sometimes gave incorrect
The motion of the antenna can be described by the following
results. In fact, in order to overcome this limitation, we re-
discrete-time equation obtained from their continuous time
scaled the QP problem as follows: counterparts by discretization, using a sampling time of 0.1s
and Euler’s first order approximation for the derivative and
1 based on the observer canonical form:
min( ΔU T QΔU cT ΔU )
+ (13)
2
s.t: θ(k + 1) 1 0.1
x(k + 1) = = x(k)
JΔU ≤
g (14) θ̇(k + 1) 0 0.9
0
where : Q = αQ, c = αc , J = βJ and g = βg, in which + u(k)
0.0787
α and β are scalar constants. It is observed that the scaling
y(k) = 1 0 x(k)
of Q, c, J and g matrices to a range of ±1 do not change
the solution of the original QP problem, however it allows The closed loop simulation results are obtained with the
obtaining accurate solutions. following constrained MPC and anti windup PID parameters:
International Scholarly and Scientific Research & Innovation 5(8) 2011 883 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
(b)
3
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
1
2
0.5
1
set−point output PID output MPC
0
0 Δumax2 Δumax1 Δu1 Δu2
0 50 100 150 200
Iterations
−0.5
0 50 100 150
(a) Iterations
(c)
30
International Scholarly and Scientific Research & Innovation 5(8) 2011 884 scholar.waset.org/1307-6892/4067
World Academy of Science, Engineering and Technology
International Journal of Electrical and Information Engineering
Vol:5, No:8, 2011
VII. C ONCLUSION [14] K. Ling, S. Yue, and J. Maciejowski, “A fpga implementation of model
predictive control,” in Proceedings of American Control Conference,
Two frameworks for embedding constrained model predic- 2006.
[15] K. Ling, B. Wu, and J. Maciejowski, “Embedded model predictive
tive control and PID anti windup controller on a performed control (mpc) using a fpga,” in Proceedings of the 17th World Congress:
STM32 microcontroller have been provided. The STM32 Keil The International Federation of Automatic Control, Seoul, Korea, 2008.
starter kit was used to implement both firmwares. Two exam- [16] U. R. Y. Jayaraman, “Fpga implementation of predictive control strategy
for power factor correction,” in Proceedings of World Academy of
ples were used to test the proposed software performances. Science, Engineering and Technology, 2008.
Hence, an efficient implementation of this code yields a low [17] G. Palomo, K. Hilton, and J. Rossiter, “Predictive control implementa-
computational burden with a high speed. Indeed based on the tion in a plc using the iec 1131.3 programming standard,” in Proceedings
of American Control Conference, 2009.
simulation results, we noticed that the proposed softwares con- [18] A. K. Abbes, F. Bouani, and M. Ksouri, “A microcontroller implementa-
trol successfully the processes with a good set-point tracking. tion of model predictive control,” in Proceedings of International Con-
A comparison between both softwares has also been done. ference on Computer, Electrical, and Systems Sciences, and Engineering,
WASET, 2011.
Although the low computational burden of the PID anti windup [19] P. Lascaux and R. Thodor, Analyse numerique matricielle appliquee
software comparing to this of the constrained MPC, the last l’art de l’ingenieur, tome 1. Dunod, 2004.
one gives better control performances such as output prediction [20] C. V. Rao, S. J. Wright, and J. B. Rawlings, “Application of interior-point
methods to model predictive control,” Journal of Optimization Theory
and less control signal oscillation. This comparison results and Applications, vol. 99, no. 3, pp. 723–757, 1998.
International Science Index, Electrical and Information Engineering Vol:5, No:8, 2011 waset.org/Publication/4067
should allow the use of MPC to be pioneered in an increasingly [21] S. Wright, “Applying new optimization algorithms to model predictive
wide range of process industries where the computational load control,” in Fifth International Conference on Chemical Process Control,
1997.
has been considered too great and encourage to implement [22] STMicroelectronics, “Datasheet stm32f103x8, stm32f103xb,” 2009.
such control method in microcontrollers. There are still much [Online]. Available: http://www.st.com/internet/mcu/family/141.jsp
detailed analysis and tests to be done, which should handle [23] A. Voda and S. Gentil, Regulateur PID analogique et numeriques.
Technique de l’ingenieur, 1999.
multivariable systems and a power consumption study in all [24] S. Sung, J. Lee, and I. Lee, Process Identification and PID Control.
possible low power modes has to be investigated. John Wiley and Sons (Asia), 2009.
R EFERENCES
[1] E. Camacho and C. Bordons, Model Predictive Control. London:
Springer, 2004.
[2] P. Campo and M. Morari, “Robust model predictive control,” in Pro-
ceedings of American Control Conference, 1987, pp. 1021–1026.
[3] M. Kothare, V. Balakrishnan, and M. Morari, “Robust constrained model
predictive control using linear matrix inequalities,” Automatica, vol. 32,
no. 10, pp. 1361–1379, 1996.
[4] Z. Wan and M. Kothare, “Robust output feedback model predictive
control using linear matrix inequalities,” Journal of Process Control,
vol. 12, pp. 763–774, 2001.
[5] Y. Wang and J. Rawlings, “A new robust model predictive control
method 1: theory and computation,” Journal of Process Control, vol. 14,
pp. 231–247, 2002.
[6] A. Casavola, D. Famularo, and G. Franze, “Robust constrained predictive
control of uncertain norm-bounded linear systems,” Automatica, vol. 40,
pp. 1865–1876, 2004.
[7] G. Pannochia, “Robust model predictive control with guaranteed set
point tracking,” Journal of Process Control, vol. 14, pp. 927–937, 2004.
[8] T. Alamo, D. Ramirez, and E. Camacho, “Efficient implementation of
constrained min-max model predictive control with bounded uncertain-
ties: a vertex rejection approach,” Journal of Process Control, vol. 15,
pp. 149–158, 2005.
[9] A. Kheriji, F. Bouani, and M. Ksouri, “Efficient implementation of
constraind robust model predictive control using a state space model,”
in Proceedings of International Conference on Informatics in Control,
Automation and Robotics (ICINCO), 2010.
[10] A. Kheriji, F. Bouani, and M.Ksouri, “Ggp approach to solve non convex
min-max robust model predictive controller for a class constrained mimo
systems,” in Proceedings of the International Workshop on Symbolic
and Numerical Methods, Modeling and applications to circuit design,
(SM2ACD) CEDA competition, 2010.
[11] A. Kheriji, F. Bouani, and M. Ksour, “A ggp approach to solve non
convex min-max predictive controller for a class of constrained mimo
systems described by state-space models,” International Journal of
Control Automations and Systems (IJCAS), vol. 9, no. 3, 2011, will
appear in June.
[12] S. Karacan, H. Hapoglu, and M. Alpbaz, “Generalized predictive control
to a packed distillation column for regulatory problems,” in European
Symposium on Computer Aided Process Engineering, 1998.
[13] G. D. Nicolao, L. Magni, and R. Scattolini, “Robust predictive control of
systems with uncertain impulse response,” Automatica, vol. 32, no. 10,
pp. 1475–1479, 1996.
International Scholarly and Scientific Research & Innovation 5(8) 2011 885 scholar.waset.org/1307-6892/4067