Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Sci.Int.

(Lahore),27(2),1063-1068,2015 ISSN 1013-5316; CODEN: SINTE 8 1063

CONTROL OF INVERTED PENDULUM CART SYSTEM BY USE OF


PID CONTROLLER
1
Mohammad Ali Eizadiyan, 2Majid Naseriyan
1,2
Department of Electrical Eng., Mehriz Branch. Islamic Azad University. Mehriz.Iran
Contact: TEL: +983525229100; FAX: +983525229102; meizadiyan@yahoo.com
ABSTRACT; In this paper, we have tried to control the nonlinear inverted pendulum-cart dynamic system
by the use of Proportional-Integral-Derivative (PID) controller.
We know that the inverted pendulum-cart dynamic system is an inherently unstable and nonlinear system
when we want to use PID controller for it, we should change the system to a linear system, then we can apply
a PID controller on it, to this end we will use Linear Quadratic Regulator (LQR). LQR is an optimal control
technique. Duration the paper simulation results are presented to verify the effectiveness of the proposed
control.

Keywords; Inverted Pendulum; nonlinear system; inherently unstable; PID; control; LQR.

INTRODUCTION The control of the inverted pendulum and, which was


The control of the inverted pendulum and, which was The Proportional-Integral-Derivative (PID) control gives the
proposed in [1], has been studied by many authors, [2, 3, 4] simplest and yet the most efficient solution to various real-
and it is a common example in Control Theory. The main world control problems. Both the transient and steady state
characteristics that make it an interesting case of study are responses are taken care of with its three-term (i.e. P, I, and
that it is a strongly nonlinear, unstable, non minimum- D) functionality. Since its invention the popularity of PID
phase, which affects stability margins and robustness, and control has grown tremendously. The advances in digital
under actuated system (there is only one actuator for more technology have made the control system automatic. The
degrees of freedom) and, therefore, a difficult and complex automatic control system offers a wide spectrum of choices
system to be controlled that has been used as a benchmark for control schemes, even though, more than 90% of
to compare different control strategies. Nearly all works on industrial controllers are still implemented based around the
pendulum control concentrate on two problems: pendulums PID algorithms, particularly at the lowest levels, as no other
swing up control design and stabilization of the inverted controllers match with the simplicity, clear functionality,
pendulums. In this paper, optimal nonlinear stabilization applicability, and ease of use offered by the PID controller.
problem is addressed: stabilize IPC minimizing an The performance of the dynamical systems being controlled
accumulative cost functional quadratic in states and is desired to be optimal. There are many optimization &
controls. For linear systems, this leads to linear feedback optimal control techniques which are present in the
control, which is found by solving a Riccati equation [5], literatures for linear & nonlinear dynamical systems[5-7].
and thus referred to as linear quadratic regulator (LQR). The recent development in the area of artificial intelligence
The inverted pendulum has two equilibrium points, one of (AI), such as artificial neural network (ANN), fuzzy logic
which is stable while the other is unstable. On the one hand, theory (FL), and evolutionary computational techniques
the stable equilibrium point corresponds to a state in which such as genetic algorithm (GA), and particle swarm
the pendulum is pointing downwards. In the absence of any optimization (PSO) etc., commonly all these are known as
control force, the system will naturally return to this state. intelligent computational techniques which have given
On the other hand, the unstable equilibrium point is novel solutions to the various control system problems.
upwards. The different control strategies try to reach and The intelligent optimal control has emerged as viable recent
maintain this unstable equilibrium position. approach by the application of these intelligent
IPC, however, is a highly nonlinear system, and its computational techniques [8-18]. There are many examples
linearization is far from adequate for control design in literature in which the inverted pendulum-cart dynamical
purposes. Nonetheless, the LQR will be considered as a system has been applied in implementing the various
baseline controller for our work. control schemes [16-21]. Linear quadratic regulator (LQR),
In general, the control problem consists of obtaining an optimal control method, and PID control which is
dynamic models of systems, and using these models to generally used for control of the linear dynamical systems
determine control laws or strategies to achieve the desired have been used in this paper to control the nonlinear
system response and performance. The simplicity of control inverted pendulum-cart dynamical system. In recent trends
algorithm as well as to guarantee the stability and even the various advance control approaches are developing
robustness in the closed-loop system is challenging task in and being tried for many dynamical systems control, the
real situations. Most of the dynamical systems such as proposed control method is simple, effective, and robust.
power systems, missile systems, robotic systems, inverted Description mathematical modelling
pendulum, industrial processes, chaotic circuits etc. are Inverted pendulum system equations
highly nonlinear in nature. The control of such systems is a The free body diagram of an inverted pendulum mounted on
challenging task. a motor driven cart is shown in Fig. 1 [1-4]. The system
equations of this nonlinear dynamic system can be derived
March-April
1064 ISSN 1013-5316; CODEN: SINTE 8 Sci.Int.(Lahore),27(2),1063-1068,2015
as follows. It is assumed here that the pendulum rod is After manipulation (4) is written as:
5
mass-less, and the hinge is frictionless. In such assumption, .. ..

