You are on page 1of 10

Model composition and controller design of an inverted pendulum system.

EERI 321
Andrew Geldenhuys 31648118

ELECTROMECHANICAL ENGINEERING
North-West -University Potchefstroom Campus

Abstract
The practical involves a comprehensive analysis of the control system for stabilizing the pendulum's angle.
Both nonlinear and linear dynamic models is derived. The non-linear model is modelled through Simulink.
The linear model is further derived and simulated in MATLAB, leveraging the Runge-Kutta method to
solve the set of differential equations. Comparing the behaviours of the linear and nonlinear models
illuminates the efficacy of linearization as an approximation. A controller is devised to stabilize the
pendulum's angle. The controllers are subsequently evaluated across both the linear and nonlinear models.
The outcomes of these evaluations are discussed, shedding light on the control system's performance, its
ability to meet prescribed settling time, angle constraint, and steady-state error criteria, and its robustness.
Keywords:

1. Introduction
1.1. Background
The inverted pendulum on a cart problem is an intuitive example of the fundamentals of control theory
and robotics. It has been studied since the 20th century when researchers began exploring the stability and
control of systems with a non-linear nature. Control theory serves an integral part in the inverted pendulum
problem. The systems dynamic nature and inherent non-linearity provides an ideal opportunity for
evaluating nonlinear control systems such as state-space control, optimal control and even artificial-
intelligence based methods. The theoretical problem has since made its way into practical applications and
serves as a benchmark for teaching concepts in control theory. Beyond educational purposes the real-world
practical applications of this can be seen in the self-balancing Segways and Hoverboards.
1.2. Problem statement
The system involves a freely rotating pendulum that is mounted atop a moving cart that is only allowed
move horizontally. The pendulum and the cart are limited to only two dimensions and the cart’s motion
influences the motion of the pendulum and vice versa. The focus of this practical is to stabilize the angle
of the pendulum in the upright position by moving the cart with an applied force. The position of the cart
is not the focus of this practical.
1.3. Literature review
The first solution to the inverted pendulum problem was by James K. Roberge in 1960 for his bachelor’s
thesis [1]. This established the groundwork for stability analysis and control strategies for unstable
systems. Classical control methods, such as Proportional-Integral-Derivative (PID) control, are commonly
employed to stabilize the pendulum's angle [2]. The evolution of control theory spurred the adoption of
state-space control techniques, enabling multivariable control strategies that consider both pendulum angle
and cart position. The introduction of the Linear-Quadratic-Regulator (LQR) offered enhanced stability
and performance through rigorous mathematical optimization [3].
1.4. Research objective
1
At the heart of this practical lies the intricate dynamics of the pendulum’s behaviour. By deriving and
modelling the systems dynamic equations, insights into the underlying responses and interactions are
gained. While the non-linear model captures the intricacies of the systems behaviour, the linearized model
provides a simplified representation of the model, allowing a straightforward analysis of the control system
requirements.
By modelling a controller that operates the motion of the cart, to stabilize the pendulum's angle, we address
the performance criteria. The settling time is targeted to be less than 5 seconds, ensuring a swift response.
Additionally, to safeguard against extreme instability, the pendulum's angle is constrained to remain within
20 degrees (approximately 0.35 radians) from the vertical. The requirement for a steady-state error below
2% underscores the precision demanded.
1.5. Methodology
It begins with deriving the dynamic equations governing the inverted pendulum-cart system's behaviour.
Subsequently, a nonlinear model is implemented in Simulink, visually capturing system interactions. The
linear model is then derived through linearization, followed by its simulation using the Runge-Kutta
method. Comparative analysis of the nonlinear and linear models allows the determination of applicable
requirements. Designing a control system involves crafting a controller, for pendulum angle stabilization.
Controller implementation and evaluation across both models test its efficacy.
1.6. Paper Structure
The paper starts with an abstract that provides a brief overview of the paper, its objectives, methods, key
findings, and conclusions. The introduction should provide the background of the inverted pendulum on
a cart practical, including the problem statement, objectives, and significance of the work. The literature
review reviews the relevant literature on the control of inverted pendulums. The model development
section is used to derive the mathematical model of the inverted pendulum on a cart and simulate the
model to analyse its dynamics. The controller design section describes the design a controller for the
inverted pendulum on a cart, justify the choice of controller, and discuss its parameters. The experiments
and results section evaluates the performance of the controller through experiments and present the results
of the experiments, including the settling time, steady-state error, and robustness to disturbances. The
discussion and conclusion section discusses the findings of the experiments and the implications of the
work and provide recommendations for future work.
2. Model derivation
2.1. Non-linear model derivation

