Open access peer-reviewed chapter

An Implementable and Stabilizing Model Predictive Control Strategy for Inverted Pendulum-Like Behaved Systems

Written By

Odilon S.L. de Abreu, Márcio A.F. Martins and Leizer Schnitman

Submitted: November 12th, 2019 Reviewed: February 5th, 2020 Published: March 7th, 2020

DOI: 10.5772/intechopen.91629

From the Edited Volume

Automation and Control

Edited by Constantin Voloşencu, Serdar Küçük, José Guerrero and Oscar Valero

Chapter metrics overview

880 Chapter Downloads

View Full Metrics


In control theory, the inverted pendulum is a class of dynamic systems widely used as a benchmarking for evaluating several control strategies. Such a system is characterized by an underactuated behavior. It is also nonlinear and presents open-loop unstable and integrating modes. These dynamic features make the control more difficult, mainly when the controller synthesis seeks to include constraints and the guarantee of stability of the closed-loop system. This chapter presents a stabilizing model predictive control (MPC) strategy for inverted pendulum-like behaved systems. It has an offset-free control law based on an only optimization problem (one-layer control formulation), and the Lyapunov stability of the closed-loop system is achieved by adopting an infinite prediction horizon. The controller feasibility is also assured by imposing a suitable set of slacked terminal constraints associated with the unstable and integrating states of the system. The effectiveness of the implementable and stabilizing MPC controller is experimentally demonstrated in a commercial-didactic rotary inverted pendulum prototype, considering both cases of stabilization of the pendulum in the upright position and the output tracking of the rotary arm angle.


  • rotary inverted pendulum
  • model predictive control
  • nonlinear system
  • Lyapunov stability
  • feasible-optimization problem

1. Motivation

Dynamic inverted pendulum-featured apparatuses are widespread in systems and control theory. These represent a class of nonlinear and underactuated electromechanical systems, which, in turn, are composed of open-loop unstable and integrating modes. The scale-up of inverted pendulum-based conceptual sketches in practical mechanisms and real applications has been in progress, of which one can cite stabilization of rocket launch, robot balance, and segway-like means of transportation, among others [1, 2].

In control theory, inverted pendulum-type systems have enabled extensive studies concerning controller architectures ranging from proportional-integrative-derivative (PID)-like classical strategies to more advanced technique ones, such as optimal and adaptive strategies. In the middle of the advanced control strategies, the so-called class of model predictive control (MPC) strategies has been preferred by systematically handling system constraints. In fact, any MPC algorithm makes explicit use of a system model to predict its outputs and to obtain an optimal control law that minimizes the prediction error and control efforts [3, 4, 5]. Since it requires an online solution to its associated optimization problem, it first became popular in applications of slow dynamic systems, such as those in petroleum refineries and petrochemical industries [6]. However, with advances in hardware development and optimization techniques, MPC applications have been extended to fast dynamic systems, including inverted pendulum-like mechatronic systems [7, 8, 9].

On the other hand, when one seeks to control open-loop unstable systems such as inverted pendulum-like behaved ones, the guarantee of stability associated with control laws plays a crucial role concerning practical implementation purposes. In particular, the synthesis of stabilizing MPC laws deals essentially with terminal state constraints. One of the most heavily studied stability approach is one based on a dual-mode framework, which is composed of two distinct control modes: in the first mode, a conventional MPC law forces the system states to converge to a certain invariant set at the end of the finite prediction horizon, while in the second control mode, a local state-feedback controller takes over and drives the state to the desired operating point within this set [10]. This approach, however, requires the computation of the invariant set parameters, which is obtained from an offline numerical procedure. Although this set can be obtained offline with standard algorithms, undesired convergence and numerical issues may appear as the system dimension increases. Furthermore, the control horizon should be large enough such that the system states at the end of this horizon lie in the invariant set; otherwise the resulting optimization problem becomes infeasible, thus compromising both feasibility and control performance.