the whole pendulum mass is concentrated in the centre of m x cos  ml  mg sin 
gravity (COG) located at the center of the pendulum ball.
The cart mass and the ball point mass at the upper end of the Equations (3) and (5) are the defining equations for this
inverted pendulum are denoted as M and m, respectively. system. These two equations are manipulated algebraically
There is an externally x-directed force on the cart, u(t) , and to have only a single second derivative term in each
a gravity force acts on the point mass at all times. The equation. Finally, we may derive the system equations
coordinate system considered is shown in Fig. 1, where x(t) describing the cart position dynamics and the pendulum
 angle dynamics respectively. Thus we have:
u  mlsin    mg cos sin 
2
represents the cart position, and x (t) is the tilt angle
6
..

referenced to the vertically upward direction. A force x


M  m  m cos 
2
balance on the system in the x-direction can be written as
u cos  M  m g sin   mlcos sin  
2 2 .

M d xm d x 1 7


..
u 
ml cos   M  ml
2 2 G 2
dt dt
Where, the time-dependent centre of gravity (COG) of the Equations (6) and (7) represent a nonlinear system which is
point mass is given by the coordinates, (xG ,yG ). relatively complicated from a mathematical viewpoint.
For the point mass assumed here, the location of the center Following subsection presents the standard state space form
of gravity of the pendulum mass is simply of these two nonlinear equations.
XG= X+lsin and yG= lcos (2) Nonlinear system state space equations of inverted
Where l is the pendulum rod length. Substituting (2) into (1) pendulum
it is written as: For numerical simulation of the nonlinear model for the
M  m x ml sin    ml cos   u 3
.. .. ..
inverted pendulum-cart dynamic system, it is required to
represent the nonlinear equations (6) and (7) into standard
In a similar way, a torque balance on the system is state space form:
performed. Fig. 2 shows the force components acting on the
system. The resultant torque balance can be written as: d x  f  x, u , t  8
(Fx cos)l – (Fy sin)l = (mg sin)l (4)
2 2
dt
d d Considering the state variables as following:
Where, F m x and F m y are the
9
x 2 G y 2 .

x1   x2    x1 , x3  x x4  x  x3
G ' '
dt dt , ,
force components in x and y directions respectively. Then, the final state space equation for the inverted
pendulum system may be written as:

 x1     f 1 
  .  
d d  x2  d    f 2 
x     
dt dt  x3  dt  x   f 
   .   3 
x
 4  x   f 
 4
Where
f 1
 x2 11
u cos x1  M  m g sin x1  mlcos x1 sin x1 x2
2
Inverted Pendulum - Cart System
f  12
x  M  ml
..
Fig. 1 Motor driven inverted pendulum-cart system 2 2
ml cos 1

f x 13
3 4

u  mlsin x  x  mg cos x sin x


2

f  1 2 1 1
14
M  m  m cos x
4 2
1

Fig. 2 Vector diagram for force components in torque balance

March-April
Sci.Int.(Lahore),27(2),1063-1068,2015 ISSN 1013-5316; CODEN: SINTE 8 1065
If both the pendulum angle  Finally, after all these manipulations (16) may be written
variables of interest, then the output equation may be explicitly as
written as:  0 1 0 0  0
   M  m g   1
.  0 0 0  
1 0 0 0    x   Ml 
 x   Ml  u 19 T
  d
