Balancing of An Inverted Pendulum Using PD Controller: June 2012

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

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/283733217

Balancing of an Inverted Pendulum Using PD Controller

Article · June 2012


DOI: 10.3329/dujs.v60i1.10348

CITATIONS READS

14 8,388

6 authors, including:

Md Mahadi Hasan Chanchal Saha


University of Wollongong IBM
17 PUBLICATIONS   80 CITATIONS    18 PUBLICATIONS   36 CITATIONS   

SEE PROFILE SEE PROFILE

M R I Sarker
Rajshahi University of Engineering & Technology
35 PUBLICATIONS   121 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Flameless Combustion of Barapukuria Bituminous Coal. View project

All content following this page was uploaded by Chanchal Saha on 13 November 2015.

The user has requested enhancement of the downloaded file.


Balancing of an inverted pendulum using PD controller
*Mahadi Hasan, *Chanchal Saha, **Md. Mostafizur Rahman, **Md. Rabiual Islam Sarker and
***Subrata K. Aditya

*Industrial Systems Engineering, School of Engineering and Technology, Asian Institute of


Technology, Pathumthani-12120, Thailand
**Department of Mechanical Engineering, Rajshahi University of Engineering & Technology,
Rajshahi-6204, Bangladesh
***Department of Applied Physics, Electronics and Communication Engineering, Dhaka University,
Dhaka-1000, Bangladesh

Abstract
Balancing of an inverted pendulum robot by moving a cart along a horizontal track is a classical problem in the
field of Control Theory and Engineering, for the beginners to understand its dynamics. Several physical models
can also be simplified as elastic inverted pendulums like rockets and walking robots. Many researchers have been
applying different control algorithm and design techniques such as PID Controller, State Space, Neural Network,
Genetic Algorithm (GA) even Particle Swam Optimization (PSO), in both digital and analog domain using
various sensors. However, this can also be done by using a single potentiometer as a sensor and PD controller as
the design algorithm. The comparison or difference between the reference and the potentiometer generates
control signal to drive the system. In this case, it consists of a thin vertical rod attached at the bottom, referred to
as pivot point mounted on a mobile toy car. The car, depending upon the direction of the deflection of the
pendulum moves horizontally in order to bring the pendulum to absolute rest. The main idea behind this control
process is the use of PD (Proportional and Derivative) controller to generate signal to control the speed and
direction of the motor. The only sensor used in this project was a potentiometer (pot) which was attached with
the pendulum rod. The variation in its resistance causes change in voltage and afterward, it was compared with
the reference voltage to generate the appropriate control signal. PROTIUS software was used for circuit
simulation, frequency responses of the system were analyzed in MATLAB with different values of KP and KD.
Finally, to represent the system stability, root locus diagram was drawn using MATLAB.

Key words: Inverted pendulum, PD controller, System stability, Output responses, Root locus

I. Introduction direction. The car, depending upon the direction of the


The one-dimensional swinging inverted pendulum deflection of the pendulum (the angle of the inverted
with two degrees of freedom (i.e. the angle of the pendulum, θ), moves horizontally in order to bring the
inverted pendulum robot along forward and backward pendulum to absolute rest. A PD (Proportional and
direction) is a popular demonstration of using Derivative) controller has been used to generate signal
feedback control to stabilize an open-loop unstable to control the speed and direction of the motor. The
system. The first solution perhaps to this problem was only sensor used in this work was a potentiometer
described by Roberge [1] in his aptly named thesis, (pot), attached to the nadir of the pendulum rod and
“The Mechanical Seal". Subsequently, it has been variation in its resistance causes change in voltage
considered by many researchers [2] as a common which is then compared with the reference voltage to
benchmark for the investigation of automatic control generate the appropriate control signal. The
techniques, most of them have been used as a Mathematical expression was established to find the
linearization theory in their control schemes. Since the system transfer function based on Newton’s second
system is inherently nonlinear, it has been using law of motion. Simulation of the circuit mechanism
extensively by the control engineers to verify a was obtained by applying PROTIUS software.
modern control theory and is also useful in illustrating MATLAB simulink has been used for closed loop
some of the ideas in nonlinear control domain. In this transfer function simulation with different values of
system, an inverted pendulum is attached to a cart KP (proportional gain) and KD (Differential gain) to
equipped with a motor that drives it along a horizontal generate output responses of the system. And finally
track. The thin vertical rod (the pendulum) hinged at root locus diagram of the system was drawn in
the bottom, referred to as pivot point, mounted on a MATLAB to show the system stability.     
mobile toy car which can move along horizontal
  
