Implementation Aspects of Model Predictive Control for Embedded Systems Pablo Zometa, Markus K¨ ogel, Timm Faulwasser, and Rolf Findeisen Abstract— We discuss implementation related aspects of model predictive control schemes on embedded platforms. Ex- emplarily, we focus on fast gradient methods and present results from an implementation on a low-cost microcontroller. We show that input quantization in actuators should be exploited in order to determine a suboptimality level of the online optimization that requires a low number of algorithm iterations and might not significantly degrade the performance of the real system. As a case study we consider a Segway-like robot, modeled by a linear time-invariant system with 8 states and 2 inputs subject to box input constraints. The test system runs with a sampling period of 4 ms and uses a horizons up to 20 steps in a hard real-time system with limited CPU time and memory. Index Terms— model predictive control, embedded systems, real-time implementation, fast gradient method, LEGO NXT I. I NTRODUCTION Model Predictive Control (MPC) has a long and successful history in the chemical industry, where it is used to control high-performance processes with slow dynamics [1]. One of the main strengths of MPC is its ability to deal with constraints as well as with multi-input multi-output systems in a systematic way. One of its main drawbacks is that high computational demands are typically associated with it, which makes real-time implementations challenging. The continuous development of more efficient MPC algorithms continues to reduce these demands. However, it is still not easy to implement MPC on embedded platforms that control fast mechatronic systems with sampling times in the range of milliseconds. These challenges arise because embedded platforms are typically based on processors with clock frequencies in the MHz range and memories in the range of kB. MPC is built upon the repetitive solution of an optimal control problem (OCP). In case of linear, time-invariant, discrete-time systems with affine input and state constraints and a quadratic cost function, the OCP is equivalent to a quadratic program (QP). The OCP arising in MPC can be solved using off-line or online methods. The former approach (known as explicit MPC [2]) is particularly fast for small systems, but has a much larger online memory footprint than the latter (especially for medium and large size problems), since the explicit solution needs to be stored in a table or tree, which become very large for larger problems. An online MPC scheme with a good balance between computational speed and memory demand based on a fast gradient method P.Z., M.K., T.F. and R.F. are with the Institute for Automation Engineer- ing, OvG University Magdeburg, Germany. M.K. and T.F. are also with the International Max Planck Research School for Analysis, Design and Optimization in Chemical and Biochemical Process Engineering, Magde- burg, Germany e-mail: {pablo.zometa, markus.koegel, timm.faulwasser, rolf.findeisen}@ovgu.de. (FGM) was presented in [3]. It is based on Nesterov’s gradient method [4]. In [3] an upper bound for the maximum number of iterations needed to ensure a predefined accuracy is provided, and the computational complexity is shown to be quadratic with respect to the horizon length and the number of inputs. In [5], the method is implemented on a high performance digital signal processor to control a simulated plant, where FGM performs better than explicit MPC. In [6], the structure of the MPC problem is exploited to derive an algorithm with computational and memory demands linearly increasing with the horizon length and the number of inputs. A simulation example shows that it is of advantage for large horizon lengths. In this work we focus on the implementation aspects of FGM-based MPC on embedded systems. In contrast to previous works on FGM-based MPC [3], [5], [6] we present results from an implementation on a real system, using a hard real-time operating system (RTOS), and a low-cost 32-bit 48-MHz microcontroller. We stabilize a system with 8 states and 2 inputs using horizon lengths of up to 20 steps with sampling times of 4 ms. For the considered example the memory required is in the order of kilobytes even for long horizons. Moreover, we propose the use of the input quantization taking place in the system actuators to determine the suboptimality level of the approximate QP solution, instead of using an ad hoc value based on the MPC cost function. We demonstrate with our example that this quantization-based suboptimality level might require only a low number of iterations of the FGM and still deliver a good system performance. Furthermore, we show with several Monte Carlo experiments that the theoretical upper bound for the number of iterations is a factor two to three higher than the number observed in practice. We implement the algorithm using fixed-point and floating-point arithmetic, and show that even in the former case the error is less than one quantization level of the inputs. Note that we focus on outlining the challenges and solutions for implementing MPC on limited embedded platforms. Stability and robustness guarantees are beyond the scope of this paper. The structure of this paper is as follows. Section II introduces the system to be controlled, and briefly describes the microcontroller and the RTOS used. In Section III we briefly recall the fast gradient method in the context of MPC, and we present an alternative way to select the maximum number of iterations based on the hardware. In Section IV we present the analysis of the computational requirements of the implementation. Finally, in Section V we state our conclusions. 2012 American Control Conference Fairmont Queen Elizabeth, Montréal, Canada June 27-June 29, 2012 978-1-4577-1094-0/12/$26.00 ©2012 AACC 1205