y  cx or y     cx     15 dt 0 0 0 1 0
x 0 0 1 0   x     
.   mg  1 
 x    M 0 0 0
  M 
Equations (10) and (15) give a complete state space his is the open loop linearized model for the inverted
representation of the nonlinear inverted pendulum-cart pendulum with a cart force, u(t) , (written in perturbation
dynamic system. form). Thus, LTI system is in standard state space form. The
Linear system state space equations of inverted equation (19) may be written in general as:
pendulum
Since the goal of this particular system is to keep the
d
 x  A x  B u 20
inverted pendulum in upright position around =0, the dt
linearization might be considered about this upright Equation (20) along with the output equation (15) represents
equilibrium point. The linear model for the system around the final linear model of the inverted pendulum-cart system.
the upright stationary point is derived by simply This is the simplified model which is used to study the
linearization of the nonlinear system given in (10). Since the system behavior in general and to design LQR.
usual A and B matrices are zero for this case; and so every Inverted pendulum system equations with disturbance
term is put into the nonlinear vector function, f (x,u, t) , then input
the linearized form for the system becomes: The system equations of this nonlinear dynamic system with
disturbance input can be derived as follows. Consider a
J x , u  x  J x , u  u 16
d
 x  x 0 0 u 0 0
disturbance input due to wind effects, acting on the inverted
dt pendulum in addition to force on the cart, u(t). Let Fw
Where, the reference state is defined with the pendulum represent the horizontal wind force on the pendulum point
stationary and upright with no input force. Under these mass. With this additional force component, the force
conditions, X0=0 , and u0=0. Since the nonlinear vector balance equation (1) becomes:
function is rather complicated, the components of the 2 2

Jacobian matrices are determined systemically, term by M d 2


xm d x 2 G
 u  Fw 21
term. The elements of the first second, third, and fourth dt dt
f which can be manipulated as to give:

J x , u  are given by
1
M  m x ml sin    ml cos   u  F w 22
.. .. ..

x 0 0
x
Columns of 1 , respectively.

Thus Combining all these separate terms gives: Similarly, the torque in the clockwise direction caused by
the horizontal wind disturbance is (Fx cos)l.
 0 1 0 0 Adding the torque contribution of this term the torque
 M  m g  balance equation (4) becomes:
 0 0 0
J x , u 
  (Fx cos)l – (Fy sin)l = (mg sin)l+(Fw cos)l (23)

Ml 17
0 0 1
x 0 0 Which can be modified to give:
0
 
24
.. ..

 mg  m x cos   ml   mg sin   F w cos 


  M 0 0 0
 Equations (22) and (24) are the defining equations for this
system with a disturbance input.
The state space equation for inverted pendulum system with
For the derivative of the nonlinear terms with respect to u ,
disturbance input is derived as same of equation (10) with
we have
following modification:
 f  M
 u cosx1 M  m  g sin x1 ml  cosx1sin x1 x 22  F w cosx1
u   0 
1
..
  
f 2 m
 25
ml cos2 x1 M  m  l
 f   1
 2
u    M 
J x , u 
u 0 0

 f
 
  0 
18 u  ml  sin x1 x 22  mg cosx1 sin x1 F wsin 2 x1

f 4  26 
u   1 
3
M  m  mcos2 x1
   
 f  M 
 4
u 
March-April
1066 ISSN 1013-5316; CODEN: SINTE 8 Sci.Int.(Lahore),27(2),1063-1068,2015
The output equation of the nonlinear inverted pendulum After linearization of nonlinear system equations about the
system with disturbance input remains same as equation upright (unstable) equilibrium position having initial
(15).
x 0,0,0,0
T
The linearized model can also be developed as following: conditions as 0 the linear state-space
 M 0m  g 1 0 0
  01  0  equation is obtained. as
 Ml 0 0 0 1
 
T
. x . Ax  Bu 31
 x   Ml  u   ml  F w
d
 x  27  Where x   ,  , x, x The state feedback control u=-Kx
dt  mg0 0 0 1   1  0 
0
leads to  
  M 0 0 0 
  M    32
.
0
x  ( A  BK ) x
This is the open loop linearized model for the inverted where, K is derived from minimization of the cost function:

pendulum with a cart force,  u t and a horizontal wind 
J   x Qx  u Ru dt
T T
 33
disturbance,  F w t  . The two inputs have been separated where, Q and R are positive semi-definite and positive
definite symmetric constant matrices respectively. The LQR
for convenience, thus the LTI system can be written as: gain vector K is given by:
d
 x  A x  b1 u  b2  F w 28
dt KR B P
1 T
34
CONTROL METHODS Where, P is a positive definite symmetric constant matrix
The following control methods are presented here to control obtained from the solution of matrix algebraic reccatti
the nonlinear inverted pendulum-cart dynamic system [3, 4]. equation (ARE):
3.1 PID control
To stabilize the inverted pendulum in upright position and A
T 1
P  PA  PB R B P  Q  0
T
35
to control the cart at desired position using PID control In the optimal control of nonlinear inverted pendulum
approach two PID controllersangle PID controller, and cart dynamical system using PID controller & LQR approach,
PID controller have been designed for the two control loops all the instantaneous
. states of the nonlinear
. system,
of the system. The equations of PID control are given as pendulum. Angle   cart position x ,
d e t 
and cart velocity have been considered available for
u p  k pp e t   k ip  e t dt  k dp 29 measurement which are directly fed to the LQR. The LQR
dt is designed using the linear state-space model of the system.
following: The optimal control value of LQR is added negatively with
d t  PID control value to have a resultant optimal control. The
u  k e t   k  e t dt  k edt
c pc x ic x dc
x
30 tuning of the PID controllers which are used here either as
PID control method or PID+LQR control methods is done
Where, e t  and ex t  are angle error and cart position
by trial & error method and observing the responses
achieved to be optimal.
error. Since the pendulum angle dynamics and cart position
dynamics are coupled to each other so the change in any SIMULATION & RESULTS
controller parameters affects both the pendulum angle and The MATLAB-SIMULINK models for the simulation of
cart position which makes the tuning tedious. The tuning of
modelling, analysis, and control of nonlinear inverted
controller parameters is done using trial & error method and pendulum-cart dynamical system have been developed. The
observing the responses of SIMULINK model to be typical parameters of inverted pendulum-cart system setup
optimal.
are selected as [16,20]: mass of the cart (M): 2.4 kg, mass of
Optimal Control using LQR the pendulum (m): 0.23 kg, length of the pendulum (l): 0.36
Optimal control refers to a class of methods that can be used m, length of the cart track (L): ± 0.5 m, friction coefficient
to synthesize a control policy which results in best possible
behavior with respect to the prescribed criterion (i.e. control
policy which leads to maximization of performance). The
main objective of optimal control is to determine control
signals that will cause a process (plant) to satisfy some
physical constraints and at the same time extremize
(maximize or minimize) a chosen performance criterion
(performance index (PI) or cost function). The optimal
control problem is to find a control which causes the
dynamical system to reach a target or follow a state variable of the cart & pole rotation is assumed negligible. After
(or trajectory) and at the same time extremize a PI which linearization the system matrices used to design LQR are
may take several forms [1-7]. computed as below:
Linear quadratic regulator (LQR) is one of the optimal
control techniques, which takes into account the states of  0 1 0 0  0 
the dynamical system and control input to make the optimal 29.8615 0 0 0  1.1574
control decisions. This is simple as well as robust [1-7]. A , B 
 0 0 0 1  0 
   
0.9401 0 0 0  0.4167 
March-April
Sci.Int.(Lahore),27(2),1063-1068,2015 ISSN 1013-5316; CODEN: SINTE 8 1067


1 0 0 0
C 0 0 1 0 ,  
0
and D  0

With the choice of

10 0 0
1 0
0
0 
Q  1
00 0 500 0
0 0 250
 and R we obtain LQR gain