II. System Dynamics
To find the system’s transfer function a brief
description on the modeling of the inverted pendulum
is presented in this section. The system consists of an
inverted pole hinged on a cart which is free to move
in the x direction as shown in Fig. 1. In order to
obtain the system dynamics, the following
assumptions have been made:
1. The system starts in an equilibrium state i.e. that
the initial conditions are assumed to be zero.
2. The pendulum does not move more than a few
degrees away from the vertical to satisfy a linear
model. Fig. 2 Free body diagram of the inverted pendulum
3. A step input (displacement of the pendulum, θ) is Summing the forces along the horizontal direction as
applied to the system. shown in the FBD, following equation for N was
obtained:
N = m&x& + mlθ&& cos θ − mlθ& 2 sin θ (2)
After substituting eqn. 2 into eqn. 1, the first equation
of motion for the system was found as follows:

(M + m) &x& + bx& + mlθ&&cosθ − mlθ& 2 sinθ = F (3)


To acquire the second equation of motion, the forces
along the perpendicular direction of the pendulum
was summed up and found the following equation:

P sinθ + N cosθ − mg sinθ = mlθ&& + m&x&cosθ (4)


To get rid of P and N terms from the eqn. 4, the
moments around the centroid of the pendulum was
Fig. 1 Cart and Inverted Pendulum System  taken which resulted following equation:
M mass of the cart 0.3 kg
− Pl sin θ − Nl cos θ = lθ& (5)
m mass of the pendulum 0.2 kg
b friction of the cart 0.1 N/m/sec Combining eqn. 4 and 5, the second dynamic equation
l length of the pendulum 0.2 m was obtained as follows:
i inertia of the pendulum 0.006 kg.m2 ( I + ml 2 )θ&& + mgl sinθ = −ml&x&cosθ (6)
f force applied to the cart kg.m/s2
g gravity 9.8 m/s2 From eqn. 3 and 6, two linear equations of the transfer
θ Vertical pendulum angle in degree function were found, where θ = π. Assume that, θ = π
+ ø (ø represents a small angle from the vertical
Table I Parameters of the inverted pendulum upward direction).
For the analysis of system dynamic equations, d 2θ
Therefore, cos θ = −1, sin θ = −φ and = 0.
Newton’s second law of motion was applied. Fig. 2 dt 2
represents the Free Body Diagram (FBD) of the
mechanism. Thus, after linearization the following two equations
of motion were appeared (where u represents the
From the FBD, summing the forces of the cart along input):
horizontal direction, following equation of motion
was obtained: ( I + ml 2 )φ&& − mglφ = ml&x& (7)

M&x& + bx& + N = F (M + m) &x& + bx& − mlφ&& = u (8)


(1)
To obtain the transfer function of the system original position (vertical) after an initial disturbance,
analytically, the Laplace transforms of the system and therefore, the reference signal should be zero. The
equations were taken: force applied to the cart was considered as an impulse
disturbance. The basic structure of the feedback
( I + ml 2 )Φ(s)s 2 − mglΦ(s) = mlX (s)s 2 (9) control system is shown below:
(M + m)Χ(s)s 2 + bΧ(s)s − mlΦ(s)s 2 = U (s) (10)
The above two transfer functions can be contracted
into a single transfer function as shown below:
ml
s
Φ( s ) q
=
U (s) b( I + ml 2 ) 2 ( M + m)mgl bmgl Fig. 3 Control block diagram (close loop) of the
s3 + s − s−
q q q inverted pendulum robot
MATLAB simulation: MATLAB Simulink was used
Where, q = [(M + m)(I + ml ) − (ml) ]
2 2
for simulation of output responses of the inverted
pendulum based on the equation and block diagram
= [(0.3+0.2) (0.006+0.2*0.22) – (0.2*0.2)2]
aforementioned. In Fig. 4, the block diagram of the
= 5.4×10-3
simulink is shown below:
.2 × .2
s
Φ(s) q
=
U(s) .1(.006+ .2 × .22 ) 2 (.3 + .2).2 × 9.8 × .2 .1× .2 × 9.8 × .2
s3 + s − s−
q q q

Φ( s) 7.407 s
= 3
U ( s) s + 0.26s − 36.296s − 7.26
2