Another way to guarantee the closed-loop system stability of MPC controllers is to adopt an infinite prediction horizon, the so-called infinite-horizon model predictive control (IHMPC). Since the infinite-horizon problems cannot be directly handled by an optimization algorithm, the realization of IHMPC controllers is obtained from the combination between a terminal cost term and terminal equality constraints [11]. The terminal cost, associated with open-loop stable modes of the system, is calculated through the solution of the Lyapunov equation, whereas the terminal constraints are necessary to limit the objective function when the system is composed of integrating and unstable modes. However, stability proof is only achieved if the constrained optimization problem is feasible. The feasibility is also a critical issue of this approach, particularly because the domain of attraction of the controller becomes quite reduced by virtue of the associated hard constraints. Although there is already a rich theory in this field, the applications are heavily limited to theoretical works [12]. Among the methods developed to circumvent this issue so far, the approach based on slacked terminal constraints seems to be more adequate for practical implementation purposes, with recent applications reported in the literature, one implementation in a crude oil distillation [13] and the other in an inverted pendulum mechatronic-like fast dynamic system, namely, customized engine control unit [14].

This class of controllers formulates optimization problems that are always feasible through the suitable inclusion of slack variables in the control laws, without compromising their convergence and stabilizing properties. Also, these IHMPC controllers make use of the customized state-space models, obtained from an analytical expression of the step response of the system. Because of this, their formulations have been gradually developed over time. Odloak [15] focused on systems with open-loop stable poles, his work being extended to contemplate simple integrating poles as well in [6], commonly found in systems of the process industry. Then, Santoro and Odloak [16] encompassed time delays to the formulation proposed in [6]. For open-loop stable and unstable time-delay processes, Martins and Odloak [12] synthesized their IHMPC controller. More recently, the master’s dissertation [17] included integrating poles in the last work formulation [12], such that its associated IHMPC controller can be directly applied to rotary inverted pendulum-behaved systems, the case understudy of this chapter. The implementation in a real system of the feasible-optimization problem-based stabilizing MPC controller proposed in [17] has not yet been documented in the literature. This gap will be filled in the present work.


2. System description

The objective of the MPC controller to be explored in this work is to stabilize the pendulum rod in the upright position while it leads the rotary arm angle to the desired positions. To this end, the rotary inverted pendulum used here will be a commercial-didactic prototype manufactured by Quanser. This prototype is installed in the Control Laboratory of the Center for Technological Training in Industrial Automation (CTAI) at the Federal University of Bahia (UFBA). Figure 1 illustrates the features of such a system [18].

Figure 1.

Rotary inverted pendulum prototype manufactured by Quanser (left) and the schematic diagram (right).

The rotary inverted pendulum prototype consists of a servomotor system, whose voltage V m applied to it is responsible for generating torque in the rotary arm of angle ( θ ). The long pendulum rod is connected to the end of the rotary arm, and its angle, α , is zero when it is upright in the vertical position (cf. Figure 1).

The governing mathematical model of this system can be obtained by the Euler-Lagrange formalism, resulting in the following well-known equations [18]:

θ ¨ = bcsin α α ̇ 2 + bdsin α cos α ce θ ̇ + cfV m ac b 2 cos 2 α , α ¨ = adsin α b 2 sin α cos α α ̇ 2 becos α θ ̇ + bfcos α V m ac b 2 cos 2 α , E1

where θ ¨ , θ ̇ , α ¨ , and α ̇ represent angular accelerations and velocities associated with rotary arm angle and inverted pendulum angle, respectively. In addition, the parameters a b c d e f are constants related to the physical dimensions of the various components that make up the inverted pendulum prototype. Information about the modeling and physical parameters of the system can be referred to [18].

Since one of the control objectives aims to the stabilization of the pendulum in the upright position, it is quite adequate to assume that α will suffer small variations, which implies that sin α α , cos α 0 , and α ̇ 2 0 . Then, after some algebraic manipulations in Eq. (1), applying the Laplace transform as well, one turns out to be the following transfer function matrix ( G s ):

θ s α s = fcs 2 fd s ac b 2 s 3 + ecs 2 ads ed bfs ac b 2 s 3 + ecs 2 ads ed G s V m s . E2

This model representation of the system in terms of transfer functions is useful to obtain the state-space formulation to be used in the stabilizing MPC control law, as will be shown in the next section.


3. Stabilizing MPC formulation

The stabilizing MPC control law used in this work seeks to solve an infinite-horizon optimization problem, such that its objective function is composed of the following terms:

J k = j = 1 y k + j k y sp δ y , k Ψ un F un j m δ un , k j m Δ t δ i , k Q y 2 + j = 0 m 1 Δ u k + j k R 2 + δ y , k S y 2 + δ un , k S un 2 + δ i , k S i 2 , E3

where m is the control horizon, Δ u k + j k R nu is the vector of input moves at time step k + j , Q y R ny × ny is a positive-definite weighting matrix of the controlled outputs, R R nu × nu is a positive-definite weighting matrix of the input moves, y sp R ny is the vector of references of the controlled variables, and y k + j k R ny is the vector of the predicted outputs at time step k + j computed at time step k , considering a state-space model obtained from an analytical expression of the step response of the system described as in Eq. (2), namely:

x s k + 1 x st k + 1 x un k + 1 x i k + 1 = I ny 0 ny × nd 0 ny × nun Δ t I ny 0 nd × ny F st 0 nd × nun 0 nd × ny 0 nun × ny 0 nun × nd F un 0 nun × ny 0 ny 0 ny × nd 0 ny × nun I ny A x s k x st k x un k x i k + B s B st B un B i B Δ u k , E4
y k = I ny Ψ st Ψ un 0 ny × nu C x s k x st k x un k x i k . E5

In the state-space model defined in the pair of Eqs. (4) and (5), x s k R ny are the artificial integrating states introduced by the incremental form of inputs, x st k C nst are the stable states of the system, x un k C nun are the unstable states of the system, and x i k R ny are the true integrating states of the system. I n and 0 n are identity and null matrices of n × n dimension, respectively. The remaining matrices ( F st , F un , B s , B st , B un , B i , Ψ st e Ψ un ) are obtained from step-response coefficients of the transfer function matrix of the system, and the details can be referred to [19, 20].

In the objective function, there are also δ y , k , δ un , k , and δ i , k that are slack variables introduced into the control law so as to provide additional degrees of freedom to the resulting optimization problem, thus assuring the feasibility of the controller. These slack variables are weighted by positive defined matrices S y R ny × ny , S un R nun × nun , and S i R ni × ni , respectively. In fact, the set of slack variables adopted in the problem formulation is responsible for softening, when necessary, terminal constraints that are imposed to limit the infinite-horizon objective function, owing to the existence of open-loop unstable and integrating modes.

It should be kept in mind that the objective function defined in Eq. (3) can be rewritten as follows:

J k = j = 1 m y k + j k y sp δ y , k Ψ un F un j m δ un , k j m Δ t δ i , k Q y 2 + j = 1 y k + m + j k y sp δ y , k Ψ un F un j δ un , k j Δ t δ i , k Q y 2 + j = 0 m 1 Δ u k + j k R 2 + δ y , k S y 2 + δ un , k S un 2 + δ i , k S i 2 . E6

Then, with the aid of the state-space model used to carry out the prediction of the system, it is possible to demonstrate that the objective function becomes:

J k = j = 1 m y k + j k y sp δ y , k Ψ un F un j m δ un , k j m Δ t δ i , k Q y 2 + j = 1 x s k + m k + j Δ t x i k + m k + Ψ st F st j x st k + m k + Ψ un F un j x un k + m k y sp δ y , k Ψ un F un j δ un , k j Δ t δ i , k Q y 2 + j = 0 m 1 Δ u k + j k R 2 + δ y , k S y 2 + δ un , k S un 2 + δ i , k S i 2 . E7

It is worth emphasizing that if constraints are not imposed at the end of the control horizon, the objective function value will increase unbounded. To this end, the following terminal constraints are imposed on the optimization control problem:

x s k + m k y sp δ y , k = 0 , E8
x un k + m k δ un , k = 0 , E9
x i k + m k δ i , k = 0 . E10

Furthermore, the term associated with stable modes of the system comprises a convergent series, giving rise to the so-called terminal cost, namely:

j = 1 Ψ st F st j x st k + m k Q y 2 = x st k + m k Q ¯ 2 , E11

where Q ¯ is the terminal weighting matrix obtained from the solution to the Lyapunov equation of the system. In symbols:

Q ¯ = F st Ψ st Q y Ψ st F st + F st Q ¯ F st . E12

Therefore, the feasible-optimization problem-based stabilizing MPC control law is summarized as follows:

Problem 1.

