A FPGA Implementation of Model Predictive Control : K.V. Ling, S.P. Yue and J.M. Maciejowski
A FPGA Implementation of Model Predictive Control : K.V. Ling, S.P. Yue and J.M. Maciejowski
A FPGA Implementation of Model Predictive Control : K.V. Ling, S.P. Yue and J.M. Maciejowski
I. INTRODUCTION
Model Predictive Control (MPC) has become an established control technology in the petrochemical industry. Its
use is currently being pioneered in an increasingly wide
range of high bandwidth applications, such as ships [12],
aerospace [11] [14], and road vehicles [10]and microscale
devices[3].
Fundamentally, MPC can be formulated as a quadratic
programming (QP) problem. It thus has the natural ability to
handle physical constraints arising in industrial applications.
Alternatively called receding horizon control, MPC computes
optimal current and future control inputs by minimizing the
difference between set-points and future outputs predicted
from a given plant model. Then only the optimal current
input is applied to the plant and this procedure is repeated
at the next sampling instance.
Two important factors determines a successful MPC applications. First, is the availability of a suitable plant model.
The second, is the ability to solve the quadratic programming
problem within the prescribed sampling period. The ability to
solve the QP problem online become critical when applying
MPC to complex systems with fast response time and/or
embedded applications where computational resource may
be limited. In addition, there would be a need for a scalable
and low-cost embedded control solution for lab-on-chip
devices on which the number of actuators and sensors could
*This research was supported by A*STAR project Model Predictive
Control on a Chip (Ref: 022-106-0044). K.V. Ling and S.P. Yue are with
the School of Electrical and Electronic Engineering, Nanyang Technological
University, Nanyang Avenue, Singapore 639798, ekvling@ntu.edu.sg. J.M.
Maciejowski is with the Cambridge University Engineering Department,
United Kingdom, jmm@eng.cam.ac.uk
Np
X
j=1
ky(k + j) (k + j)k2 +
NX
u 1
ku(k + j)k2
j=0
(2)
According to the infeasible interior point framework introduced by Wright [16], an optimal control signal can be
computed by solving the QP problem using the following
algorithm:
Step 1:
Choose an initial condition (z 0 , 0 , t0 ) with (0 , t0 ) > 0.
Step 2:
At the k-th iteration step, solve for the increments
(z k , k , tk ) with
k
T
z k
r
Q J
(9)
= 1k ,
r2
k
J
and
tk = tk + (k )1 ( k k e T k k ).
with
~y
= [ y(k + 1)T
CA
2
CA
=
... ,
1
t1
T
1
. . . u(k + Nu 1)T ] ,
..
..
..
,
e
=
=
,
T
=
.
.
.
1
kmc
tkmc
(11)
In addition,
y(k + 2)T
...
CANp
CB
CAB
..
.
0
CB
..
.
CANp 1 B
CANp 2 B
y(k + Np )T ] ,
0
.
..
..
.
.
Np Nu
CA
B
Jz g,
(3)
(4)
Qz + J = c,
(5)
Jz t = g,
(6)
0,
t 0,
t = 0.
(7)
(10)
k = (tk ) k /mc ,
(8)
r1k
r2k
= Qz k J k c,
= Jz k + g k k (k )1 e.
(12)
Step 3:
Increment the variables by
(z k+1 , k+1 , tk+1 ) = (z k , k , tk ) + k (z k , k , tk ),
(13)
for some k (0, 1] subject to (k+1 , tk+1 ) > 0.
Step 4:
Judge the convergence. If the iterations converges, stop the
process and the optimal control z k+1 is obtained; otherwise,
go back to Step 2 with (z k+1 , k+1 , tk+1 ) and continue the
iteration process.
Remark 2.1: It can be seen that solving such a QP problem is an iterative process and the main computational load
is in solving equation (9) at each iteration.
Equation (9) can be solved either as
(
T
k = ( JQ1 J )1 (r2k JQ1 r1k )
(14)
T
z k = Q1 r1k Q1 J k ,
or
z k
k
(15)
(16)
lation environment for designing and implementing control algorithms. The MPC algorithm is first prototyped in
MATLAB code and then simulated and verified in the
MATAB/SIMULINK environment.
Step 2: Prototyping in Handel-C Code
The prototype MPC in the form of MATLAB code is
translated into Handel-C code for FPGA realisation. The
code is then compiled and optimized in the DK design
suite. It is mapped, placed and routed by Xilinx ISE to a
target FPGA. The Xilinx tool would report hardware resource
usage and timing performance. If the results do not meet the
specified requirements, design iterations would need to be
carried out.
Step 3: Handel-C/MATLAB Co-Simulation
Two options are available for algorithm verification: software or hardware verification. For software verification, the
Handel-C code will be packaged into a DLL file and then
be called by Simulink as a S-function (see Fig. 2).
Fig. 2.
Fig. 3.
Fig. 1.
Simulink/Handel C Co-Simulation
Hardware-in-the-loop Verification
Although FPGA implementation of MPC is highly application dependent, there exists some common core components. The first, is an efficient floating point library (available
in the DK design suite). Next, is a matrix inversion core.
TABLE I
A S AMPLE T EST S UITE FOR FPGA I MPLEMENTATION OF
C ONSTRAINED MPC
%--------------------------------------------------clear all
TOL = 1e-3; %acceptable accuracy
N = 50;
%how many test
n = 6;
%size of QP
mc = 32;
...
for i = 1:N
% generate a QP program randomly
H = rand(n,n); Q = H*H;
...
u_qp = quadprog(Q,c,J,g); %use MATLABs QP solver
disp(Download program and data to RC10 board...)
for i=1:n
for j=1:n, fwrite(s,Q(i,j),single); end
end
...
|u| 0.524,
|y1 | 0.349.
Our experience showed that a 1.5 million gates Spartan3L FPGA could easily handle a 128x128 matrix inversion
problem with IEEE single precision floating point arithmetic
(8-bit exponent and 23-bit mantissa)[7].
When using the interior point method to solve the constrained MPC problem, the solution depends on the precision
of the floating point arithmetic and the criteria used in the
convergence test.
IV. TESTING THE FPGA-MPC ON AN AIRCRAFT
EXAMPLE
To verify our FPGA implementation, we tested it using
the Cessna Citation 500 aircraft model from [9], p.64. It has
the following continuous-time state space form
0.3
1.2822
0
0.98
0
0
0
1
0
0
A =
,
, B =
17
5.4293
0
1.8366 0
0
128.2 128.2
0
0
0
1
0 0
0
C = 0
0
0 1, D = 0.
(17)
128.2 128.2 0 0
0
The model has the elevator angle (rad) as its input, and
the pitch angle (rad), altitude (m) and altitude rate (m/s)
as outputs. The elevator angle is limited to 15o (0.262
Fig. 4.
Next, the set point for altitude was set to 400m, corresponds to Fig.2.7 in [9]. In our work, we found that solving
the QP problem as in (3) and (4) sometimes gave incorrect
results. To overcome this problem, we re-scaled the QP and
wrote it as
T
1 T
f (z) = z Qz
+ c z
(18)
2
and
g,
Jz
(19)
with
= Q, c = c, J = J, g = g.
Q
(20)
Control
Scenario
Fig. 5.
Slice
4565 (34%)
LUT
8451 (31%)
FF
1860 (6%)
Block
Memory
19 (59%)
System
Clock
20MHz
1
2
3
4
Average number
of Interior Point
Iterations
6.6
8.6
8.3
8.4
Average number
of clock cycles
per sample
398,920
475,133
368,527
390,229
Average execution
time (msec)
per sample
19.9
23.7
18.4
19.5
V. CONCLUSIONS
In this paper, we explored the implementation of constrained MPC algorithm using a FPGA chip. Interior point
method, with dense matrix formulation, was employed to
solve the resulting QP problem. A rapid prototyping environment suitable for exploring the various implementation
issues to bring MPC onto a FPGA chip was described.
Simulation tests were conducted to verify the applicability
of the MPC on a Chip idea. It was shown that a modest FPGA chip could be used to implement a reasonably
sized constrained MPC controller. Further work is needed to
investigate the possible parallelising of MPC computations
to take advantage of the available on-chip resources on the
FPGA chip. In this work, we have used Matlab/Simulink,
Handel-C, Xilinx ISE, etc. to take a MPC solution from
design to embedded implementation. Further effort should
also be directed at achieving a higher level of automation
in implementing embedded MPC technology. This would
facilitate the embedded system community to explore the
design space available in realizing a customized embedded
MPC design.
Fig. 7.
R EFERENCES
[1] R. Andrak, A survey of CORDIC algorithms for FPGA based computers, Proceedings of the 1998 ACM/SIGDA sixth international symposium
on Field programmable gate arrays, March 1998, pp. 191-200
[2] M. Baleani, F. Gennari, Y. Jiang, Y. Patel, R. K. Brayton, A.
Sangiovanni-Vincentelli, System partitioning and timing analysis:
HW/SW partitioning and code generation of embedded control applications on a reconfigurable architecture platform, Proceedings of
the tenth international symposium on Hardware/software codesign, May
2002, pp.151-156.
[3] L. Bleris, J. Garcia and M. Kothare, Model Predictive Hydrodynamic
Regulation of Microflows, American Control Conference, Portland, OR,
June 8-10, 2005, pp.1752-1757.
[4] K. Compton and S. Hauck, Reconfigurable computing: a survey of
systems and software, ACM Computing Surveys (CSUR), Vol. 34, Issue
2, June 2002, pp.171-210.
[5] R. R. Fletcher, Practical Methods of Optimization, Wiley, 2nd Edition,
1987.
[6] J. G. Garcia, M. G. Arnold, L. G. Bleris and M. V. Kothare. LNS
architectures for embedded model predictive control processors. In 2004
International Conference on Compilers, Architectures and Synthesis for
Embedded Systems, pp.7984, Washington, D.C., September 2004.
[7] M. H. He and K. V. Ling, Model Predictive Control on a Chip, The 5th
International Conference on Control & Automation, Budapest, Hungary,
June 26-29, 2005.
[8] K. V. Ling, J. M. Maciejowski and B. F. Wu, Multiplexed Model
Predictive Control, 16th IFAC World Congress, Prague, July 2005.
[9] J. M. Maciejowski, Predictive Control with Constraints, Prentice Hall,
2002.
[10] M. Morari, M. Baoti
c and F. Borrelli, Hybrid systems modeling and
control, European Journal of Control, Vol. 9, 2003, pp.177-27.
[11] R.M. Murray, J. Hauser, A. Jadbabie, M.B. Milam, N. Petit, W.B.
Dunbar and R. Franz, Online control customization via optimizationbased control, In: Software-Enabled Control (T. Samad and G. Balas,
Eds.). IEEE Press and Wiley, 2003.
[12] T. Perez, G.C. Goodwin and C.W. Tzeng, Model predictive rudder roll
stabilization control for ships, In: Proc. 5th IFAC Conf. on Manoeuvring
and Control of Marine Craft, Aalborg, Denmark, 2000.
[13] C. V. Rao, S. J. Wright and J. B. Rawlings, Application of interiorpoint methods to model predictive control, Journal of Optimization
Theory and Applications , Vol. 99, 1998, pp. 723-757.