III. Controller design and simulation Fig. 4 Block diagram in MATLAB Simulink
The Proportional Derivative (PD) is a type of The system was examined for different values of Kp
feedback controller whose output, a Control Variable and Kd. For instance, three critical combinations of Kp
(CV), is generally based on the error (e) between and Kd (Table 2) are presented to understand the entire
some user-defined Reference Point (RP) and some trend of system stability.
measured Process Variable (PV). Based on the error
each element of the PD controller performs a Case Case 1 Case 2 Case 3
Gain
particular action. Kp 1 1 10
Proportional (Kp): Hence, error is multiplied by a Kd 1 50 50
gain Kp, an adjustable amplifier. In many systems, Kp
is responsible for process stability: too low, and the Table 2 Combinations of Kp and Kd
PV will drift away; too high, the PV will oscillate [3].
Case 1: In this case, the values of both Kp and Kd are
Derivative (Kd): The rate of change of error taken 1. Fig. 5 shows the corresponding MATLAB
multiplied by a gain, Kd. In many systems, Kd is codes. As can be seen in Fig. 6, the system was
responsible for system response: too high and the PV unstable as well as the response time was also pretty
will oscillate; too low and the PV will respond high (t>8 sec.).
sluggishly. The designer should also note that
derivative action can amplify any noise in the error Case 2: In case 2, the value of Kp was increased to 50
signal [3]. with keeping the value of Kd unchanged. The output
response (Fig. 7) was found stable with some initial
Tuning of a PD controller involves the adjustment of oscillations.
Kp, and Kd to achieve some user defined "optimal"
character of system response. Case 3: For case 3, the value of Kp and Kd were
considered 10 and 50 respectively. The output
In this problem, the main concern was to control the
pendulum's position, which should return to its
response (Fig. 8) was found quite stable and the
response time was very low (t<1 sec.)

Fig. 8 Response curve for case 3


IV. Circuit analysis and simulation
Circuit analysis: The rotational direction of the DC
Fig. 5 MATLAB codes for case 1 servo motor depends on the flow of current to control
the pendulum by moving cart backward or forward.
The current controlling part of the circuit is analyzed
in this section.

Fig. 9 Direction of current flow of the motor driving


circuit
Fig. 6 Response curve for case 1
According to Fig. 9, Q1 and Q2 are NPN and PNP
transistors respectively. When there is a positive
voltage at the base of Q1 and Q2, the transistor Q1 goes
into forward active region and Q2 gets cutoff. Thus,
the current flows from +VCC to ground through motor.
Similarly, when there is a negative voltage at the base,
Q2 goes into forward active region and Q1 gets cutoff.
Here, current flows from ground to -VCC. Table 3
summarizes the function of Q1, Q2, D1 and D2 to
represent the forward-reverse direction of motor.
Component
Voltage Motor
Q1 Q2 D1 D2
direction
Positive ON OFF OFF OFF Forward
Negative OFF ON OFF OFF Reverse
Fig. 7 Response curve for case 2
Zero OFF OFF OFF OFF ----------
Table 3 Function of Q1, Q2, D1 and D2
Darlington transistor was selected in order to drive V. Fabrication
more current since β value of this transistor is equal to
Initially in ‘breadboard’ as it’s easy to build and test,
product of β value of two transistors as shown below:
then in ‘matrix board’ and finally, self-made ‘PCB’
was used to fabricate the circuit which was driven by
an external power supply. The complete structure of
β2  β2 
the ‘Inverted pendulum robot’ is shown in Fig. 12.

β1 
Rotary type potentiometer was used to sense (position
β1  sensor) the angle of the pendulum. The circuit was
operated by two separate power supply, viz. ± 12V for
the Op-amp circuit and ± 17V for the motor driving
circuit.
Fig. 10 NPN and PNP Darlington transistor
Here, β new = β1 × β2 Æ IC = ID × β new.
Therefore, DC motor rotated faster due to the higher
new collector current. As the Darlington transistors
get heated faster, a heat sink was connected.

Fig. 12 Inverted pendulum robot