min Δ u k , δ y , k , δ un , k , δ i , k J k = j = 1 m y k + j k y sp δ y , k Ψ un F un j m δ un , k j m Δ t δ i , k Q y 2 + x st k + m k Q ¯ 2 + j = 0 m 1 Δ u k + j k R 2 + δ y , k S y 2 + δ un , k S un 2 + δ i , k S i 2 ,

subject to Eqs. (8), (9), and (10), and

Δ u k + j k U , j = 0 , , m 1 , E13
U = Δ u max Δ u k + j k Δ u max Δ u k + j k = 0 , j m u min u k 1 + i = 0 j Δ u k + i k u max , E14

where Δ u k = Δ u k k Δ u k + m 1 k T is the sequence of control moves along the control horizon.

Remark 1. The slack variables play a remarkable role with respect to the feasibility of the control formulation, i.e., the control law of Problem 1 will always provide a feasible solution, either the nominal case (linear model) or plant-model mismatch, an object under study of this work.

Remark 2. The weighting matrices S y , S un , and S i (additional tuning parameters when compared to conventional MPC strategies) should be carefully selected. For instance, the values of S y should be chosen sufficiently large, e.g., orders of magnitude larger than Q y ( 10 3 Q y ), to guarantee that the solution of the slacked optimization problem will only use the slack vector when the terminal constraints need to be softened. While δ un , k and δ i , k do not need to be minimized a priori, by issues of achieving the closed-loop stability as fast as possible, one seeks their minimization weighted by large enough values of positive-definite S un and S in ( 10 2 Q y ) in order to enforce them to zero in a finite number of steps.

Remark 3. From the stability point of view, the master’s dissertation [17] demonstrates the conditions necessary to prove that the objective function behaves as a Lyapunov function, thus assuring that the control actions obtained from the solution of Problem 1 drive the system asymptotically to the reference value (desired steady state), if it is reachable; otherwise, the system will converge to an equilibrium point (reachable steady state) lying at a minimum distance from the desired steady state.


4. Results and discussion

This section is devoted to present the implementation results of the feasible-optimization problem-based stabilizing MPC controller (Problem 1) in the rotary inverted pendulum prototype described in Section 2. The ultimate goal of the controller is to maintain the pendulum rod in the upright position after it has been swung up to this position by the energy-based swing-up control scheme embedded in the system. In addition, the IHMPC controller is simultaneously designed to track the desired positions to be configured for rotary arm angles. In Quanser apparatus, an unconstrained linear-quadratic regulator (LQR) controller makes up the control system, besides the swing-up control strategy. The existing LQR strategy will be replaced by the IHMPC controller, and this scheme is depicted in Figure 2.

Figure 2.

Schematic representation of the application of the IHMPC controller in the rotary inverted pendulum prototype.

The architecture used for this real-time implementation of the IHMPC controller is summarized in Figure 3. From this figure, it is possible to note the information exchange among software-hardware-equipment mechanisms of the prototype. The control law is solved at each sampling time on the computer i7-8550H with 1.80GHz processor and 16GB of RAM, using Matlab script and Quarc real-time control toolbox. The software-hardware interface is done via USB communication through the Q8-USB acquisition board. This acquisition system acts, in turn, as an interface between the digital part of the system (controller) and the analogic one that is composed of the amplifier (VoltPAQ-X1).

Figure 3.

The architecture used in communication among software-hardware-equipment mechanisms.

For the experimental results presented as follows, we consider a scenario of square wave-type tracking on the rotary arm, while the controller must maintain the pendulum rod around the upright vertical position, even in the existing unmeasured disturbance scenarios. The constraints associated with the control signal and control actions (decision variables) are those established in Table 1. Note that there is a strict condition of ± 1 V on the control actions. Also, the IHMPC tuning parameters considered were sampling period Δ t = 2 milliseconds, Q y = diag 1 6 × 10 2 , R = 9.8 × 10 2 , S y = diag 10 5 10 4 , S un = diag 10 2 6 × 10 4 , and S i = 10 2 . The state estimator used here was the Kalman filter, whose tuning parameters associated with process noise and measurement noise were the following covariance matrices Q Kalman = I 9 × 9 and R Kalman = 2.4 × 10 6 I 2 × 2 , respectively. Finally, a control horizon of m = 9 has been adopted as an appropriate value to attain the desired control performance, which was chosen from a sensitivity analysis, as will also be shown here.

