Auto-Generated Algorithms For Nonlinear Model Predictive Control On Long and On Short Horizons
Auto-Generated Algorithms For Nonlinear Model Predictive Control On Long and On Short Horizons
Abstract— We present a code generation strategy for han- Nonlinear model predictive control (NMPC) allows one
dling long prediction horizons in the context of real-time nonlin- to apply MPC to nonlinear dynamical systems [3], [4]. The
ear model predictive control (NMPC). Existing implementations continuation/GMRES method [19], the advanced step NMPC
of fast NMPC algorithms use the real-time iteration (RTI)
scheme and a condensing technique to reduce the number of controller [28] and the real-time iteration (RTI) scheme [7],
optimization variables. Condensing results in a much smaller, [8] represent efficient algorithms for fast NMPC. The reader
but dense quadratic program (QP) to be solved at every time is referred to [9] for a more detailed overview.
step. While this approach is well suited for short horizons, Automatic code generation for convex optimization solvers
it leads to unnecessarily long execution times for problem became very popular recently. The basic idea of code gen-
formulations with long horizon. This paper presents a new
implementation of auto-generated NMPC code based on a eration is to exploit the fact that all problem dimensions
structure exploiting auto-generated QP solver. Utilizing such and structure is known a priori. This allows one to gen-
a QP solver, the condensing step can be avoided and execution erate highly customized and fast solver code, which then
times scale linearly with the horizon length instead of cubically. solves instances of a specific problem. The code generation
Our simulation results show that this approach significantly framework CVXGEN [17] was the first implementation that
decreases the execution time of NMPC with long horizons. For
a nonlinear test problem that comprises 9 states and 3 controls allowed one to export tailored interior-point (IP) solvers that
on a horizon with 50 time steps, an improvement by a factor can solve quadratic programs (QPs) very fast on embedded
of 2 was observed, reducing the execution time for one RTI to platforms. Following the observation that linear MPC prob-
below 4 milliseconds on a 3 GHz CPU. lems fall into the class of multistage problems with particular
structure [11], FORCES has been designed to overcome
I. INTRODUCTION the limitations of CVXGEN in terms of problem size. The
FORCES code generation framework [10] exports primal-
Model predictive control (MPC) has been originally de- dual interior point codes.
signed and used for control of large-scale processes, typically In a similar fashion, nonlinear MPC (NMPC) relevant
in the chemical and petroleum industry. Slow dynamics dimensions are also known before deployment of a controller
of those systems allowed large control intervals measured and highly efficient code can be generated to speed up com-
in tens of seconds or even hours, leaving enough time to putations. To our knowledge, the existing implementations of
compute a solution to the underlying optimization problem. NMPC code generators are AutoGenU [23] and the ACADO
However, progress in the area of optimization algorithms Code Generation tool [15]. The ACADO Code Generation
and computational hardware in the last two decades have tool exports efficient self-contained C-code that implements
extended the applicability of numerical optimization on em- the RTI scheme. The algorithm implements an sequential
bedded platforms. These developments made MPC suitable quadratic programming (SQP) framework and consists of
for control of fast dynamical systems with time constants in simulation and linearization of the nonlinear system, and
micro- and millisecond range. solution of a convex subproblem – a QP. The RTI scheme [8]
performs a single SQP iteration per sampling instant in
Milan Vukov and Moritz Diehl are with the Department of Electrical order to quickly deliver an approximate solution to the
Engineering, KU Leuven, Kasteelpark Arenberg 10, 3001 Leuven, Belgium.
Alexander Domahidi and Manfred Morari are with the Automatic Control optimization problem. An experimental verification of the
Laboratory, Department of Information Technology and Electrical Engineer- exported NMPC code is presented in [25], showing execution
ing, ETH Zurich, 8092 Zurich, Switzerland. times below 1.1 milliseconds per RTI step for a nontrivial
Hans Joachim Ferreau is with the ABB Corporate Research, Baden-
Dättwil, Switzerland. dynamic model.
Contact: [email protected] The original implementation of the code generator for non-
This research was supported by Research Council KUL: PFV/10/002 linear MPC within the ACADO toolkit utilizes the embedded
Optimization in Engineering Center OPTEC, GOA/10/09 MaNet and
GOA/10/11 Global real- time optimal control of autonomous robots version of the QP solver qpOASES [1]. The QP solver is
and mechatronic systems. Flemish Government: IOF/KP/SCORES4CHEM, based on an (online) active set strategy [12] and employs
FWO: PhD/postdoc grants and projects: G.0320.08 (convex MPC), dense linear algebra routines. To obtain feedback times in
G.0377.09 (Mechatronics MPC); IWT: PhD Grants, projects: SBO LeCoPro;
Belgian Federal Science Policy Office: IUAP P7 (DYSCO, Dynamical the milliseconds range, a technique called condensing [6]
systems, control and optimization, 2012-2017); EU: FP7-EMBOCON (ICT- is applied, which significantly reduces the number of opti-
248940), FP7-SADCO ( MC ITN-264735), ERC ST HIGHWIND (259 166), mization variables in the QP. However, both the condensing
Eurostars SMART, ACCM.
The authors would like to thank Janick Frasch and Timon Achtnich for procedure and an active-set QP solver have cubic complexity
helpful discussions during the preparation of this paper. in number of prediction intervals, leading to prohibitively
long execution times when long prediction horizons are The typical choice for NMPC is to use piecewise constant
needed. parametrization of controls, resulting in N control variables
In this paper we present an extension of the ACADO Code uk , k = 0, . . . , N − 1.
Generation tool for NMPC that can efficiently handle long In the context of multiple shooting, the state trajectory
prediction horizons. In particular, we present a variant of is computed independently on each subinterval [tk ,tk+1 ]. For
an auto-generated NMPC that is utilizing the structure ex- that purpose, additional variables sk are introduced to serve
ploiting QP solver FORCES [11], [10]. Employing FORCES as initial values:
bypasses usage of the condensing procedure, thus saves a
significant amount of computational time for long prediction ẋk (t) = f (xk (t), uk ), xk (tk ) = sk , t ∈ [tk ,tk+1 ]. (2)
horizons. The new implementation of the NMPC is tested
against the original, condensing based, NMPC on a scalable Furthermore, in order to ensure continuity of the optimal
example – a chain of masses connected with springs. The state trajectory on the whole horizon matching constraints
purpose of this paper is to explore at which horizon length are added to the NLP:
the cubic growth will make condensing non-competitive
compared with NMPC utilizing sparse QP solver. sk+1 = Fk (sk , uk ), k = 0, . . . , N − 1, (3)
The paper is organized as follows. In Section II, we
introduce the problem formulation of the nonlinear MPC where Fk represents the solution of the initial value problem
problem, and give the concept of the real-time iteration (RTI) (IVP) (2) at time t = tk+1 . The objective and path constraints
scheme and background on dense vs. sparse QP solvers. are discretized at the same grid as the states and controls.
Section III describes the ACADO Code Generation tool The NLP that comes as a result of the multiple shooting
and the extension to generating code that utilizes sparse discretization reads:
QP solvers. We give a numerical example showing the
1 N−1
computational benefits for long horizons with the structure min
u, s 2 k=0
ks − x ref 2
k + ku − u ref 2
∑ k k Q k k R + ksN − xNref k2P
k
exploiting QP solver FORCES in Section IV. Section V
concludes the paper. (4a)
0
Condensed Nnu Nnu NM
Sparse Nnu + (N + 1)nx Nnu + (N + 1)M 0
−0.5
−1
z [m]
−1.5