vector as following:
K   137.7896  25.9783  22.3607  27.5768
Here three control schemes have been implemented for
optimal control of nonlinear inverted pendulum-cart
dynamical system: 1. PID control method having two PIDs
i.e. angle PID & cart PID, 2. Two PIDs (i.e. angle PID &
cart PID) with LQR control method, 3. One PID (i.e. cart Figure 3. Responses of pendulum angle , cart position x , and
PID) with LQR control method. Both alternatives of control
PID+LQR control method are similar in all respect of force u of nonlinear inverted pendulum system with PID
control techniques but they differ only in number of PID control.
controllers used. The SIMULINK models for these control
schemes are shown in Figs. 2, 4, and 6 respectively. The
corresponding simulation results are shown in Figs. 3, 5,
and 7 respectively.
The reference angle has been set to 0 (rad), and reference
cart position is set to 0.1 (m). The tuned PID controller
parameters of these control schemes are given as in table
PID control response is shown in Fig. 3. It is observed here
that the pendulum stabilizes in vertically upright position
after two small overshoots. The cart position x reaches the
desired position of 0.1 (m) quickly & smoothly. The control
input u is bounded in range [-0.1 0.1]. The response of
optimal control of inverted pendulum system using two PID
controllers (angle PID & cart PID) with LQR control
method is shown in Fig. 5, and using one PID controller
(cart PID) with LQR control method is shown in Fig. 7
respectively. Here for both control methods of PID+LQR
the responses of angle , cart position
x , cart velocity , and control u have been plotted. It is .
observed that in both control schemes the pendulum Figure 4. Responses of pendulum angle , angular velocity ,
stabilizes in vertically upright position quickly & smoothly cart
after two minor undershoots and a minor overshoot The CONCLUSION
angular velocity approaches 0 (rad/s) quickly. The cart In this paper we have introduced the nonlinear inverted
position x reaches smoothly the desired position of 0.1 (m) pendulum-cart dynamic system and by use of PID controller
quickly in approx. 6 seconds, and the cart velocity reaches and LQR, an optimal control technique to make the optimal
to zero. The control input u is bounded in range [-0.1 0.1]. control decisions, have been implemented to control this
Comparing the results it is observed that the responses of system. In the optimal control of nonlinear inverted
both alternatives of PID+LQR control method are better pendulum dynamical system using PID controller and LQR
than PID control, which are smooth & fast also. It is also approach all the instantaneous states of the nonlinear system
observed that the responses of 2PID+LQR control and cart are considered available for measurement, which are
PID+LQR control are similar. Since 2PID+LQR method has directly fed to the LQR. The tuning of the PID controllers
additional degree of freedom of control added by the angle which are used here either as PID control method or
PID controller, this will have overall better response under PID+LQR control methods is done by trial & error method
disturbance input. But the cart PID+LQR control has and observing the responses achieved to be optimal. The
structural simplicity in its credit. The performance analysis analysis of the responses of control schemes gives that the
of the control schemes gives that these control schemes are performance of proposed PID+LQR control method is better
effective & robust. than PID control. This comparative performance
position x , cart velocity ,and control force u of nonlinear investigation for this benchmark system establishes that the
inverted pendulum system with Angle PID , Cart PID & proposed PID+LQR control approach being simple,
LQR Control. effective & robust control scheme for the optimal control of
nonlinear dynamical systems.