Variables Minimum value (V) Maximum value (V)
Control signal −12 12
Control actions −1 1

Table 1.

Constraints on system inputs.

The closed-loop system results are depicted in Figures 4 and 5. From Figure 4, one can see that after about 5.5 seconds, the time necessary that the swing-up control acted to lead the pendulum rod to its upright position, the IHMPC controller takes over and performs quite well both tasks associated with the rotary arm angle tracking and the stabilization of the pendulum rod within an acceptable range lying at about ± 2 . It is also noteworthy that after the execution of the square-wave trajectory on the rotary arm angle, the controller had a great performance concerning impulse-like external disturbances inserted in the pendulum rod since the controlled variables are momentarily moved away from their set points, but soon they are brought back to their original positions.

Figure 4.

Controlled variables: rotary arm angle ( θ ) and pendulum rod angle ( α ).

Figure 5.

Behavior of the control signal (tension applied to the servomotor).

Even though the stability of the IHMPC controller is only related to the nominal case (linear model), it proved to be very sufficient in a realistic plant-model mismatch scenario, including nonlinearities existing in the rotary inverted pendulum apparatus, such as dead zone, friction, backlash, hysteresis, and so on. This model uncertainty scenario was responsible for non-prohibitive oscillations, within a practical implementation purpose, on the constrained control signal (cf. Figure 5), which were reflected in the controlled outputs.

Furthermore, it is worth mentioning that fulfilling a tighter constraint ( ± 1 V) by a conventional stabilizing MPC controller, e.g., [11, 21], could result in an unfeasibility scenario; however, since IHMPC controller used here is based on a feasible-optimization formulation, its control law always will provide a feasible solution while the system is controllable, thus becoming it implementable in practice. The IHMPC controller uses its additional degrees of freedom (slack variables), when necessary, in order to comply with the terminal constraints. Figure 6 illustrates the use of the slack variables in the control problem. It is observed that the controller makes use of these variables immediately after a perturbation in the system occurred namely, set-point changes and unmeasured disturbance entrance, situations in which it can be hard to comply with non-slacked terminal constraints. However, as the system goes to an acceptable cyclic steady state around its set point, due to the noise degree intrinsic to the system, the slack variables converge to the origin very fast and systematically.

Figure 6.

Behavior of the slack variables associated with the feasible-optimization formulation of the IHMPC controller.

On the other hand, in order to obtain a satisfactory performance as in the results presented earlier, an effort with respect to the controller tuning was necessary. This tuning task is easier in the stabilizing MPC controllers than the conventional finite-horizon MPC ones [13], as demonstrated in what follows. In this case, it was sufficient to handle only the control horizon. In inverted pendulum-like fast dynamic systems, when one applies a more aggressive control policy, i.e., small control horizon, it can cause undesired overshoots, while adopting large control horizons, it cannot have time sufficient to act with control action properly, thus bringing unnecessary oscillations or even causing the instability of the closed-loop system.

To work around this trade-off, we proceeded with sensitivity analysis on the control horizon, keeping the same remaining tuning parameters shown in the preceding experimental results. Figure 7 summarizes the aforementioned analysis. Note that as the control horizon increases, the oscillations decrease until the control horizon m = 9 . However, a value greater than m = 9 makes the closed-loop system go back to having undesired and larger oscillations, thus jeopardizing the use of energy associated with the control signal. Therefore, the use of the IHMPC controller enabled a simple analysis concerning only one tuning parameter, which yielded an appropriate value to meet the desired control performance in the real case.

Figure 7.

Sensitivity analysis on the control horizon of the closed-loop system.


5. Conclusions

In this chapter, we have investigated the application of an implementable and stabilizing model predictive control model strategy in a commercial-didactic rotary inverted pendulum apparatus, hitherto unexplored in the literature. Although the guarantee of stability of the controller is devoted to the nominal case (linear model), its formulation based on a feasible-optimization problem allows it to be used in any plant-model mismatch scenario in practice, such as one series of nonlinearities existing in the real system, namely, dead zone, friction, and backlash, among other unmodelled dynamics. The experimental results showed the effectiveness and robustness of the controller in the aforementioned plant-model mismatch setting by performing quite well its task in the rotary arm angle tracking and stabilization of the pendulum rod around the upright position as well as in the optimum use of energy associated with control efforts.

