Modelling & Simulation For Optimal Control of Nonlinear Inverted Pendulum Dynamical System Using PID Controller & LQR
Modelling & Simulation For Optimal Control of Nonlinear Inverted Pendulum Dynamical System Using PID Controller & LQR
Modelling & Simulation For Optimal Control of Nonlinear Inverted Pendulum Dynamical System Using PID Controller & LQR
Abstract—This paper presents the modelling and simulation system response and performance. The simplicity of control
for optimal control design of nonlinear inverted pendulum-cart algorithm as well as to guarantee the stability and robustness
dynamic system using Proportional-Integral-Derivative (PID) in the closed-loop system is challenging task in real
controller and Linear Quadratic Regulator (LQR). LQR, an situations. Most of the dynamical systems such as power
optimal control technique, and PID control method, both of systems, missile systems, robotic systems, inverted
which are generally used for control of the linear dynamical pendulum, industrial processes, chaotic circuits etc. are
systems have been used in this paper to control the nonlinear highly nonlinear in nature. The control of such systems is a
dynamical system. The nonlinear system states are fed to LQR challenging task.
which is designed using linear state-space model. Inverted
The Proportional-Integral-Derivative (PID) control gives
pendulum, a highly nonlinear unstable system is used as a
benchmark for implementing the control methods. Here the
the simplest and yet the most efficient solution to various
control objective is to control the system such that the cart real-world control problems. Both the transient and steady-
reaches at a desired position and the inverted pendulum state responses are taken care of with its three-term (i.e. P, I,
stabilizes in upright position. The MATLAB-SIMULINK and D) functionality. Since its invention the popularity of
models have been developed for simulation of control schemes. PID control has grown tremendously. The advances in digital
The simulation results justify the comparative advantages of technology have made the control system automatic. The
LQR control methods. automatic control system offers a wide spectrum of choices
for control schemes, even though, more than 90% of
Keywords—Inverted pendulum; nonlinear system; PID industrial controllers are still implemented based around the
control; optimal control; LQR PID algorithms, particularly at the lowest levels, as no other
controllers match with the simplicity, clear functionality,
I. INTRODUCTION applicability, and ease of use offered by the PID controller.
The performance of the dynamical systems being
The Inverted Pendulum is an inherently open loop & controlled is desired to be optimal. There are many
closed loop unstable system with highly nonlinear dynamics. optimization & optimal control techniques which are present
This is a system which belongs to the class of under-actuated in the literatures for linear & nonlinear dynamical systems
mechanical systems having fewer control inputs than degrees [5-7]. The recent development in the area of artificial
of freedom. This renders the control task more challenging intelligence (AI), such as artificial neural network (ANN),
making the inverted pendulum system a classical benchmark fuzzy logic theory (FL), and evolutionary computational
for the design, testing, evaluating and comparing of different techniques such as genetic algorithm (GA), and particle
classical & contemporary control techniques. swarm optimization (PSO) etc., commonly all these are
The inverted pendulum is among the most difficult known as intelligent computational techniques which have
systems being an inherently unstable system, is a very given novel solutions to the various control system problems.
common control problem, and so being one of the most The intelligent optimal control has emerged as viable recent
important classical problems, the control of inverted approach by the application of these intelligent
pendulum has been a research interest in the field of control computational techniques [8-18].
engineering. Due to its importance this is a choice of There are many literatures present which have taken
dynamic system to analyze its dynamic model and propose a inverted pendulum-cart dynamical system for implementing
control law. The aim of this case study is to stabilize the the various control schemes [16-21]. Linear quadratic
Inverted Pendulum (IP) such that the position of the cart on regulator (LQR), an optimal control method, and PID control
the track is controlled quickly and accurately so that the which are generally used for control of the linear dynamical
pendulum is always erected in its inverted position during systems have been used in this paper to control the nonlinear
such movements. Realistically, this simple mechanical inverted pendulum-cart dynamical system. In recent trends
system is representative of a class of altitude control even the various advance control approaches are developing
problems whose goal is to maintain the desired vertically and being tried for many dynamical systems control, the
oriented position at all times [1-4]. proposed control method is simple, effective, and robust.
In general, the control problem consists of obtaining This paper is organized in 5 sections. Section I presents
dynamic models of systems, and using these models to the relevance & the general introduction of the paper.
determine control laws or strategies to achieve the desired Section II describes the mathematical model of the inverted
139
g sin θ − lθ into the nonlinear vector function, f (x, u , t ) , then the
x=
cos θ linearized form for the system becomes
and putting this into eqn. (4) gives d
δ x = J x (x0 , u0 )δ x + J u (x 0 , u0 )δ u (17)
( M + m)( g sin θ − lθ) dt
− ml sin θθ 2 + ml cos θθ = u where, the reference state is defined with the pendulum
cos θ
or stationary and upright with no input force. Under these
conditions, x 0 = 0 , and u 0 = 0 .
( M + m)( g sin θ − lθ) − ml cos θ sin θθ 2
Since the nonlinear vector function is rather complicated, the
+ ml cos 2 θθ = u cos θ components of the Jacobian matrices are determined
and systemically, term by term. The elements of the first second,
(ml cos 2 θ − ( M + m)l )θ = u cos θ third, and fourth columns of J x (x0 , u0 ) are given
(11)
−( M + m) g sin θ + ml cos θ sin θθ 2 ∂f i ∂f i ∂f i ∂f i
by , , , and respectively.
Finally, dividing by the lead coefficients of eqns. (10) and ∂x1 ∂x2 ∂x3 ∂x4
x0 ,u 0 x0 ,u 0 x0 ,u 0 x0 ,u 0
(11) gives
Thus, combining all these separate terms gives
u + ml (sin θ )θ 2 − mg cos θ sin θ
x=
(12) ª 0 1 0 0º
M + m − m cos 2 θ « ( M + m) g »
u cos θ − ( M + m) g sin θ + ml (cos θ sin θ )θ « 0 0 0»
θ = (13) « Ml »
ml cos 2 θ − ( M + m)l J x ( x 0 , u0 ) = « (18)
0 0 0 1»
Now these equations may be represented into state space « »
form by considering the state variables as following: « mg »
«¬ − M 0 0 0»
x1 = θ x2 = θ = x1 x3 = x x4 = x = x3 (14) ¼
Then, the final state space equation for the inverted For the derivative of the nonlinear terms with respect to u,
pendulum system may be written as we have
ª x1 º ªθ º ª f1 º ª ∂f1 ∂u º
«x » « » «f »
d d d θ «∂f ∂u »»
x = « 2» = « » = « 2» (15) J u ( x 0 , u0 ) = « 2
dt dt « x3 » dt « x » « f 3 » « ∂f 3 ∂u »
« » « » « » « »
¬ x4 ¼ ¬ x ¼ ¬ f 4 ¼
¬∂f 4 ∂u ¼ x ,u
where, f1 = x2 , f 3 = x4 , and 0 0
ª 0 º ª 0 º
u cos x1 − ( M + m) g sin x1 + ml (cos x1 sin x1 ) x22 « » (19)
f2 = cos x « −1 »
ml cos 2 x1 − ( M + m)l « 1 » « »
« ml cos 2 x1 − ( M + m)l » « Ml »
u + ml (sin x1 ) x22 − mg cos x1 sin x1 =« » =« »
f4 = « 0 » 0
M + m − m cos 2 x1 « »
« 1 » « 1 »
This expression is now in the desired form as given in eqn. « »
2 «¬ M »¼
(9). If both the pendulum angle θ and the cart position x are ¬ M + m − m cos x1 ¼ x 0 , u0
the variables of interest, then the output equation may be
Finally, after all these manipulations eqn. (17) may be
written as
written explicitly as
ªθ º
« » ª 0 1 0 0º ª 0 º
θ
ª º ª 1 0 0 0 º «θ » « ( M + m) g » « −1 »
y = Cx or y = « » = Cx = « » (16) «
¬ x¼ ¬0 0 1 0¼ « x » 0 0 0» « »
d
« » δ x = «« Ml »
δ x + «« Ml »» δ u (20)
¬ x ¼ dt 0 0 0 1» 0
« » « »
Equations (15) and (16) give a complete state space « mg » « »1
representation of the nonlinear inverted pendulum-cart «¬ − M 0 0 0»
¼ «¬ M »¼
dynamic system.
This is the open loop linearized model for the inverted
C. Linear System Equations of Inverted Pendulum pendulum with a cart force, δ u (t ) , (written in perturbation
The linear model for the system around the upright form). Thus, LTI system is in standard state space form. The
stationary point is derived by simply linearization of the eqn. (20) may be written in general as
nonlinear system given in eqn. (15). Since the usual A and d
B matrices are zero for this case; and so every term is put δ x = Aδ x + Bδ u (21)
dt
140
Equation (21) along with the output eqn. (16) represents the T
J = ³ ( X QX + u Ru ) dt
T
(13)
final linear model of the inverted pendulum-cart system. This
where, Q and R are positive semi-definite and positive
is the simplified model which is used to study the system
definite symmetric constant matrices respectively.
behaviour and LQR design.
The LQR gain vector K is given by
III. CONTROL METHODS K = R −1 BT P (14)
where, P is a positive definite symmetric constant matrix
To control the nonlinear inverted pendulum-cart
obtained from the solution of matrix algebraic reccatti
dynamical system the following control methods are
equation (ARE)
presented in this paper.
AT P + PA − PBR −1 BT P + Q = 0 (15)
A. PID Control In the optimal control of nonlinear inverted pendulum
To stabilize the inverted pendulum in upright position dynamical system using PID controller & LQR approach, all
and to control the cart at desired position using PID control the instantaneous states of the nonlinear system, pendulum
approach two PID controllers- angle PID controller, and cart angle θ , angular velocity θ , cart position x , and cart velocity
PID controller have been designed for the two control loops x have been considered available for measurement which are
of the system. The equations of PID control are given as directly fed to the LQR. The LQR is designed using the
following: linear state-space model of the system. The optimal control
de (t ) value of LQR is added negatively with PID control value to
u p = K pp eθ (t ) + K ip ³ eθ (t ) + K dp θ (9)
dt have a resultant optimal control. The tuning of the PID
de (t ) controllers which are used here either as PID control method
uc = K pc ex (t ) + Kic ³ ex (t ) + K dc x (10) or PID+LQR control methods is done by trial & error
dt method and observing the responses achieved to be optimal.
where, eθ (t ) and ex (t ) are angle error and cart position error.
Since the pendulum angle dynamics and cart position IV. SIMULATION & RESULTS
dynamics are coupled to each other so the change in any The MATLAB-SIMULINK models for the simulation of
controller parameters affects both the pendulum angle and modelling, analysis, and control of nonlinear inverted
cart position which makes the tuning tedious. The tuning of pendulum-cart dynamical system have been developed. The
controller parameters is done using trial & error method and typical parameters of inverted pendulum-cart system setup
observing the responses of SIMULINK model to be optimal. are selected as [16,20]: mass of the cart (M): 2.4 kg, mass of
B. Optimal Control using LQR the pendulum (m): 0.23 kg, length of the pendulum (l): 0.36
m, length of the cart track (L): ± 0.5 m, friction coefficient of
Optimal control refers to a class of methods that can be the cart & pole rotation is assumed negligible.
used to synthesize a control policy which results in best After linearization the system matrices used to design
possible behavior with respect to the prescribed criterion (i.e. LQR are computed as below:
control policy which leads to maximization of performance).
The main objective of optimal control is to determine control ª 0 1 0 0º ª 0 º
signals that will cause a process (plant) to satisfy some « 29.8615 0 0 0 »» « −1.1574 »
physical constraints and at the same time extremize A=« , B=« »
(maximize or minimize) a chosen performance criterion « 0 0 0 1» « 0 »
« » « »
(performance index (PI) or cost function). The optimal ¬ −0.9401 0 0 0¼ ¬ 0.4167 ¼
control problem is to find a control which causes the ª1 0 0 0º ª0º
dynamical system to reach a target or follow a state variable C=« » , and D = « »
(or trajectory) and at the same time extremize a PI which ¬0 0 1 0¼ ¬0¼
may take several forms [1,4-7]. With the choice of
Linear quadratic regulator (LQR) is one of the optimal
control techniques, which takes into account the states of the
ª1 0 º 0 0
dynamical system and control input to make the optimal «0 1 0 0 »
Q=« », and R =1 ,
control decisions. This is simple as well as robust [1,4-7].
After linearization of nonlinear system equations about «0 0 500 0
»
the upright (unstable) equilibrium position having initial «¬0 0 0 250»¼
T we obtain LQR gain vector as following:
conditions as X 0 = [0, 0, 0, 0] , the linear state-space
K = [ −137.7896 −25.9783 −22.3607 −27.5768]
equation is obtained as
X = AX + Bu (11) Here three control schemes have been implemented for
optimal control of nonlinear inverted pendulum-cart
where, X = [θ , θ, x, x ] .
T
dynamical system: 1. PID control method having two PIDs
The state feedback control u = − KX leads to i.e. angle PID & cart PID, 2. Two PIDs (i.e. angle PID & cart
X = ( A − BK ) X (12) PID) with LQR control method, 3. One PID (i.e. cart PID)
where, K is derived from minimization of the cost function with LQR control method. Both alternatives of PID+LQR
141
control method are similar in all respect of control 5
-3
x 10 PID CONTROL OF NONLINEAR INVERTED PENDULUM SYSTEM
theta (rad)
used. The SIMULINK models for these control schemes are 0
shown in Figs. 2, 4, and 6 respectively. The corresponding
simulation results are shown in Figs. 3, 5, and 7 respectively. -5
0 1 2 3 4 5 6 7 8 9 10
The reference angle has been set to 0 (rad), and reference 0.1
cart position is set to 0.1 (m). The tuned PID controller
parameters of these control schemes are given as in table I.
x(m)
0
control u
PID -40 0 -8 -1 0 -3
0
2 PID+LQR 1 1 1 1.5 -7.5 5
1 PID+LQR --- --- --- 1.5 -7.5 5
-0.2
0 1 2 3 4 5 6 7 8 9 10
PID control response is shown in Fig. 3. It is observed time (sec)
PID controller (cart PID) with LQR control method is shown Ref. Angle
Angle PID Controller
Control u
position x , cart velocity x , and control u have been plotted. Inverted Pendulum
10
PID control, which are smooth & fast also. It is also
observed that the responses of 2PID+LQR control and cart 5
u
Angle PID Controller
Theta
0.1 u
PID Theta -0.2
Ref. position
Saturation x 0 1 2 3 4 5 6 7 8 9 10
Cart PID Controller
Inverted Pendulum
time (sec)
Pulse Generator x
pendulum system with Angle PID , Cart PID & LQR Control.
142
OPTIMAL CONTROL OF NONLINEAR INVERTED PENDULUM S YS TEM US ING CART PID & LQR
REFERENCES
Control u
[1] K. Ogata, Modern Control Engineering, 4th ed, Pearson Education
Theta
0.1
PID thetadot
(Singapore) Pvt. Ltd., New Delhi, 2005, Chapter 12.
Ref. Cart Position u
10
[6] M. N. Bandyopadhyay, Control Engineering: Theory and Practice,
5 Prentice Hall of India Pvt. Ltd., New Delhi, 2004, Chapter 13.
0 [7] Roland S. Burns, Advanced Control Engineering, Elsevier -
Butterworth Heinemann, 2001, Chapters 9 & 10.
-5
0 1 2 3 4 5 6 7 8 9 10 [8] Astrom K. J., and McAvoy Thomas J., “Intelligent control”, J. Proc.
0.1 Cont. 1992, Vol. 2, No 3, pp 115-127.
[9] T. I. Liu, E. J. Ko, and J. Lee, “Intelligent Control of Dynamic
x and xdot
0 Systems”, Journal of the Franklin Institute, Vol. 330, No. 3, pp. 491-
503, 1993.
-0.1
0 1 2 3 4 5 6 7 8 9 10
[10] Yasar Becerikli, Ahmet Ferit Konar, and TarÕq Samad, “Intelligent
optimal control with dynamic neural networks”, Elsevier Journal of
0.2
Neural Networks, Vol. 16, 2003, pp 251–259.
0
[11] Kevin M. Passino, and Stephen Yurkovich, Fuzzy Control, Addison
u
143