March-April
1068 ISSN 1013-5316; CODEN: SINTE 8 Sci.Int.(Lahore),27(2),1063-1068,2015
ACKNOWLEDGMENT [15] Lal Bahadur Prasad, Krishna Pratap Singh, and Hema Latha
We acknowledge our friend, Mehdi fatemi and the Javvaji, “Simulation of Neuro-Fuzzy Position Controller for
Associate Editor and anonymous reviewers for their Induction Motor Drive using Simulink”, Proceedings of XXXI
valuable comments and suggestions that have helped us to National Systems Conference, NSC 2007, P-49, Dec. 14-15,
improving the paper. 2007, MIT Manipal, India.
[16] G. Ray, S. K. Das, and B. Tyagi, “Stabilization of Inverted
REFERENCES Pendulum via Fuzzy Control”, IE(I) Journal-EL, vol. 88, Sept.
[1] K. Furuta, M. Yamakita and S. Kobayashi, “Swing-up Control of 2007, pp. 58-62.
Inverted endulum Using Pseudo-State Feedback,” Journal[17] of C. W. Tao, J. S. Taur, C. M. Wang, and U. S. Chen, “ Fuzzy
Systems and Control, vol. 206, no. 4, pp. 263-269, 1992. hierarchical swing-up and sliding position controller for the
[2] K. Astrom and K. Furuta, “Swinging up a Pendulum by Energy inverted pendulum-cart system”, Elsevier Journal: Fuzzy Sets
Control,” Automatica, vol. 36, no. 2, pp. 287-295, 2000. and Systems, vol. 159, 2008, pp. 2763-2784.
[3] F. Leung, L. Wong and P. Tam, “Fuzzy Model Based Controller [18] Yanmei Liu, Zhen Chen, Dingyun Xue, and Xinhe Xu, “Real-
for an Inverted Pendulum,” Electronics Letters,vol. 32, no. 18, p. Time Controlling of Inverted Pendulum by Fuzzy Logic”,
1683 – 1685, 1996. Proceedings of the IEEE International Conference on
[4] J. Zhao and M. Spong, “Hybrid Control for Global Stabilization Automation and Logistics, Shenyang, China, August 2009, pp.
of the Cart-Pendulum System,” Automatica, vol. 37, no. 12, pp. 1180-1183.
1941-1951, 2001. [19] K. J. Astrom, and K. Furuta, “Swinging up a pendulum by
[5] G. F. Franklin, J. D. Powell, and A. Emami-Naeini. Feedback energy control”, Elsevier-Pergamon Journal: Automatica, vol.
control of dynamic systems. Addison- Wesley, 2 edition, 1991. 36, 2000, pp. 287-295.
[6] M. N. Bandyopadhyay, Control Engineering: Theory [20] and Debasish Chetergee, Amit Patra, and Harish K. Joglekar,
Practice, Prentice Hall of India Pvt. Ltd., New Delhi, 2004, “Swing-up and stabilization of a cart-pendulum system under
Chapter 13. restricted cart track length”, Elsevier Journal: Systems & Control
[7] Roland S. Burns, Advanced Control Engineering, Elsevier - Letters, vol. 47, 2002, pp. 355-364.
Butterworth Heinemann, 2001, Chapters 9 & 10. [21] Carlos Aguilar Ibanez, O. Gutierrez Frias, and M. Suarez
[8] Astrom K. J., and McAvoy Thomas J., “Intelligent control”, J. Castanon, “Lyapunov-Based Controller for the Inverted
Proc. Cont. 1992, Vol. 2, No 3, pp 115-127. Pendulum Cart System”, Springer Journal: Nonlinear Dynamics,
[9] T. I. Liu, E. J. Ko, and J. Lee, “Intelligent Control of Dynamic Vol. 40, No. 4, June 2005, pp. 367-374.
Systems”, Journal of the Franklin Institute, Vol. 330, No. 3, pp.
[22] Gholipour, Y., Mola, M. (2014). Investigation stability of
491-503, 1993. Rikitake system.Journal of Control Engineering and
[10] Yasar Becerikli, Ahmet Ferit Konar, and Tar�q Samad, Technology, 4(1).
“Intelligent optimal control with dynamic neural networks”, [23] Gholipour, Y., Ramezani, A., Mola, M. (2014). Illustrate the
Elsevier Journal of Neural Networks, Vol. 16, 2003, pp 251–259. Butterfly Effect on the Chaos Rikitake system. Bulletin of
[11] Kevin M. Passino, and Stephen Yurkovich, Fuzzy Control, Electrical Engineering and Informatics, 3(4).
Addison Wesley Longman, Inc., California, 1998. [24] Gholipour, Y., Mola, M. (2015). STABILIZATION OF
[12] M. A. Abido, “Optimal Design of Power–System Stabilizers CHAOS RIKITAKE SYSTEM BY USE OF FUZZY
using Particle Swarm Optimization”, IEEE Transactions on CONTROLLER. SCIENCE INTERNATIONAL-LAHORE 27
Energy Conversion, Vol. 17, No. 3, September 2002, pp. 406- (1), 115-119
413.
[13] James Fisher, and Raktim Bhattacharya, “Linear quadratic
regulation of systems with stochastic parameter uncertainties”,
Elsevier Journal of Automatica, vol. 45, 2009, pp. 2831-2841.
[14] M.A. Denai, F. Palis, and A. Zeghbib, “Modeling and control of
nonlinear systems using soft computing techniques”, Elsevier
Journal of Applied Soft Computing, vol. 7, 2007, pp 728–738.

March-April

You might also like