Implementation and Analysis of Nonlinear Model Predictive Controller on Embedded Systems for Real-Time Applications
Implementation and Analysis of Nonlinear Model Predictive Controller on Embedded Systems for Real-Time Applications
Abstract— Today, various nonlinear programming problem changing dynamic systems, etc., require real-time implemen-
(NLP) solvers and C/C++ code generation frameworks are avail- tations. The code generation tools such as Casadi [6], IPOPT
able as open source for solving nonlinear model predictive [7], PANOC NMPC [8], and AutoGenU for Mapple in [9]
control (NMPC). Almost all the solvers are written in C/C++ code
which are more compatible for the PC-based simulation envi- are excellent for PC-based environment but not as suitable
ronment. These codes are not directly compatible for embedded and ready to port for embedded implementation. Tools such
implementation and real-time control. An attempt has been as FORCES PRO [10] and ODYS [11] are commercially
made to address this shortcoming by creating a customized available for embedded implementation of NMPC.
framework on top of the C code generated from ACADO On the other hand, ACADO Toolkit [12], is a general-
Toolkit to make it directly compatible with ARM based
embedded platforms. The study also analyzes the embedded ized framework for various automatic control and dynamic
implementation aspects using C code generated for qpOASES, optimization along-with built in NMPC. This is a self-
qpDUNES, and HPMPC solvers from ACADO Toolkit. We contained object-oriented C/C++ code, which comes with the
show the results of hardware-in-loop (HIL) simulations with MATLAB user interface and is available as open source
detailed analysis and comparison of memory requirement under GNU lesser general public license1 . The toolkit gen-
and achievable sampling time for three benchmark dynamical
systems on different embedded platforms viz ARM Cortex erates highly efficient C/C++ code but it is generally library
M3, PYNQ FPGA and Raspberry Pi. The results show that dependent. Several authors have validated the reliability of
qpOASES outperforms as compared to the other two solvers the ACADO Toolkit C/C++ code in PC-based simulations
when the computational time is of prime importance for small with sampling time in microsecond range [13]. The previous
prediction horizon. Similarly, when there are limited on-chip works [14], [15], [16] shows the implementation of NMPC
memory resources, qpDUNES can prove beneficial.
Index Terms— Nonlinear model predictive control, optimiza- with computational time results obtained from PC-based
tion solvers, embedded systems. simulations. The author [17] implemented C/C++ code from
ACADO Toolkit on RaspberryPi which is an OS-based
I. INTRODUCTION embedded platform.
Model predictive control (MPC) has been consistently Features like high-performance architecture, flexible pe-
used in both, industries and academic research [1]. MPC has ripheral connectivity, analog support, and low power con-
an inherent potential to handle multi-objective/multi-variable sumption makes ARM based processor a suitable choice in
problems, dealing explicitly with hard constraints as well various industrial applications. ARM based controllers are
as economic and safety considerations. The prevalent use restricted by the available memory and clock frequency.
of linear model predictive control in control tasks has been FPGA is one of the possible solutions for high memory
well established and the nonlinear model predictive control and speed demanding applications. Due to features like
(NMPC) looks like an intriguing solution for highly nonlin- parallelism and optimal performance, FPGA is proven to be
ear control tasks. NMPC captures all the natural nonlinear the most probable choice for applications like image pro-
dynamics and constraints of the model and outperforms cessing, telecommunication, military & aerospace, medical
as compared to linear MPC. This potential can only be electronics, automotive etc.
fully utilized when all the nonlinear process dynamics and In this paper, NMPC for real-time control is implemented
constraints are explicitly defined in the controller [2], [3], on Atmel ARM Cortex M3 micro-controller which has
[4]. limited resources in terms of clock and memory. ACADO
The blooming development in the optimization area has Toolkit generates a s-function which is compatible with
made room for many nonlinear solvers and C/C++ code MATLAB simulations but not with embedded devices. For
generation tools. These tools are highly efficient, reliable and HIL co-simulations on Atmel ARM, we have modified the
feasible for real-time online optimization with sampling time s-function so as it can be easily ported on embedded devices.
in milliseconds and microseconds range [5]. Similarly, we have validated the results on RaspberryPi
However, computationally challenging applications like and Xilinx PYNQ FPGA for models with large memory
autonomous vehicles, unmanned aerial vehicles, fast- requirements. Extending the work, we have also performed
detailed analysis of memory utilization and sampling time for
1 Department of Instrumentation and Control Engineering, College of
different solvers available in ACADO Toolkit for different
Engineering Pune, Shivajinagar 411005, India {adhauss17.instru,
patilsd17.instru, dns.instru}@coep.ac.in problem size.
2 University of Lyon, IFSTTAR, ENTPE, Lyon 69120, France
[email protected] 1 http://acado.github.io/
II. N ONLINEAR M ODEL P REDICTIVE C ONTROL The time required to feed control inputs to the real process
MPC as a constrained finite-time optimal control (CFTOC) depends on how fast quadratic problem (QP) is solved.
problem for reference tracking is represented as, B. Restrictions to use RTI Scheme
Z t0 +T
1
While using the RTI scheme in real-time applications,
min ||x(t) − xref (t)||2Q + ||u(t) − uref(t)||2R dt
x(.),u(.) t0 2 some factors might lead to failure of the algorithm [13]:
+ ||x(t0 + T ) − xref (t0 + T )||2P , (1a) 1) Infeasibility: The cost function in (1a), subjected to
state and inequality constraints is vulnerable to two types
subjected to following constraints for all t ∈ [t0 ,t0 + T ] of infeasibilities. The nonlinear optimization problem might
x(t0 ) = x̂0 , (1b) itself be infeasible or the underlying SQP-type algorithm can
become infeasible.
ẋ(t) = f (x(t), u(t)), (1c)
2) Instability: Assuming the QP is feasible for all prob-
umin ≤ u(t) ≤ umax , (1d) lems, the closed-loop system might still become unstable.
xmin ≤ x(t) ≤ xmax . (1e) As we have finite prediction horizon, closed-loop system is
susceptible to instability. Adding weights on the cost function
with initial condition x(t0 ) ∈ Rn .
The term (1a), is the
and/or zero terminal constraints removes this instability.
cost function and T > 0 is the prediction horizon. The cost
function is weighted by Q 0, P 0, and R ≻ 0. The function C. Nonlinear Model and OCP Formulation
f in (1c) describes the nonlinear dynamics of the system in Using the MATLAB interface, nonlinear dynamics of the
ordinary differential equations (ODE) form which depends model were added in the form of f . All the case studies
on the input signal u(t) ∈ Rm . The x̂0 is the current state have been studied with prediction horizon, T = 5 and same
estimate in (1b) and t0 is the current time. The input is control horizon.
bounded by umin and umax . The time varying states and
control references are xref and uref , respectively, see [18], [19, D. Solvers Used
Chapter 2]. Solvers require to solve the parameterized dynamic opti-
mization problems simultaneously for obtaining an optimal
III. ACADO FOR NMPC P ROBLEM F ORMULATION AND
control law at each sampling time. Convex QP solvers
C ODE G ENERATION
are used in ACADO Toolkit for solving optimal control
This section briefly describes the low level C/C++ based problems. In this study, solvers have been selected in con-
numerical methods employed to solve the NLP at each real- sideration with the realization of embedded NMPC to run
time iteration. in a real-time scenario. The following factors were the main
The ACADO Toolkit includes a variety of algorithms criteria for selection of the solvers.
for dynamic optimization, state and parameter estimation,
• Performance and numerical stability considering the
and automatic control. The toolkit exports highly efficient
safety aspects so as to run with limited resources and
C/C++ code for NMPC. There are numerous user accessible
the ability to use single precision arithmetic for the
settings for defining the NMPC problem and achieving
microcontroller,
the desired performance. The ACADO Toolkit-MATLAB
• Structure of the C-code, minimum library dependence,
interface is used to generate customized C code which can
and code portability,
be readily ported onto the embedded devices. Some of the
• Ability to terminate the solver early in order to obtain
basic steps while problem formulation and code generation
a feasible but suboptimal solution for the real-time
are discussed below:
applications,
A. Real-Time Iteration Scheme • Ability to hotstart the QP for fast receding horizon
Cost Function
Fig. 2. HIL design flow of NMPC algorithm on ARM.
Constraints
No. of States
Solver
2 6 9 2 6 9 2 6 9
TABLE III
NMPC RTI AVERAGE TIME IN (µs) WITH T = 5.
No. of States
Solver
2 6 9 2 6 9 2 6 9
qpDUNES 305 Not available 233 928 3090 237 1190 3580
TABLE IV
VARIATION IN AVERAGE RTI TIME IN (µs) WITH CHANGE IN PREDICTION HORIZON (T) FOR HOVERCRAFT MODEL (2)