Figure 1: Free body diagram of the inverted pendulum on a cart


2
The motion of the inverted pendulum system can be represented by Newton’s second law of motion. The
law states that when a force acts upon a body it will cause the body to accelerate in the direction of the
force. With Newtons second law, the following equations are derived to describe the forces and motion of
the pendulum and the cart,
𝑑2 𝑥
𝐹 – 𝐻 = 𝑚2 𝑑𝑡 2 , (1)
𝑑2 (𝑙−𝑙𝑐𝑜𝑠𝜃)
𝑚1 𝑔 − 𝑉 = 𝑚1 𝑑𝑡 2
, (2)
𝑑2 (𝑥−𝑙𝑠𝑖𝑛𝜃)
𝐻 = 𝑚1 𝑑𝑡 2
. (3)
Considering the angular motion of the pendulum and knowing that the sum of torques on the pole is equal
to zero, the following formula can be derived,
` 𝑉𝑙𝑠𝑖𝑛𝜃 − 𝐻𝑙𝑐𝑜𝑠𝜃 = 0. (4)
By substituting equations (3.3) and (3.4) into equation (3.5) thee following equation is derived.
𝑑2 (−𝑙𝑐𝑜𝑠𝜃) 𝑑2 (𝑥−𝑙𝑠𝑖𝑛𝜃)
(𝑚1 𝑔 + 𝑚1 ) 𝑙𝑠𝑖𝑛𝜃 − (𝑚1 ) 𝑙𝑐𝑜𝑠𝜃 = 0, (5)
𝑑𝑡 2 𝑑𝑡 2

Now substitute equation (3.4) into equation (3.2).


𝑑2 𝑥 𝑑2 (𝑥−𝑙𝑠𝑖𝑛𝜃)
𝐹 = 𝑚2
𝑑𝑡2
+ 𝑚1
𝑑𝑡2
, (6)
Substituting the identities of second order derivatives of trigonometry, into equations (3.6) and (3.7) results
in the two nonlinear equations below,
𝑑2 𝑥 𝑑2 𝜃
𝑔𝑠𝑖𝑛𝜃 = 𝑐𝑜𝑠𝜃 𝑑𝑡 2 − 𝑙 𝑑𝑡 2 , (7)
𝑑2 𝑥 𝑑𝜃 2 𝑑2 𝜃
𝐹 = ( 𝑚1 + 𝑚 2 ) 𝑑𝑡 2 + 𝑙𝑚1 𝑠𝑖𝑛𝜃 ( 𝑑𝑡 ) − 𝑙𝑚1 𝑐𝑜𝑠𝜃 𝑑𝑡 2 , (8)
The systems non-linear behaviour is described by Equations (3.11) and (3.10), which can now be solved
𝑑2 𝑥 𝑑𝜃 𝑑2 𝜃
for 𝑥̈ and 𝜃̈ . Note that 𝐹 = 𝑢, 𝑥̈ = 2 , 𝜃̇ = and 𝜃̈ = 2 is respectively substituted resulting in the
𝑑𝑡 𝑑𝑡 𝑑𝑡
following nonlinear equations.
𝑔𝑠𝑖𝑛𝜃( 𝑚1 +𝑚 2 )−𝑢 𝑐𝑜𝑠𝜃− 𝑙𝑚1 𝑐𝑜𝑠𝜃𝑠𝑖𝑛𝜃𝜃 ̇2
𝜃̈ = , (9)
−𝑙𝑚 𝑐𝑜𝑠 2 𝜃 +( 𝑚 +𝑚 )𝑙
1 1 2
2
𝑙𝑚1 𝑠𝑖𝑛𝜃(𝜃̇) −𝑔𝑚1 𝑐𝑜𝑠𝜃𝑠𝑖𝑛𝜃+𝑢
𝑥̈ = (𝑚1 +𝑚 2 −𝑚1 𝑐𝑜𝑠 2 𝜃)
(10)

2.2. Linear model derivation


The linear model of the inverted pendulum is derived from the non-linear model by linearizing around the
vertical reference θ = 2π radians or θ = 0 radians. This allows for the assumptions (A.17), (A.18) and
(A.19), found in Appendix A, to be substituted into the non-linear behavioural equations (9) and (10). The
linear behavioural equations is derived in Appendix A, resulting in equations (11) and (12):

𝑔𝜃( 𝑚1 +𝑚 2 )−𝑢
𝜃̈ = , (11)
𝑚 𝑙 2
𝑢−𝑔𝑚1 𝜃
𝑥̈ = 𝑚2
. (12)

3
The linear equations can now be written as a state space model:
0 1 0 0 0
𝑥̇ −𝑔𝑚1 𝑥 1
𝑥̈ 0 0 0
𝑚2 𝑥̇ 𝑚2
[𝜃̇ ] = 0 0 0 1 [𝜃 ] + 0 𝑢 (𝑡 ) . (13)
𝜃̈ 𝑔( 𝑚1 +𝑚 2 )
0] 𝜃̇
1
[0 0 𝑚 2𝑙 [− 𝑚 𝑙]2

The state space model is used to describe the linear behaviour of the inverted pendulum.

3. Model simulation
3.1. Non-linear model simulation
The non-linear model of the inverted pendulum was implemented within the Simulink environment. The
schematic is based on equations (9) and (10).

Figure 2: Non-linear model in Simulink

A simulated step input is used to simulate the pushing of the cart. The response of the position of the cart
and the angle deviation of the pole is measured for 10 seconds and the result is represented in Figure 3
below.

4
Figure 3:The Position and angle deviation of the nonlinear system due to a step input

The response of the nonlinear model shown in Figure 3 above, describes the behaviour of the system when
a disturbance is induced on the system. Note the solid line, which describes the position of the cart,
accelerates in the direction of the applied force due to there being no frictional force for this ideal case.
The pendulums falls from an initial upright position and continues to sway in the bottom half a few times
and then it continues to oscillate in the down position.
3.2. Linear model simulation
The linear model is simulated within the Simulink environment. By using the linear state space model, the
following schematic was implemented and a step signal was used as the force input.

Figure 4:Scematic of linear model in Simulink

The response of the linear model was recorded for 1.5 seconds.

5
Figure 5: Response of the linear model

From Figure 5 the response due to a disturbance shows that the pendulum angle, shown as a dashed line
decreases at a faster rate than the position of the cart.
Runga Kutta is also used to determine the set of first order functions from the second order functions
Equations 9 and 10. The Linear model can then be determined in MATLAB and the response is represented
in figure below.

3.3. Linear and non-linear model comparison


The angular displacement for the linear and nonlinear model is compared and represented in Figure 6
6
below.

Figure 6: Comparing the resulting angular displacement of the Linear and nonlinear models when a force is applied.

Note that the linear and nonlinear model does not look similar, and this is due to the linearization which
eliminates the oscillations by means of approximations.
4. Controller design for angle control
The following sections discusses the control of the unstable system by means of a Proportional Integral
Derivative (PID) controller. PID controllers are widely used in industry to control linear systems, although
adjustments can be made to allow control of non-linear systems. A PID controller is a three-term controller
that contains a proportional gain, an integral gain, and a derivative gain term represented by KP, KI, and
KD respectively. The controllers transfer function is given as,
𝐾𝐼
𝐺𝑐 (𝑠) = 𝐾𝑃 + + 𝑠𝐾𝐷 . (14)
𝑠

The advantage is in its simplistic ability to regulate the systems transient and steady state behaviour with
only three gain values.
The controller is implemented in the linear and nonlinear systems to keep the pendulum in the upright
position and to make any corrections when a disturbance is applied to the cart, simultaneously adhering to
the performance requirements.

Now to determine the values of the PID controller we first derive the transfer function of the angle Ɵ(s)
with respect to the input U(s),
Ɵ(s) −4.1667
𝑇(𝑠) = 𝑈(𝑠) = 𝑠 2−34.7083. (15)

Noting that he characteristic equation of a second order system is in the form,


𝑠 2 + 2ζω𝑛 + ω2𝑛 , (16)
The damping coefficient ζ is equal to zero and the natural frequency ω𝑛 is equal to 5.891375 rad/s.
Now including the PID controller into the closed loop system the resulting characteristic equation is,
𝑠 3 − 4.147𝐾𝐷 𝑠 2 − (34.744 + 4.147𝐾𝑃 )𝑠 − 4.147𝐾𝐼 , (17)
7
The form of a third order characteristic equation is,
𝑠 3 + 1.75ω𝑛 𝑠 2 + 2.15ω2𝑛 𝑠 + ω3𝑛 , (18)
Now the values for KP, KI, and KD are found to be,
𝐾𝑃 = 26.375
𝐾I = 49.308
𝐾𝐷 = 2.486
4.1. Linear model with controller
The PID controller is derived to control the angular displacement of the linear model previously derived
in section (3.3). To integrate the PID controller with the linear model, requires the angular displacement
of the linear system to be determined. The resulting angular deviation from its upright position is then fed
into the PID controller. The sum of the controller output and the simulated disturbance is then fed into the
linear system. The schematic of the controlled linear system is shown in Figure 7 below.

Figure 7: Linear model integrated into a PID controller.

The simulation was allowed to run for 20 seconds, and two impulse disturbances were applied to the cart.
The resulting angle of the pendulum and input disturbance is measured and shown in Figure 8 below.

Figure 8:Angular deviation due to a force disturbance

8
Figure 8 is divided to show how a large disturbance of 50N, shown at the bottom, influences the angular
displacement of the linear PID controlled system. Note that the PID controller is designed for critical point
control. Further adjustments to the PID controller is required to insure robust operation when
implementing into practical systems.
4.2. Non-Linear model with controller
For the Non-linear model the PID controller is integrated in the same way as with the linear model. The
schematic of the controlled linear system is shown in Figure 9 below.

Figure 9: Nonlinear model integrated with a PID controller.

When a similar disturbance, as in the controlled linear model simulation, is applied to the non-linear
controlled system the following Figure 10 shows the measured results of the pendulum angle due to the
input disturbances.

Figure 10: Nonlinear model reaction with PID controller

Note how similar the reaction of the nonlinear model is when the a similar PID controller is used that is
designed for the linear system.
5. Results
9
To compare the linear and non-linear controlled systems is necessary to quantify the performance of the
controller’s ability to keep the pendulum in the upright position. The settling time, maximum deviation and
steady-state error is used to compare the two models and their respective performance due to a specific
disturbance.
From the outputs of the controlled linear and non-linear the following results were obtained and tabulated in
Table 1.

Table 1: Property comparison of controlled Linear and nonlinear system.

Parameters Controlled Linear Model Controlled Non-linear Model


Maximum Deviation 0.01211 rad 0.01214 rad
Steady-State Error 0.43e-6 rad 0.01589e-6 rad
Settling Time 998.901 ms 987.223 ms

From the results the required specifications are met graciously. The PID controller thus meets the
requirements for both the Linear and the non-linear model.
Comparing the linear model with the non-linear mode l one can see that for the linear model the Maximum
angular deviation is less than the non-linear model by just 0.003e-3 radians. The Steady state error for both
models is below the required specifications, and the difference between the models is 0,41411e-6 radians.
The settling time for the non-linear model is 11.678 ms before the linear model.
6. Conclusion
The linear and nonlinear models for the pendulum were successfully derived and simulated in the Simulink
environment. Runge Kutta’s method was used to derive the linear model state space model from the non-
linear model. The design of the PID controller was based on the linear model and the critical controller was
implemented into the Simulink environment for both the linear and nonlinear models. The performance of
the controller’s ability to regulate the angle of the pendulum successfully met the specifications required
from the practical. Comparing the linear and nonlinear models there is not a lot of similarity in the angle
deviation. Although it was noted that when designing a controller for a nonlinear system, the linear model
of the system can be used to design a PID controller that will react in a similar way to a non-linear system
with the same controller. The practical gave invaluable insights into the modeling and design of a controller
for unstable systems. The work done here can be further integrated into a micro controller to allow for the
control of a pendulum on a track.
7. References
[1] J. K. Roberge, “The mechanical seal,” Massachusetts Institute of Technology, Cambridge, 1960.
[2] Z. Tieyan, Z. Yan, Z. Xiaohui and Z. Dan, “Robust controller design for uncertain nonlinear systems via adaptive fuzzy PID approach,” in
Proceedings of the 31st Chinese Control Conference, 2012, pp. 2771-2774.
[3] P. Scokaert and . J. Rawlings, “Constrained linear quadratic regulation,” IEEE Transactions on Automatic Control, vol. 43, no. 8, pp. 1163-
1169, Aug 1998.
[4] M. F. Golnaraghi and B. C. Kuo, “Automatic Control Systems,” Wiley, 2019.

10

You might also like