A simple tuning procedure was adopted by virtue of using a stabilizing MPC controller, which allowed us to handle only one tuning parameter through sensitivity analysis on the control horizon. The value found was quite adequate to attain the control objectives in terms of the trade-off existing between the performance on the controlled variables and the use of energy related to the control signal.

The future direction for this research is to further extend this controller to guarantee the stability of the nonlinear case, including the energy-based swing-up control schemes.



The authors would like to thank the Brazilian research agencies CAPES, CNPq, and FAPESB for their financial support.


  1. 1. Ogata K. Modern Control Engineering. 5th ed. Upper Saddle River: Prentice Hall; 2010
  2. 2. Nise NS. Linear Systems Theory. 7th ed. Hoboken: Wiley; 2015
  3. 3. Rossiter JA. Model-Based Predictive Control: A Practical Approach. Boca Raton: CRC Press; 2003
  4. 4. Camacho EF, Bordons C, Alba CB. Model Predictive Control. London: Springer; 2004
  5. 5. Maciejowski JM. Predictive Control: With Constraints. Harlow: Pearson Education; 2002
  6. 6. Carrapiço OL, Odloak D. A stable model predictive control for integrating processes. Computers and Chemical Engineering. 2005;29(5):1089-1099
  7. 7. Askari M, Mohamed HAF, Moghavvemi M, Yang SS. Model predictive control of an inverted pendulum. In: International Conference for Technical Postgraduates, TECHPOS. 2009. DOI: 10.1109/TECHPOS.2009.5412069
  8. 8. Mohamed HAF. Hard constraints explicit model predictive control of an inverted pendulum. 1st International Conference on Energy, Power and Control (EPC-IQ). 2010;6(1):28-32
  9. 9. Peyrl H, Zanarini A, Besselmann T, Liu J, Boéchat M-A. Parallel implementations of the fast gradient method for high-speed mpc. Control Engineering Practice. 2014;33:22-34
  10. 10. Mayne DQ, Rawlings JB, Rao CV, Scokaert POM. Constrained model predictive control: Stability and optimality. Automatica. 2000;36(6):789-814
  11. 11. Rawlings JB, Muske KR. The stability of constrained receding horizon control. IEEE Transactions on Automatic Control. 1993;38(10):1512-1516
  12. 12. Martins MAF, Odloak D. A robustly stabilizing model predictive control strategy of stable and unstable processes. Automatica. 2016;67(5):132-143
  13. 13. Martin PA, Zanin AC, Odloak D. Integrating real-time optimization and model predictive control of a crude distillation unit. Brazilian Journal of Chemical Engineering. 2019;36(3):1205-1222
  14. 14. Brugnolli MM, Angelico BA, Laganá AAM. Predictive adaptive cruise control using a customized ecu. IEEE Access. 2019;7:55305-55317
  15. 15. Odloak D. Extended robust model predictive control. AIChE Journal. 2004;50(8):1824-1099
  16. 16. Santoro BF, Odloak D. Closed-loop stable model predictive control of integrating systems with dead time. Journal of Process Control. 2012;22(7):1209-1218
  17. 17. Abreu OSL. Stabilizing model predictive control applied to open-loop unstable and integrating systems (in Portuguese) [Master dissertation]. Federal University of Bahia; 2018
  18. 18. Quanser. Inverted Pendulum Experiment for Matlab/Simulink Users; 2011
  19. 19. Yamashita AS, Santoro BF, Martins MAF, Odloak D. Application of an infinite horizon mpc to a nonlinear open-loop unstable reactor system. In: 8th International Conference on Integrated Modeling and Analysis in Applied Control and Automation, IMAACA. 2015. pp. 22-28
  20. 20. Qin SJ, Badgwell TA. A survey of industrial model predictive control technology. Control Engineering Practice. 2003;11(7):733-764
  21. 21. Muske KR, Rawlings JB. Model predictive control with linear models. AIChE Journal. 1993;39(2):262-287. ISSN 0001-1541

Written By

Odilon S.L. de Abreu, Márcio A.F. Martins and Leizer Schnitman

Submitted: November 12th, 2019 Reviewed: February 5th, 2020 Published: March 7th, 2020