PCB: Printed Circuit Board (PCB), on which the
Fig. 11 Snap shot of simulation in PROTEUS circuit was built, has been designed using PROTEUS
software and then fabricated as shown in Fig. 13.
Simulation of circuit: Rather than approaching Unlike matrix board, PCB facilitated to build the
directly to the circuit fabrication, a simulation was circuit more professionally with minimum risk of
conducted first for successful completion of the short-circuits during soldering, de-soldering, testing
project. and so on.
PROTEUS software was used for the circuit
simulation which helped to visualize the operation of
the circuit before building it physically. Different
combination of the circuit components such as
transistors, operational amplifiers, resistors, DC motor
and so on were attempted in PROTEUS to analyze
and decide which combination of components results
better performance. It enabled to visualize the speed (a) Design view (b) Fabricated view
and direction of the DC motor along with appropriate Fig. 13 Image of PCB
design of the driving circuit. It also facilitated to VI. Results and verification
observe voltage and current at any point of the circuit
by using the tools available in PROTEUS (Fig. 11). Results: Following observations were notified after
completion of the experiment:
According to Fig. 11when the variable resistor RV2
(pendulum) was moved upward, the DC motor rotated • The robot was able to balance the pendulum
in clockwise direction. On the other hand, the motor accurately in both directions. However, the
rotated in counter clockwise direction while moved performance was more accurate in forward direction
downward. The flow of current and rotation of motor as compared to backward due to improper mass
were also visible in active simulation. This simulation balance.
ensured appropriate functioning of the circuit. • For small degree of disturbance, the robot was
adequately capable to balance the pendulum.
• For larger disturbance, the robot was observed to VIII. Conclusions
keep running for reaching balanced position.
The swinging inverted pendulum robot was
Verification: The study was verified through ‘root successfully balanced along to and fro horizontal
locus’ diagram drawn in MATLAB. Fig. 14 shows direction using a simple PD controller. The frequency
root locus diagram of the inverted pendulum robot. As responses of the system for different proportional and
is observed in the figure, there was a pole on the right derivative gains were shown. Root locus diagram was
hand side of the graph indicating that the system was drawn to verify the system stability. However, this
absolutely unstable for the low value of gain. In case technique has some limitations, in terms of
of increasing the magnitude of gain, the pole began to Mechanical and Electrical point of view such as
shift towards left direction, referring that the system vibrations, slip of wheels, insufficient current, and
was going to be stable. With the sufficient amount of heating of transistor. Use of accurate and multiple
enhancement of gain, the system at last approached sensors can increase the accuracy and robustness of
towards a fully stable state. The corresponding other the system. Several future enhancements can be
parameters are also mentioned in the upper right drawn by adopting more sensors like encoder, tilt
quadrant of the graph. sensor, accelerometer and so on. In addition, different
controllers such as PID, SP, GA are also applicable
for ensuring better performance. This study supposed
to be considered as an interesting initiative for the
beginners to have a fundamental perception over
Control Theory and Engineering with very limited
resources.
IX. Reference
1. Roberge, J. K., 1960 The Mechanical Seal.
Bachelor's Thesis, Massachusetts Institute of
Technology.
2. Nasir, A. N. K., Ismail, R. M. T. R. and Ahmad,
M. A., 2010, Performance Comparison between
Fig. 14 Root Locus Diagram of the system
Sliding Mode Control (SMC) and PD-PID
VII. Problems encountered and solutions Controllers for a Nonlinear Inverted Pendulum
System, World Academy of Science, Engineering
Problems Reasons Solutions and Technology, Universiti Malaysia Pahang,
Inaccurate Friction on Lubricant was
Malaysia.
reference potentiometer used to make pot
comparison frictionless 3. Kasruddin , A. N., Modeling and Controller
Electrical limitations Design for an Inverted Pendulum System, Master
Low speed Low value of beta Darlington Thesis, Faculty of Electrical Engineering,
of motor in power transistor was
Universiti Teknologi Malaysia.
transistors used
Heating of As the collector - Heat sink was 4. http://www.engin.umich.edu/group/ctm/examples/
transistor emitter voltage was used to lower the pend/invpen.html
high the collector temperature of
current draws very power transistor 5. http://courses.cit.cornell.edu/ee476/FinalProjects/s
high and more heat 2003/es89kh98/es89kh98/index.htm
was dissipated by
the transistor 6. Jain, T. and Nigam, M. J., Optimization of Pd-Pi
Mechanical limitations Controller Using Swarm Intelligence, 2008,
Vibration of Weak joint between Better material Journal Of Theoretical And Applied Information
the pendulum and the was used to Technology.
pendulum pot strengthen the
mechanism 7. Astrom, K. J. and Furuta, K., 2000, Swinging up a
Slip of Low quality of Better quality of Pendulum by Energy Control, Automatica.
wheels wheels wheels were tried
8. Eker, J., and Astrom, K. J., 1996, A Nonlinear
Table 4 Problem encountered and solutions Observer for the Inverted Pendulum, 8th IEEE
Conference on Control Application.

View publication stats

You might also like