Professional Documents
Culture Documents
Email: endric@endric.com
AbstractThis paper describes an implementation strategy solution of a quadratic program (QP) and a combined im-
of nonlinear model predictive controller for FPGA systems. A plementation on an FPGA as well as a CPU was presented
high-level synthesis of a real-time MPC algorithm by means of in [11]. A similar approach was demonstrated in [12] where
the M ATLAB HDL Coder as well as the Vivado HLS tool is only an FPGA implementation was used. The results in both
discussed. In order to exploit the parallel processing of FPGAs, contributions rely on a oating point notation for the number
the included integration schemes are parallelized using a xed-
representation within the MPC scheme. In contrast, [13] and
point iteration approach. The synthesis results are demonstrated
for two different example systems. [14] demonstrated an FPGA realization of a QP based MPC by
means of a xed-point number representation. A different MPC
framework that followed the ideas of a fast gradient method
I. I NTRODUCTION was discussed in [15]. The approach was implemented on
common FPGAs from Xilinx where computation times in the
The solution of an optimal control problem (OCP) along a
microsecond range were achieved. However, all approaches so
moving horizon is the basis of model predictive control (MPC)
far used a linear MPC for controlling linear systems. Regarding
[1][3]. This modern control method has become popular in
the nonlinear case, a rst discussion on FPGA implementation
the recent years due to its ability to handle nonlinear multiple
strategies of a nonlinear MPC scheme can be found in [16].
input systems with constraints. However, the computational
effort that is typically required to solve the underlying OCP This paper describes a high-level synthesis strategy for
usually limits the use of nonlinear MPC to sufciently slow implementing a nonlinear model predictive controller on FPGA
and/or low-dimensional systems. systems. The discussion is based on a real-time MPC algorithm
that is converted into the register transfer level by means of the
A suitable way to circumvent this problem is the use M ATLAB HDL Coder and the Vivado HLS tool, respectively.
of real-time MPC approaches and algorithms existing in the The applied algorithm contains the numerical solution of the
literature [4][7]. These methods implement different solution necessary optimality conditions. For the underlying numerical
strategies, as for instance a continuation method in com- integrations, an approach to parallelize the computation is
bination with the generalized minimum residual (GMRES) presented that follows the ideas of a xed-point iteration.
method [4] or a real-time iteration scheme using a Newton- Synthesis results for two different examples demonstrate the
type framework [5]. While [4][7] address nonlinear systems, potential of the presented methods.
linear model predictive control approaches with real-time ap-
plicability are presented in [8], [9].
II. MPC SCHEME AND ALGORITHM
A more intuitive way to speed up the computation in MPC This section introduces the problem formulation and briey
frameworks is to use suitable hardware systems that exploit describes the real-time MPC algorithm that is used for a
certain algorithmic properties of an applied approach. In terms synthesis procedure on an FPGA.
of computation times in combination with parallel processing,
FPGAs (eld-programmable gate array) are a serious alterna-
A. Problem formulation
tive to common sequentially working CPUs (central processing
unit). Due to the inherent parallel processing of programmable The MPC scheme considered in this contribution repeat-
logic in FPGAs, a high data throughput with low latency can edly solves an input constrained OCP of the following form:
be achieved [10]. However, the conversion of a general MPC
algorithm into digital circuits of an FPGA is a challenging tk +T
task and hence requires a thorough analysis of the used model min J(u, xk ) = V (x(tk + t)) + L(x(t), u(t)) dt (1a)
u() tk
predictive control scheme in particular in the nonlinear MPC
case. s.t. x(t) = f (x(t), u(t)), x(tk ) = xk (1b)
u(t) [u , u+ ], t [tk , tk + T ], (1c)
There exist already some contributions regarding the im-
plementation of linear model predictive controller on FPGA where T > 0 denotes the prediction horizon and x Rn
systems in the literature. An MPC framework based on the and u Rm are the states and controls of the system,
663
the integration steps (9) are summed up in the following way
1
x x 0 , x 1 , u0 , u1
.. ..
. = a + Kz + h . (10)
N
N 1 N N 1 N
x x ,x ,u ,u
=:z =:(z)
generated HDL code can be implemented and tested on an where I Rnn is the unit matrix and z RnN comprises the
FPGA system. states at all discretization points i = 1, . . . , N . The integration
is then approximated by means of the xed-point iteration
2) Synthesis procedure with Vivado HLS: In order to use
The MPC algorithm from Section II-B relies on the forward xi+1 = xi + hf xi , ui , i = 0, . . . , N 1 (14)
and backward integration of the system and adjoint dynamics,
respectively. Generally, the steps within numerical integration T
with the xed step size h = N . The associated xed-point
schemes are performed in a sequential manner and thus cannot iterations (12) and (13), respectively, then follow by simply
take advantage of the parallel processing of an FPGA system. using the system function f as iteration function, i.e. = f .
To this end, a parallel integration approach is discussed where The xed-point formulation for the integration of the adjoint
ideas of the xed-point iteration method are used. dynamics (5b) can be obtained in a similar way. According
to (5b) and the Euler forward method (cf. (14)), the related
An integration step of both explicit and implicit integration iteration function for integrating the adjoint dynamics is =
schemes (e.g. Euler forward/backward approach, Runge-Kutta Hx . Also note that due to the backward integration a negative
methods) with the step size h is given by step size h = NT
has to be chosen.
664
aC 1 l [m]
0
States
l [rad]
r -1
r [m]
-2
0 1 2 3 4 5
aR
3 aC [m/s2 ]
2
Fig. 2. Schematics of the overhead crane.
Controls
1
0
-1
A. Overhead crane -2 aR [m/s2 ]
-3
Figure 2 shows the schematics of a two-dimensional over- 0 1 2 3 4 5
head crane consisting of a moving cart and a mounted rope that
can also be altered in length. The nonlinear system dynamics
of the overhead crane is given by [22] 20
1
Cost
r = aC , l = aR , = g sin + aC cos + 2l (15) 10
r
with the gravitational constant g. The states x R6 of the
system are the cart position x1 = r, the rope length x3 = l 0
0 1 2 3 4 5
and the angle x5 = to the vertical direction as well as the
Time t [s]
corresponding velocities x2 = r, x4 = l and x6 = . The cart
and the rope accelerations u1 = aC and u2 = aR serve as Fig. 3. MPC trajectories for the overhead crane.
control inputs which are subject to the constraints
T T
u = 3 m/s2 , 3 m/s2 , u+ = 3 m/s2 , 3 m/s2 . (16)
reactions of the educt A to the desired product B and the
The integral and terminal cost in (1a) are set to parallel reactions to the undesired byproducts C and D. A
nonlinear model of the reactor based on mass and energy
V (x) = xT P x, L(x, u) = xT Qx + uT Ru (17)
balances is given by [23]
with P = Q = diag (10, 1, 10, 1, 10, 1) and R =
cA = k1 ()cA k2 ()c2A + (cin cA ) q (21a)
diag (0.01, 0.01). Additionally, x := x xSP and u :=
u uSP denote the distance to a desired setpoint xSP and cB = k1 () (cA cB ) cB q (21b)
uSP , respectively. The corresponding prediction horizon, the = h(cA , cB , ) + (c ) + (in ) q (21c)
sampling time, as well as the number of discretization points c = ( c ) + Q (21d)
and gradient iterations are
where cA and cB denote the concentrations of educt A and
T = 1 s, N = 30, t = 1 ms, Ngrad = 2. (18) product B and and c are the temperatures within the reactor
Simulation results for the stabilization of the setpoint and the cooling jacket, respectively. The dilution rate and the
665
cooling power are the control inputs u = [q, Q]T [u , u+ ] 2000 [C] 110
Concentrations
Temperatures
constrained by c [C]
T T 105
u = 3 h1 , 9000 kJ/h , u+ = 35 h1 , 0 kJ/h . (22) 1500 cA [kmol/m3 ]
100
The enthalpy h(cA , cB , ) in (21c) is cB [kmol/m3 ]
1000 95
h(cA , cB , ) = k1 () (cA HAB + cB HBC )
(23) 0 2000 4000 6000
+k2 ()c2A HAD 6 0
Cooling power
and the reaction rates k1 () and k2 () are modelled with the
Dilution rate
5 q [h1 ] -500
Arrhenius functions
4
Ei
ki () = ki0 exp , i = {1, 2}. (24) Q [kJ/h] -1000
/C + 273.15 3
The parameters of the CSTR can be found in [23]. Investi- 2 -1500
gations in view of an FPGA implementation revealed that the 0 2000 4000 6000
exponential functions in the Arrhenius terms (24) require many 100
Cost (scaled)
bits for the number representation. Hence, the functions are ap-
proximated within the region of operation [80 C, 120 C]
by the 4-th order polynomials 50
4
j
ki () aij (/C 100) . (25)
j=0
0
0 2000 4000 6000
The cost (1a) is also chosen quadratically (cf. (17)) with Time t [s]
the weights
P =
Q = diag (0.2, 1, 0.5, 0.2) and R =
diag 0.5, 5 103 . The prediction horizon, the sampling time, Fig. 5. MPC trajectories for the CSTR.
as well as the number of discretization points and gradient
iterations are set to
1) M ATLAB HDL Coder: The synthesis results for the
T = 1200 s, N = 30, t = 1 s, Ngrad = 2. (26) overhead crane obtained with the M ATLAB HDL Coder are
Figure 5 illustrates the simulation results for the model pre- illustrated in Table II where the sequential integration scheme
dictively controlled CSTR performing a setpoint change from was used. The approximated number of required elements was
the initial state estimated after the HDL code generation by means of the
T software tool Vivado (version 2013.2, 64-bit) from Xilinx.
x0 = 2.02 kmol/m3 , 1.07 kmol/m3 , 100 C, 97.1 C (27)
TABLE II. M ATLAB HDL CODER SYNTHESIS RESULTS FOR THE
to the desired setpoint OVERHEAD CRANE .
T
xSP = 1.37 kmol/m3 , 0.95 kmol/m3 , 110 C, 108.6 C Examples No. of DSPs No. of LUTs No. of FFs No. of BRAMs
T (28)
uSP = 5 h1 , 1190 kJ/h .
Crane 18128 1623531 1557 1
666
TABLE III. V IVADO HLS SYNTHESIS RESULTS FOR THE OVERHEAD
CRANE AND THE CSTR .
[2] E. F. Camacho and C. Bordons, Model Predictive Control. London:
Springer, 2003.
Comp. Integration [3] L. Grune and J. Pannek, Nonlinear Model Predictive Control: Theory
Examples DSPs LUTs FFs BRAMs
time [ms] scheme and Algorithms. London: Springer, 2011.
102 37704 39828 19 50.6 sequential [4] T. Ohtsuka, A continuation/GMRES method for fast computation of
Crane
160 94220 109999 19 10.4 xed-point nonlinear receding horizon control, Automatica, vol. 40, no. 4, pp.
168 32627 33468 12 60.4 sequential 563574, 2004.
CSTR
330 120460 116493 12 20.0 xed-point
[5] B. Houska, H. J. Ferreau, and M. Diehl, ACADO Toolkit An Open
Source Framework for Automatic Control and Dynamic Optimization,
Optimal Control Applications and Methods, vol. 32, no. 3, pp. 298312,
With regard to the synthesis procedure, the word length for 2011.
each state and control variable was set to 28 bit (20 fractional [6] D. DeHaan and M. Guay, A real-time framework for model-predictive
bit) for the crane example and to 24 bit (14 fractional bit) control of continuous-time nonlinear systems, IEEE Transactions on
for the CSTR, respectively. The remaining synthesis settings Automatic Control, vol. 52, no. 11, pp. 20472057, 2007.
(pipeline techniques, degree of parallelism) were chosen in [7] V. M. Zavala and L. Biegler, The advanced-step NMPC controller:
such a way as to obtain an acceptable tradeoff between Optimality, stability and robustness, Automatica, vol. 45, no. 1, pp.
8693, 2009.
required resources and computation times. The related results
[8] Y. Wang and S. Boyd, Fast model predictive control using online opti-
are illustrated in Table III. The results reveal that the xed- mization, IEEE Transactions on Control Systems Technology, vol. 18,
point integration scheme requires more resources than the no. 2, pp. 267278, 2010.
sequential procedure due to the parallelization. It can also be [9] A. Domahidi, A. U. Zgraggen, M. N. Zeilinger, M. Morari, and
observed that the model predictively controlled crane as well C. N. Jones, Efcient interior point methods for multistage problems
as the CSTR in combination with the sequential integration arising in receding horizon control, in Proceedings of the 51th IEEE
scheme can be implemented on both reference FPGAs (cf. Conference on Decision and Control, 2012, pp. 668674.
Table I). However, a corresponding xed-point version can [10] P. K. Chan and S. Mourad, Digital Design Using Field Programmable
Gate Arrays. New Jersey: Prentice Hall, 1994.
only be used on the Artix FPGA.
[11] H. Chen, F. Xu, and Y. Xi, Field programmable gate array/system
3) Comparison: Computation times of the MPC with se- on a programmable chip-based implementation of model predictive
quential integration running on a standard PC2 and a dSPACE3 controller, IET Control Theory and Applications, vol. 6, no. 8, pp.
system are shown in Table IV. The results of the FPGA 10551063, 2012.
implementation with the xed-point integration scheme show [12] J. L. Jerez, G. A. Constantinides, E. C. Kerrigan, and K.-V. Ling, Par-
allel MPC for real-time FPGA-based implementation, in Proceedings
that lower computation times can be achieved and hence of the 18th IFAC World Congress, 2011, pp. 13381343.
demonstrate the potential of the nonlinear MPC on an FPGA. [13] K. Basterretxea and K. Benkrid, Embedded high-speed model pre-
TABLE IV. C OMPUTATION TIMES OF THE MODEL PREDICTIVELY dictive controller on a FPGA, in Proceedings of the 2011 NASA/ESA
CONTROLLED CRANE AND CSTR . Conference on Adaptive Hardware and Systems, 2011, pp. 327335.
[14] A. G. Wills, G. Knagge, and B. Ninness, Fast linear model predictive
Computation time [ms] control via custom integrated circuit architecture, IEEE Transactions
Examples
PC dSPACE
on Control Systems Technology, vol. 20, no. 1, pp. 5971, 2012.
[15] J. L. Jerez, P. J. Goulart, S. Richter, G. A. Constantinides, E. C.
Crane 26 172
Kerrigan, and M. Morari, Embedded predictive control on an FPGA
CSTR 29 180
using the fast gradient method, in Proceedings of the 2013 European
Control Conference, 2013.
[16] G. Knagge, A. Wills, A. Mills, and B. Ninness, ASIC and FPGA
V. C ONCLUSION
implementation strategies for model predictive control, in Proceedings
This paper described an implementation strategy of a of the 2009 European Control Conference, 2009, pp. 144149.
nonlinear model predictive control scheme on FPGA systems. [17] D. E. Kirk, Optimal Control Theory: An Introduction. Mineola: Dover
Based on a real-time MPC algorithm, two different synthesis Publications, 1970.
procedures using the M ATLAB HLD Coder as well as the [18] J. C. Dunn, On L2 sufcient conditions and the gradient projection
method for optimal control problems, SIAM Journal on Control and
tool Vivado HLS were discussed. Synthesis results for two Optimization, vol. 34, no. 4, pp. 12701290, 1996.
examples were illustrated in order to demonstrate the potential [19] K. Graichen and B. Kapernick, A real-time gradient method for
of an FPGA implementation of a nonlinear MPC. nonlinear model predictive control, in Frontiers of Model Predictive
Control, T. Zheng, Ed. InTech, 2012, pp. 928, http://www.intechopen.
Future work concerns improving the synthesis results by com/books/frontiers-of-model-predictive-control.
using further optimization strategies in order to reduce the
[20] K. Graichen and A. Kugi, Stability and incremental improvement of
required number of logic elements as well as the computation suboptimal MPC without terminal constraints, IEEE Transactions on
time. Moreover, the discussed real-time MPC scheme shall be Automatic Control, vol. 55, no. 11, pp. 25762580, 2010.
implemented and tested on a common used FPGA system. [21] J. P. Elliott, Understanding Behavioral Synthesis: A Practical Guide
to High-Level Design, 2nd ed. Boston: Kluwer Academic Publishers,
R EFERENCES 2000.
[1] D. Q. Mayne, J. B. Rawlings, C. V. Rao, and P. O. M. Scokaert, Con- [22] B. Kapernick and K. Graichen, Model predictive control of an over-
strained model predictive control: Stability and optimality, Automatica, head crane using constraint substitution, in Proceedings of the 2013
vol. 36, no. 6, pp. 789814, 2000. American Control Conference, 2013, pp. 39793984.
[23] R. Rothfuss, J. Rudolph, and M. Zeitz, Flatness based control of a
Core i5 @ 2.67 GHz and 4 GB memory.
2 Intel
nonlinear chemical reactor model, Automatica, vol. 32, no. 10, pp.
3 dSPACE DS1103 with a PowerPC 750 GX @ 1 GHz and 96 MB memory. 14331439, 1996.
667