You are on page 1of 66

Robust Stabilizing and Fuzzy Swing up

Control For Inverted Pendulum

By

Arslan Tahir

Thesis submitted to the faculty of Engineering in partial


fulfillment of requirements for the Degree of MS Systems

Engineering.

Department of Electrical Engineering,


Pakistan Institute of Engineering and Applied Sciences,
Nilore, Islamabad 45650, Pakistan

October 12, 2012


iii

Department of Electrical Engineering


Pakistan Institute of Engineering and Applied Sciences (PIEAS)
Nilore, Islamabad 45650, Pakistan

Declaration of Originality

I hereby declare that the work contained in this thesis and the intellectual content
of this thesis are the product of my own research. This thesis has not been
previously published in any form nor does it contain any verbatim of the published
resources which could be treated as infringement of the international copyright law.
I also declare that I do understand the terms copyright and plagiarism, and that
in case of any copyright violation or plagiarism found in this work, I will be held
fully responsible of the consequences of any such violation.

Signature:
Name: Arslan Tahir
Date: October 12, 2012
Place: PIEAS
iv

Certificate of Approval

This is to certify that the work contained in this thesis entitled


“Robust Stabilizing and Fuzzy Swing up Control For Inverted
Pendulum”
was carried out by
Arslan Tahir
under my supervision and that in my opinion, it is fully adequate,
in scope and quality, for the degree of MS Systems Engineering from
Pakistan Institute of Engineering and Applied Sciences (PIEAS).

Approved By :

Signature:
Supervisor: Dr. Muhammad Abid

Verified By:

Signature:
Head, Department of Electrical Engineering
Stamp:
v

To my parents.
vi

ACKNOWLEDGEMENTS

Successful hardware projects in Pakistani Universities have always been a challenging


task to its graduate students, as they have to overcome the consequenses of limited
funds, scarce hardware suppliers and shipment delays. In such uncertain conditions i
would like to thank Almighty God, who ensured valuable, helpful and timely sources
in completion of my thesis. I also want to thank my supervisor Dr.M.Abid for his
guidance and motivation in the field of control systems. I would also like to convey
thanks to the Department personnel for providing laboratory facilities and fiscal
funds.
vii

Contents

Acknowledgements vi

List of Figures x

List of Tables xii

Abstract xiii

Nomenclature xiv

1 INTRODUCTION 1
1.1 Applications Of Inverted Pendulum . . . . . . . . . . . . . . . . . . 1
1.2 Rocket Propulsion . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Robot Balancing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Benchmark For Researchers . . . . . . . . . . . . . . . . . . . . . . 2

2 MECHANICS AND MATHEMATICAL MODELING 3


2.1 Mechanics of IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 Mechanical Design Of Inverted Pendulum . . . . . . . . . . 3
2.2 Transfer Function Of Motor . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Transfer Function of Cart Pulley System . . . . . . . . . . . . . . . 6
2.4 Transfer Function of Cart and Pendulum . . . . . . . . . . . . . . . 7
2.5 State Space Realization . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.6 NonLinear Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.7 An Insight to Mathematical Modeling . . . . . . . . . . . . . . . . . 14
viii

2.8 Mechanical Parameters . . . . . . . . . . . . . . . . . . . . . . . . . 15

3 ELECTRONICS OF INVERTED PENDULUM 17


3.1 Choice Of Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2 Choice of Controller . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2.1 Quadrature Encoder Interface(QEI) . . . . . . . . . . . . . . 20
3.2.2 PWM module . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2.3 Processing Speed . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3 Choice Of Actuators . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4 PCB Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4.1 Motor Drive Card . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4.2 Control Card . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5 Problems With Solutions . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5.1 Bit Bang I 2 C . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5.2 Bounding All States . . . . . . . . . . . . . . . . . . . . . . 28
3.5.3 PIC18f4431 PGM Pin . . . . . . . . . . . . . . . . . . . . . 28
3.5.4 Friction NonLinearity . . . . . . . . . . . . . . . . . . . . . . 28
3.5.5 Shaft Play . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

4 SWING UP FUZZY CONTROL 30


4.1 Design Using Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5 REGULATING θ AND CONTROLLING X 34


5.1 SISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.1.1 PID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.1.2 Loop Shaping . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.2 MIMO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.2.1 PID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.2.2 LQG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
ix

6 GRAPHICAL USER INTERFACE 42


6.1 MATLAB GUIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

7 CONCLUSION AND FUTURE WORK 45


7.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Appendices 47

Appendix A Mathematical Model 48

References 50

About the Author 52


x

List of Figures

2.1 Mechanical structure of inverted pendulum . . . . . . . . . . . . . . 4


2.2 Mechanical structure of inverted pendulum . . . . . . . . . . . . . . 4
2.3 Servo motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 Pulley attached with motor . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Inverted pendulum[1] . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.6 Pole zero map of IP . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.1 Othogonal signal generated by optical encoder . . . . . . . . . . . . 18


3.2 Dual interrupt circuit . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 4 states of optical encoder [2] . . . . . . . . . . . . . . . . . . . . . 20
3.4 QEI block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.5 Big picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.6 PCB designed for IP . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.7 I 2 c 7bit addressing[3] . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.8 I 2 C different conditions [3] . . . . . . . . . . . . . . . . . . . . . . . 27
3.9 Offset problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

4.1 Different region of operation . . . . . . . . . . . . . . . . . . . . . . 30


4.2 Switching Of controllers . . . . . . . . . . . . . . . . . . . . . . . . 32
4.3 Fuzzy surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
0
4.4 θ vs θ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

5.1 Inverted pendulum . . . . . . . . . . . . . . . . . . . . . . . . . . . 34


5.2 Proposed SISO loop . . . . . . . . . . . . . . . . . . . . . . . . . . 35
xi

5.3 Loop for bounded θ . . . . . . . . . . . . . . . . . . . . . . . . . . . 35


5.4 Respose of SISO PID controller . . . . . . . . . . . . . . . . . . . . 36
5.5 Desired loop shape . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.6 Disturbance rejection . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.7 MIMO configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.8 PID MIMO arrangment . . . . . . . . . . . . . . . . . . . . . . . . 39
5.9 LQG as H2 synthesis[4] . . . . . . . . . . . . . . . . . . . . . . . . 41
5.10 Results of LQG controller: Tracking x and regulating θ . . . . . . . 41

6.1 Inverted pendulum GUI . . . . . . . . . . . . . . . . . . . . . . . . 43


xii

List of Tables
xiii

Abstract

Inverted Pendulum is one of the most famous laboratory equipment used to test and
verify the effectiveness of numerous Control Schemes like Fuzzy control, Non-linear
control, PID control, Robust control and etc. This report will address the complete
indigenous design and implementation phases of hardware and control section of
Inverted Pendulum Project. Hardware section will deal with the electronics and
mechanics of Inverted Pendulum, whereas Control section will deal with the design
and simulation of robust control schemes.

It was observed that conventional/theoratical model of Inverted Pendulum does not


include dynamics of motor, actuator and pulley system. So this report will also deal
with the remodeling of Inverted Pendulum.

Controllers working in simulations always need extra effort to counter practical


limitations and missing dynamics of hardware. Example of such are; uncertain starting
angle offset, motor nonlinearity, friction, air drag, unbound displacement etc. At the
end of this report reader can acknowlege the complete insight and working
complexities of control project.
xiv

Nomenclature

Symbol Nomenclature
IP Inverted Pendulum
COG Center of gravity
P ID Propotional Integral Diffrential
LQG Linear Quadratic Guassian
SISO Single input Single Output
M IM O Multiple Input Multiple Output
GU I Graphical User Interface
QEI Quadrature Encoder Interface
P CB Printed Circuit Board
1

Chapter 1
INTRODUCTION
An Inverted Pendulum, as name implies, is a pendulum which has mass above its
pivot point. Inverted Pendulum is one of the most famous laboratory equipment used
to test and verify the effectiveness of numerous Control Schemes . The main objective
of these control schemes is to swing up and balance its mass (COG). The simplest
realization of inverted pendulum can be thought of as balancing a broom stick on
ones hand.
Inverted Pendulum is a non-linear, unstable control problem. Its Hardware assembly
is composed of a cart pulley sytem energied by an electric motor. Pivot point of IP lies
on a cart, whereas controlled cart movements can ensure its smooth swingup and
stabilization/upward erection. During swingup and stabilization, position of cart must
always stay within defined parmeters. IP can be used for relative comparison and
effectivenes of dedicated Control schemes. These stabilizing Control schemes can be
compared for rejection of one parameter (e.g. noise, ocilliations,
nonlinearities,unstability) without compromising others .
The IP is among one of the famous and challenging systems to verify effectiveness of
control schemes. So, it has been a task of choice to be assigned to Control
Engineering students to analyze its model and propose a stabilizing controller
according to the different control laws.

1.1 Applications Of Inverted Pendulum

Inverted Pendulum has verstile applications as being a benchmark for researchers. It


is also a subset of rocket propulsion and robot balancing systems.
2

1.2 Rocket Propulsion

Control of an Inverted Pendulum is a Control Engineering problem based on flight


simulation of rocket or missile during initial stages of flight. As a rocket flies
through the air, it both translates,rotates and move on a desired trajectory. The
rotation occurs about a point called the center of gravity(COG). The COG is the
location where average weight of the rocket lies. Its mass is distributed throughout
the rocket, and for some reasons, it is important to know the distribution of
its mass. But for rocket trajectory and maneuvering, we need to be concerned
with only the total weight of rocket and the location of the COG.To force the
rocket to track the desire path we need a well established control algorithm(3D
inverted pendulum).So the subsection of this part i.e. 2D inverted pendulum is
implemented in this project.

1.3 Robot Balancing

Robot balancing is also one of the application of inverted pendulum. In this


application we are concerned with the center of gravity of robot to be remained
under its foot. This robot balancing mechanism can be thought as an inverted
pendulum with multiple degrees of freedom.

1.4 Benchmark For Researchers

It is also used as a benchmark for testing control algorithms PID controllers,


neural networks,robust controllers (LQG, H∞ ) ,fuzzy control, genetic algo-
rithms.Although it is quiet easy to simulate a given mathematical model in
matlab but to implement this setup practically,from hardware design to imple-
mentation of control algorithm, makes this task really challenging.
3

Chapter 2

MECHANICS AND
MATHEMATICAL MODELING

2.1 Mechanics of IP

Our inverted pendulum structure is similar to cart pulley system. Choice of this
structure was to avoid the complexities of mathematical modeling.The Figure (2.1)
show the particular arrangement.The motor is attached with the pulley. Belt is
used as a source of connection between cart and pulley . With to and fro rotation
of pulley cart moves to and fro and can be used to balance the pendulum in upward
direction.

2.1.1 Mechanical Design Of Inverted Pendulum

Hardware that we design consist of cart which has capability to slide on two rods.
Cart is attached with motor through belt. And pendulum can rotate having pivot
point on cart. Figure(2.2) shows particular hardware assembly.
The Mathematical modeling of Inverted Pendulum can be divided in three
parts i.e.

• The transfer function from applied voltage to angular velocity of motor

• The transfer function from angular velocity to force appear on cart


4

Figure 2.1: Mechanical structure of inverted pendulum

Figure 2.2: Mechanical structure of inverted pendulum


5

• The transfer function from force appear on cart to angular position of pen-
dulum

θ(s) ω(s) µ(s) θ(s)


e(s)
= e(s) ω(s) µ(s)
So here we will discuss each, one by one.

2.2 Transfer Function Of Motor

Figure 2.3: Servo motor

The motor used in our project is a DC servo motor. These motors are widely
used in control system projects because of low cost and simple dynamics. The
differential equation governing the dynamics of servo motor is as follow

00 0
Jθ + Bθ = Ke(t) (2.1)

Here we are interested in calculating the transfer function between angular velocity
0 J
ω and the input voltage e(t) so we substitute ω = θ .where as the ratio τ = B
is
called the time constant of the motor.J is the inertia and B is the frictional force.
By taking the laplace transform and rearranging the equation we get

ω(s) K
= (2.2)
e(s) τs + 1

Though there are some nonlinearities present in the dynamics of motor


equation.2.2 but these nonlinearities are ignored here for the sake of simplic-
ity.
6

K is steady state angular speed of the motor and τ is the time required to
attain 60% of angular speed of motor.These both quantities can be calculated
easily with the help of optical encoder attached with the motor.

2.3 Transfer Function of Cart Pulley System

In this part we are interested to find the transfer function of pulley i.e the transfer
function between angular velocity applied by the motor and as a result force
applied on the cart attached to a belt connected with pulley.

Figure 2.4: Pulley attached with motor

Figure(2.4) shows the particular arrangement. As we know from modeling


00
theory that for angular motions Js θ = τ where τ is the torque present in the
system.( Js is the moment of inertia of pulley.Here for simplicity it is assumed that
moment of inertia of whole system is concentrated in the pulley and for pulley we
can write moment of inertia as Js = M r2 ) Or simply it can be said as sum of all
00
tourqes present in the system is equal to Js θ . As here we are interested to find the
transfer function between the linear motion parameter µ and the rotation motion
parameter ω so we will use the relation τ = F r where F is the force present in the
belt and r the radius of the pulley. Our present system is not ideal because of the
frictional forces present in the system. F = µ − Fb here µ is the force applied on
0
the cart and Fb = Bx is the reaction because of the frictional force in the system.
7

x = rθ is the linear distance.

00 0
Js θ = (µ − Bx )r (2.3)

00 0
Js θ = (µ − Brθ )r

So our final expression for the transfer function of pulley is equation (2.4)

µ(s)
= M rs + Br (2.4)
ω(s)

2.4 Transfer Function of Cart and Pendulum

In modeling of system from cart to pendulum two equations are of great impor-
θ(s)
tance i.e the function governing the angular position w.r.t the force µ(s)
and second
X(s)
one is the linear position of the cart w.r.t force µ(s)
. And also the state space
model of this portion will be shown in next chapter.The Figure (2.4) shows the
diagram of inverted pendulum to be modeled.

Figure 2.5: Inverted pendulum[1]

Define the angle of the rod from the vertical line as θ. Define also the (x, y)
coordinates of the center of gravity of the pendulum rod as (xg ,yg ).Then xg = x +
lsinθ and yg =lcosθ. Rotational motion of pendulum around the center of gravity
is given as
8

00
Jθ = V lsinθ − Hlcosθ (2.5)

The horizontal and vertical motion of center of gravity of rod can be written
as

d2
H=m (x + lsinθ) (2.6)
dt2

d2
V = mg + m (lcosθ) (2.7)
dt2

the motion of cart can be modeled as

d2 x 0
M = µ − Bx − H (2.8)
dt

Linearizing the above equations around origin i.e θ=0.We substitute cosθ=1 ,
sinθ ' θ
After Simplification we get following two very important equations.

00 0
(M + m)x + mlθ = µ − Bx (2.9)

00 00
(J + ml2 )θ + mlx = mglθ (2.10)

Our next step is to eliminate x from equation 2.9 .Form equation 2.10 we get

mglθ − (J + ml2 )θs2


x= (2.11)
ml

Substituting value of x in equation 2.9 we get

mglθ − (J + ml2 )θs2 mglθ − (J + ml2 )θs2


(M + m)[ ] + mlθs2 = µ − Bs
ml ml
9

Let A= mgl − (J + ml2 )s2

θ(s) −mls
= (2.12)
µ(s) (M + m)As + m2 l2 s3 + BA

Further simplification leads us to the following results

θ(s) −mls
=
µ(s) (M J + M ml + mJ)s + B(J + ml2 )s2 − mgl(M + m)s − Bmgl
2 3

(2.13)
As the friction and moment of inertia of rod around its center of gravity can
be neglected. So substituting B=0 and J=0 in equation 2.13. We should make
above assumption compatible with real hardware.For J=0 mass of rod should be
less than mass of bob.And for B=0 we are using linear bearings to reduce friction
as much as possible.

θ(s) −1
= (2.14)
µ(s) M ls2 − (M + m)g

Although it will be shown later in report that neglecting friction actually


creates misconceptions about model of inverted pendulum rather than reducing
the complexity.

As the information of linear position of cart is also of interest for us.And in


MIMO design we have to track the linear position of cart. So in order to find the
X(s)
transfer function of µ(s)
we will use the equation (2.11).Here we get an expression

X(s) mglθ − (J + ml2 )s2


=
θ(s) mls2

X(s) g (J + ml2 )
= 2− (2.15)
θ(s) s ml
10

X(s)
The transfer function of µ(s)
can be written as

X(s) θ(s) X(s)


= (2.16)
µ(s) µ(s) θ(s)

X(s) −mls(mgl − (J + ml2 )s2 )


=
µ(s) (mls2 )((M J + M ml2 + mJ)s3 + B(J + ml2 )s2 − mgl(M + m)s − Bmgl)
(2.17)
As again our assumption to simplify the above design B=0 and J=0 we get the
final result as
X(s) −(g − ls2 )
= 2 (2.18)
µ(s) s (M ls2 − (M + m)g)

2.5 State Space Realization

The classical control theory consists of methods like root locus and nyquist plots.
We have been using them, in class to date, for simple transfer function of the
plant to obtain our desired response. These methods do not use any knowledge of
the interior structure of the plant, and are valid for SISO systems. Limited types
of controllers can only be designed with this approach. Modern control theory
solves many of the limitations by using a much richer or good description of the
plant dynamics i.e state-space realization of system. MIMO systems can easily be
handled with this type of approach easily.
Coming toward the inverted pendulum case we have to track the position of cart
and also regulate the angular position of the pendulum. So it will be quite easy
to design a robust controller based on techniques like LQG, H∞ . In this section
we will be presenting the state space realization of our inverted pendulum plant.
By using equation (2.9) and equation (2.10) we get the following two important
equations.

(M + m)(J + ml2 ) − (ml)2 00 0


θ = (M + m)gθ − µ + Bx (2.19)
ml
11

(M + m)(J + ml2 ) − (ml)2 00 0 (ml)2 gθ


x = µ − Bx − (2.20)
(J + ml2 ) J + ml2

    
0
 θ1   0 1 0 0   θ1 
 0   mgl(M +m)
 
 θ Bml
 2
 
(M +m)(J+ml2 )−(ml)2
0 0 (M +m)(J+ml2 )−(ml)2
  θ2 
= + (2.21)
   
 
 x0   0 0 0 1  x 
 1    1 
    
0 −(ml)2 −B(J+ml2 )
x2 (M +m)(J+ml2 )−(ml)2
0 0 (M +m)(J+ml2 )−(ml)2
x2

 
 0 
 
 −ml 
(M +m)(J+ml2 )−(ml)2
µ (2.22)
 


 0 

 
J+ml2
(M +m)(J+ml2 )−(ml)2

Our interested states that we want to see at output are the angular position of
the pendulum and linear displacement of cart.So we choose x1 and θ1 as output
states.  
θ
    1 
 
 y1   1 0 0 0   θ2 
 
 =   (2.23)
y2 0 0 1 0  x1 


 
x2

The above state space model is without actuator dynamics.No by including


both the dynamics of pulley and motor we get the following state space model.By
using equation (2.4) we get µ = M rsω , + Brω and from equation(2.2) we get
0 Ke ω
ω = τ
− τ

M rKe Brτ − M r
µ= +ω (2.24)
τ τ

0 Ke ω
ω = − (2.25)
τ τ
12

using equation(2.19), equation(2.20),equation(2.25) and equation(2.24) we get

  
θ1 0 0 1 0 0
  
 0   mgl(M +m) Bml
 θ2   0 0
   (M +m)(J+ml2 )−(ml)2 (M +m)(J+ml2 )−(ml)2
 0  
 x = 0 0 0 1
 1  
  
 0   −g(ml)2 −B(J+ml2 )
 x2   (M +m)(J+ml2 )−(ml)2
0 0 (M +m)(J+ml2 )−(ml)2
  
0
ω1 0 0 0 0

   
0 θ1 0
   
ml(Brτ −M r)    M rKml

− τ ((M +m)(J+ml 2 )−(ml)2 )
  θ2   −
   τ ((M +m)(J+ml2 )−(ml)2 )


   
0  x  +  0 e (2.26)
 1   
   
(Brτ −M r)(J+ml2 ) M rK(J+ml2 )
  x2   τ ((M +m)(J+ml
   
τ ((M +m)(J+ml2 )−(ml)2 ) 2 )−(ml)2 ) 
   
−1 K
τ
ω1 τ

 
θ1
 
    
 θ2 
 y1   1 0 0 0 0 0  
 

 =   x1 

 (2.27)
y2 0 0 1 0 0 0  
 x2 
 
 
ω1

2.6 NonLinear Model

High nonlinearity is one of the property of Inverted Pendulum . As far as the


normal controllers are concerned the linearized plant is used to design a stabilizing
control to track the linear position of the cart and regulate the angular position
of pendulum, but to design and to analyze the fuzzy control swing up strategy we
need the nonlinear model of inverted pendulum.

00 0
Jθ = V lsin(θ) − Hlcos(θ) − γθ (2.28)

00 00 0
x (m + M ) + ml(sin(θ)) = µ − Bx (2.29)
13

Above two are the basic nonlinear equations of inverted pendulum. here γ is the
friction between the cart and the pendulum i.e the friction present in the rotary
joint.
where
00
V = mg + mlcos(θ)

00 00
H = M x + mlsin(θ)

00 00 0
cos(θ) = −sin(θ)θ − (θ )2 sin(θ)

00 00
sin(θ) = cos(θ)θ − (θ. )2 sin(θ)

simplifying euuation(2.28) we get

00 00 0
Jθ00 = mglsin(θ) − ml2 θ − mlcos(θ)x − γθ

00 0
00 mglsin(θ) mlcos(θ)x γθ
θ = − − (2.30)
J + ml2 J + ml2 J + ml2

simplifying equation(2.29) we get

00 00 0 0
x (m + M ) + θ (mlcos(θ)) = µ − Bx + mlsin(θ)(θ )2

0 0 00
00 µ Bx mlsin(θ)(θ )2 θ (mlcos(θ))
x = − + − (2.31)
M +m M +m M +m m+M

equation(2.30) and equation(2.31) are the nonlinear state space equations of


the inverted pendulum. These two equations are used to test the fuzzy swing up
control with detail analysis. Using equation (2.30) and (2.31) and converting them
into standard form.

α = (M + m)(J + ml2 ) − (mlcos(x1 ))2


14

0
θ1 = θ2

0
θ2 = α1 ((M + m)mglsin(θ1 ) − mlcos(θ1 )µ + Bx4 mlcos(θ1 )2

−(ml)2 cos(θ1 )sin(θ1 )θ22 − γθ2 (M + m))

0
x 3 = x4

0
x4 = α1 (µ(J + ml2 ) − Bx4 (J + ml2 ) + (J + ml2 )sin(θ1 )θ22

−(ml)2 gsin(θ1 )cos(θ1 ) + mlcos(θ1 )γθ2 )

The above nonlinear state space equations were implemented in the simulink.
And corresponding fuzzy control strategy is discussed in the upcoming chapters

2.7 An Insight to Mathematical Modeling

One interesting thing can be observed in the transfer function of equation(2.17)


is that it includes unstable dynamics of angular position of cart. Intuition says
that if angular position of pendulum is stable then linear position of cart should
also be stable. This point can further be demonstrated with the help of following
example. If we give impulse as an input to the system, intuition says that after
sometime cart should stop beacuase of frictional forces present in the system but
here this transfer function shows that dynamics of cart position are unstable i.e
response to impulse is unbounded response. The above misleading dynamics are
there, because we are using a linearized version of inverted pendulum at θ = 0.
And one other important problem is that If we assume that friction in the IP is
zero then pole zero map of IP are as shown in Figure(2.6). If we stick to the rule
that there should be no pole zero cancellation in right half plane then figure shows
that plant is unable to stabilize through classical control techniques because pole
15

and zero is present in right half plane, and root locus will always lie in right half
s-plane .But in reality plant friction is present in system so we cannot neglect this
parameter in designing the controller for IP, reason!!, presence of friction moves
zero of plant from the origon to left side of s-plane.
Web Links are provided in apendix where you can get matlab and pi18f4431
codes in soft form and linear and non linear models of IP in simulink.Plant model
is available in appendix too.

Figure 2.6: Pole zero map of IP

2.8 Mechanical Parameters

The actual parameters of the mechanical system are calculated and explained in
this section First variables are used in MATLAB simulations and second one are
16

used in mathematical modeling.

Mass of Cart Matlab Variables Modling Variables Value Units

Mass of Cart Mc M 1.25 Kg


Mass of Pendulum Mp m 0.50 Kg
Total Mass M Mt 1.5 Kg
Length of Pendulum L l 0.24 m
Radius of pulley r r 0.0235 m
Gravity g g 9.8 N/Kg
Time constant of Motor t τ 0.13 s
Inertia of COG of IP J J 0 Kgm2
Inertia of pulley Js Js 0.0069 Kgm2
17

Chapter 3

ELECTRONICS OF INVERTED
PENDULUM

Coming toward the electronics of the project We have following problems that
need efficient solution

• Sensing the position and speed of the pendulum.

• Sensing the position and speed of the cart.

• Manipulate digital data

• Digital Framework to implement the digital controller

So we provide solution of above problems in following steps

• Choice Of Sensors

• Choice Of Controller

• Choice Of Actuator

• Big Picture
18

3.1 Choice Of Sensors

We have two choices to measure the position i.e angular and linear.

• Potentiometer

• Optical Encoder

Potentiometers are actually good choice to design an analog controllers. But for
digital controllers we need ADC to extract some useful information from them.
They have also some very common draw backs that they are sensitive to tempera-
ture, they have limited life .Wear and tear is easy in case of potentiometer.Friction
and nonlinearities are also present in them.
Where as Optical Encoder gives us direct digital output.They give us high reso-
lution .And can be easily interfaced with the digital controller. So we are using
2500 ppr optical encoder of manufacturer named OMRON.

3.2 Choice of Controller

We need a controller which is capable of extracting data form optical encoder and
actuate the system with the desired input. As it was discussed earlier that system
is actuated with the help of voltage signal given to motor drive card. Where
input to motor drive card is PWM signal. We have different methods to extract
info from optical encoder through microcontrollers. Optical encoder give us two
orthogonal pulses as shown in the Figure (3.1)

Figure 3.1: Othogonal signal generated by optical encoder


19

One way is to use channel A as interrupt signal to microcontroller and incre-


ment/decrement the counter depending upon the 1/0 status of channel B.Through
this approach we are getting 1x resolution.Another way is that we use a dedicated
circuit for both the channel to get interrupt on both rising and falling edges of
channel A shown in Figure(3.2).

Figure 3.2: Dual interrupt circuit

And channel B is used to extract the information of direction.This approach


give us 2x resolution. But there is very serious problem associated with above two
methods. If the equipment attached with the optical encoder undergoes too and
fro motion, we observe ±offset in the actual reading i.e. offset can be abservered
whenever optical encoder will change its direction.
So to avoid above problem we should another technique that takes decision on
4 states of orthogonal channels. Figure(3.3) shows the state diagram of optical
encoder.4x resolution is achieved through this method.But to apply the above
method in controller is not a good idea. Any delay in its processing can cause
skipping of counter increment/decrement operation.
Dedicated ICs are available to perform the above operation.HCTL2000 is one
to them. But we got something better than that.
PIC18f4431 is the controller used in our project. Build in modules are present
in the microcontroller to interface with the optical encoder.This controller has built
in 4 state operation module. It auto increments counter.To actuate the plant we
20

Figure 3.3: 4 states of optical encoder [2]

need PWM signals.So we lock overselves on PIC18f4431 which has built in QEI
and PWM module and available in market easily.

3.2.1 Quadrature Encoder Interface(QEI)

The Quadrature Encoder Interface (QEI) decodes speed and motion sensor in-
formation. It can be used in any application that uses a quadrature encoder for
feedback. The interface implements these features:

• Three QEI inputs: two phase signals (QEA and QEB) and one index signal
(INDX)
21

• Direction of movement detection with a direction change interrupt


(IC3DRIF)

• 16-bit up/down position counter

• Standard and high-precision position tracking modes

• Two position update modes (x2 and x4)

• Velocity measurement with a programmable post scaler for high-speed ve-


locity measurement

• Position counter interrupt (IC2QEIF in the PIR3 register)

• Velocity control interrupt (IC1IF in the PIR3 register)

The QEI sub-module has three main components: the QEI control logic block, the
position counter and velocity post scaler.The QEI control logic detects the leading
edge on theQEA or QEB phase input pins, and generates the count pulse which is
sent to the position counter logic. It alsosamples the index input signal (INDX),
and generates the direction of rotation signal (up/down) and the velocity event
signals.
The position counter acts as an integrator for tracking distance traveled. The
QEA and QEB input edges serve as the stimulus to create the input clock which
advances the Position Counter Register (POSCNT). The register is incremented
on either the QEA input edge, or the QEA and QEB input edges, depending on
the operating mode. It is reset either by a rollover on match to the Period Register,
MAXCNT, or on the external index pulse input signal (INDX). An interrupt is
generated on a reset of POSCNT if the position counter interrupt is enabled.
The velocity postscaler down-samples the velocity pulses used to increment the
velocity counter by a specified ratio. It essentially divides down the number of
velocity pulses to one output per so many input, preserving the pulse width in
the process..Interested readers can furthers refer the original datasheet of this
controller.
22

Figure 3.4: QEI block diagram

3.2.2 PWM module

The Power Control PWM module simplifies the task of generating multiple, syn-
chronized pulse width modulated (PWM) outputs for use in the control of motor
controllers and power conversion applications. In particular, the following power
and motion control applications are supported by the PWM module:

• Three-phase and Single-phase AC Induction Motors

• Switched Reluctance Motors

• Brushless DC (BLDC) Motors

• Uninterruptible Power Supplies (UPS)

• Multiple DC Brush MotorsThe PWM module has the following features:

• Up to eight PWM I/O pins with four duty cycle generators. Pins can be
paired to get a complete half-bridge control.

• Up to 14-bit resolution, depending upon the PWM period.


23

• On-the-fly PWM frequency changes.

• Edge- and Center-aligned Output modes.

• Single-pulse Generation mode.

• Programmable dead time control between paired PWMs.

• Interrupt support for asymmetrical updates in Center-aligned mode.

• Output override for Electrically Commutated Motor (ECM) operation; for


example, BLDC.

• Special Event comparator for scheduling other peripheral events.

• PWM outputs disable feature sets PWM outputs

to their inactive state when in Debug mode. The Power Control PWM module
supports three PWM generators and six output channels on PIC18F2X31 devices,
and four generators and eight channels on PIC18F4X31 devices.

3.2.3 Processing Speed

Maximum available speed of controller is 10 MIPS (Mega instructions per sec-


ond)through PLL module. That is sufficient to implement complex and high
order difference equation of robust controller obtained from the techniques like
LQG or H∞ .

3.3 Choice Of Actuators

Hbridge is needed to actuate the system with the dc motor. H bridge was made
with BUZ11 mosfets with high current ratings and IR2110 is used to open upper
side mosfet gates of Hbridge. Other choice was to use lm298 having embedded
hbridge. But its current rating was upto 4 Amps. An our motor maximum current
is 5Amps, so making Hbridge of our own was preffered.
24

Figure 3.5: Big picture

We are using two controllers in our design.The one is responsible to maintain


the communication between computer and the plant through RS232. The sec-
ond one is used to generate and stabilize the plant by interpreting the data and
generating actuating signals.Whereas the two controllers remain updated by I 2 C
communication protocol.

3.4 PCB Design

The work on PCB design was sliced in two parts.

1. Motor Drive Card

2. Control Card

3.4.1 Motor Drive Card

Motor Drive Card was designed with the capacity of 5Amps rating. Because of
high currents this module was designed separately to avoid EMI[8].
25

3.4.2 Control Card

Control Card consists of two controllers. Two optical encoders connects on control
card and actuating signals are also generated and sent to motor drive card.

Figure 3.6: PCB designed for IP

3.5 Problems With Solutions

3.5.1 Bit Bang I 2 C

As shown in the bigpicture of complete hardware setup the two controllers


PIC18f4431 were connected with I 2 C interface.It was later found that I 2 C mater
module is not present in this controller.In order to counter this problem I 2 C was
implemented in the firmware to extract the info of second encoder.A brief intro
to this protocol will be discussed here and its implementation in pic18f4431.
The I 2 C named as Inter-Integrated-Circuit, was originally designed by Philips
Inc, to transfer high speed data between ICs at the hardware(PCB) level. The
physical layer of this interface consists of two open collector lines and pull ups
can be attached depending on desired speed; one line is used as clock (SCL) and
26

other line is used for data (SDA). The data and clock lines are pulled high with
1k resistors in our PCB design to the VDD rail. The bus can have one Master
module and many Slave module or may have multiple master modules attached.
The master module is used in generating the clock source in both transmission
and reception mode.
The I 2 C protocol supports 7/10 bit addressing mode, permitting about 128 or
1024 controllers to be communicating on the single bus, respectively. But In
practice, the bus reserves some addresses for its own use, so we have slightly
fewer addresses available for our use. For example, the 7-bit addressing mode
allows 128 usable addresses. The 7-bit addressing protocol is used in our project
to trnasmit HIGH and LOW bytes i.e 16 bit word at a time.[3].

Figure 3.7: I 2 c 7bit addressing[3]

All data transfers are initiated by the master module and on every clock edge
eight bits are transfered, Most Significant bit first. There are no limits to the total
size of data that can be sent form one module to other in single go. After each 8-
bit word transfer, a ninth clock pulse is sent on the bus by master module. At this
time instant, the transmitting deve (i.e either master or slave) on the bus releases
the data (SDA) line to get acknowledgment of tranmitted data from the reciever
27

. An ACK condition (SDA held low) is sent if the data reception is successfull, or
NACK condition (SDA is high) is sent if rececption is unsuccessful. NACK can
also be used to terminate data transfer after the reception of last byte.
According to I2C protocol, SDA line should changes its state from 0 or 1, when
SCL pin is at low. Two unique conditions can be detected on the bus because of
above mentioned restriction; (S) a START sequence and a (P) STOP sequence.
START sequence occurs when the master module pulls the SDA line low while
the SCL line is high. The START sequence tells all Slave devices on the bus
that address bytes are about to be sent. The STOP sequence occurs when the
SDA line goes high while the SCL line is high, and it terminates the transmission.
Slave devices on the bus should reset their receive logic after the STOP sequence
has been detected. Because of lack of availability of dedicated master module the

Figure 3.8: I 2 C different conditions [3]

operation of master were written in firmware where as slave was configured by


28

just tuning some of the registers of pic18f4431.Interested readers can further refer
to the data sheet of pic18f4431.

3.5.2 Bounding All States

As in the previous semester the controller was designed to sbilize the angular
position of theta but realized later that even with the balanced theta the state
”‘linear position of cart” becomes unbounded. i.e because of infinite euiliblium
point of ”x” exists with θ = 0. So adding a control loop to ”x” solves our problem.

3.5.3 PIC18f4431 PGM Pin

PGM pin of pic18f4431 is usually very sensaative to noise. It was realized after
a very tiring effort that the reason the controller was not working is because of
PGM pin.And it was properly pull down to ground and controller starts working
properly.

3.5.4 Friction NonLinearity

In practical implementation of controllers on IP setup one other important problem


was static friction nonlinearity. Bacause of friction a dead band of ±4 volts was
present in the system i.e. motor was unable to respond to in this voltage range,
and was causing ocillations in balancing the pendulum. Counter to this problem
was done in the software. Second problem associated with the friction was that
it was not unifrom throughout the rod, so to couter this problem we have to
introduce linear bearing in the system.

3.5.5 Shaft Play

Starting routine of our burnt program in microconteoller is that we assign π angle


when pendulum is initially at rest in downward position. And then incremental
encoder is used to increment or decrement the angle in the program. But what, if
there is some play in shaft or some static friction present there in pivot of pendulum
29

and as we are intialiszing our angle with π but in reality angle of pendulum is π −.
So instead of balacing the pendulum and 0 angular position our setup will try to
balance it to  i.e. it will read origon as  And cart will attain a constant velocity
and will go out of bound.Controller reads the values of Figure(3.9) π −  as π and
 as 0.

Figure 3.9: Offset problem


30

Chapter 4

SWING UP FUZZY CONTROL

To bring the pendulum in the upward direction the region of pendulum flight is
divided in to three parts as shown in the Figure(4.1).

Figure 4.1: Different region of operation

the standup routine should consist of the following subroutines, in this order:

1. Cart is initiated with quik left move to initiate swinging of pendulum.

2. The the critical point of cart movement where maximum energy can trans-
fered to pendulum should be found.

3. As pendulum starts swinging higher,reduce cart actuation amplitude slowly


so that the pendulum approaches upside position with small angular velocity.
31

To apply the above algorithm region I is used to add energy in the system i.e
actuating signal is applied in this region.In region II actuating signal is removed
and pendulum is allowed to deacceleerate which also adds energy and in region
III we wait and repeat same procedure in the opposite direction.[11]
As the pendulum approaches the inverted position a method of switching between
the swing up controller and stabilization controller is required. Different switching
criteria are considered in swing up mode.
The stabilizing controller is designed to work around the 0 (vertical) position in
which it can stabilize the pendulum with the designed stability margins. This is
because the stabilizing controller is based on the linearised system about the 0
point. If the stabilizing controller is switched on when the pendulum is outside
this region of attraction the system will not be able to stabilize the pendulum.
The pendulum must have an angular velocity below a certain value when the sta-
bilization controller switches on. If the angular velocity is too large it will cause
the motor to apply a large force to the cart to try and stabilize the pendulum,
causing the cart to run out of track.
The best switching moment occurs when the pendulum is approaching the 0 ver-
tical position with a small angular velocity. Figure(4.2) shows how both the con-
trollers are connected with each other.

4.1 Design Using Matlab

Fuzzy Logic Toolbox provides MATLAB functions, graphical tools, and a Simulink
block for analyzing, designing, and simulating systems based on fuzzy logic. The
product guides you through the steps of designing fuzzy inference systems. Func-
tions are provided for many common methods, including fuzzy clustering and
adaptive neurofuzzy learning. Figure(4.3) shows the fuzzy surfaces which gives us
the insight of actions to be performed for different level of inputs[12].
Figure(4.4) shows the how the angular velocity of inverted pendulum changes
with change in angular position of inverted pendulum.
32

Figure 4.2: Switching Of controllers

Figure 4.3: Fuzzy surface


33

0
Figure 4.4: θ vs θ
34

Chapter 5

REGULATING θ AND
CONTROLLING X

In this chapter SISO and MIMO control strategy will be discussed. As name
implies (single input and single output) inverted pendulum can be converted in
SISO arrangement with only single input and single regulating output i.e θ. But
before going in details of SISO arrangement let try to understand structure of our
plant.

Figure 5.1: Inverted pendulum

Figure(5.1) shows plant in block diagram. The first thing that can come in
readers mind that why not use only stabilizing controller on angular position of
inverted pendulum and leave x open. But the problem with the arrangement
shown in Figure(5.2) is that the linear position of cart become unbounded. Or it
35

Figure 5.2: Proposed SISO loop

is impossible to control the linear position of cart.From state space model it can be
seen that state x1 is unobservable from θ1 .Intuitively it can be said that if we are
balancing a stick on our hand we can balance a stick but can also attain constant
velocity too, if its assumed that there is negligible air drag. Because of missing air
drag dynamics our simulation results on the proposed Figure (5.2) arrangement
are able to stabilize the angular position of inverted pendulum but linear position
of cart become unbounded.

5.1 SISO

In in order to avoid this situation we arrange our block diagram as shown in


Figure(5.3).

Figure 5.3: Loop for bounded θ


36

In this arrangement linear position of cart is introduced as disturbance in the


loop having intentions to stabilize the angular position of pendulum. With this
approach we are able to bound linear position of cart as well as regulating the
angular position of pendulum.The block of controller can be controller of any type
i.e. PID, Lead/Lag,LQG and H∞ etc. This arrangement helps us to stabilize
angular position of of pendulum with hidden bounding loop on angular position
of cart. The Matlab code of plant is provided in the Appendix, and simulink
models are available on the download links in Apendix for testing.Here the order
of our controller is of order 1x1.

5.1.1 PID

PID controller was designed and tuned for Figure(5.3). Figure(5.4) shows the
response of PID stabilizing control.

Figure 5.4: Respose of SISO PID controller

5.1.2 Loop Shaping

One of wonders of modern control design theory is H-infinity loop-shaping. De-


velopment of this control design technique is based on methods, such as Bode’s
sensitivity integral, with H-infinity optimization techniques to design controllers
37

whose stability and performance properties are good in spite of bounded differ-
ences between the nominal plant assumed in design and the true plant encoun-
tered in practice. The control system designer mention the desired responses (i.e
step,impulse or frequency) and noise-suppression properties by applying different
weights to the plant transfer function in the frequency domain; then the result-
ing ’loop-shape’ is used and ’robustified’ through different optimization technique.
Robust methods that are applied usually has less effect at high and low frequencies
ranges, but its response near unity-gain crossover is adjusted to obtain and maxi-
mize the desired system’s stability margins. H-infinity loop-shaping can be applied
to multiple-input multiple-output (MIMO) systems. In our SISO configuration we
are using it this technique to get our desired response.[14]

Figure 5.5: Desired loop shape


38

Figure 5.6: Disturbance rejection

5.2 MIMO

Comming towards the MIMO design of inverted pendulum.Here the regulating


portion of inverted pendulum is as that of SISO but here additional thing is that
we also want to track linear position of cart. The order of controller in MIMO
design is of 2x1 i.e. 2 inputs and one output. Inputs to our controller are two
error signals and out is the voltage signal to regulate angular position of IP and
control the linear position of the cart. PID and LQG controller is discussed in the
following sections.

5.2.1 PID

The PID control strategy consists of three separate tunable parameters, or it can
be said as a controller having three degree of freedom: P the proportional param-
eter,I the integral parameter and D is for derivative parameter. These values can
also be evaluated in terms of time,P has effects on the present error, past errors
can be effected by using the parameter I, and derivative term is used for prediction
purpose i.e. D. The sum of these three actions followed by gain K is used stabilize
the plant.
39

Figure 5.7: MIMO configuration

In MIMO arrangement two loops are tuned separately to achieve the desired re-
sponse of IP. Figure(5.8) shows the particular loop structure.

Figure 5.8: PID MIMO arrangment

5.2.2 LQG

Consider the following plant

0
x = Ax + Bµ + wd (5.1)
40

y = Cx + wn (5.2)

The cost function for the LQG problem can be given in the following form as

Z T
1
J = E{ lim (xT Qx + uT Ru)} (5.3)
T →∞ T 0

if we choose   
1
 Q 2 0  x 
z=  
1
0 R2 u

then equation(5.3) becomes as

Z T
1
J = E{ lim (z(t)T z(t)dt)} (5.4)
T →∞ T 0

H2 norm has different deterministic interpretations and equation(5.4) is also one


of them. So equation(5.4) can be written as kFl (P, K)k22

z(s) = Fl (P, K)w(s)

stochastic process can be represented as


   
1
 wd   W 2 0 
 = 1
w
wn 0 V2

The generalized plant P can be represented as

 
1

 A W 0 B 
2

 1 
 Q2 0 0 0 
P =
 

1 
 0 0 0 R 
2

 
1
C 0 V 2 0
41

if we are interested to control the the plant i.e. we want to track the position of
cart so we have to introduce one more row in the generalized plant.

 
1

 A 0 W 0 B 
2

 1 
 Q2 0 0 0 0 
P =
 

 0 0 0 0 0 
 
 
1
C I 0 V 2 0

Figure 5.9: LQG as H2 synthesis[4]

Figure 5.10: Results of LQG controller: Tracking x and regulating θ


42

Chapter 6

GRAPHICAL USER
INTERFACE

Graphical user interface (GUI) is a type of user interface that allows users to
interact with electronic devices with images rather than text commands. Designing
the visual composition and temporal behavior of GUI is an important part of any
computer application. Its goal is to enhance the efficiency and ease of use for the
underlying logical design of a stored program. Methods of user-centered design are
used to ensure that the visual language introduced in the design is well tailored
to the tasks.
Now coming toward the GUI of inverted pendulum setup we have to test different
type of control strategies so programming the micro controllers again and again
is really a cumbersum task.To avoid these complexities user fascilitatedd visual
language is used to ensure the solution of above complexities. Many problems
may arise during hardware testing i.e. communication link may fail, sensors are
not working properly.To check these problems again and again with ocillioscope
and digital multimeter really boils the head of the subject.So by just giving at a
look to gui its very easy to locate the error and can be resolved easily
43

6.1 MATLAB GUIDE

GUIDE, the MATLAB graphical user interface development environment provides


a set of tools for creating graphical user interfaces (GUIs). These tools simplify
the process of laying out and programming GUIs.
Using the GUIDE Layout Editor you can populate a GUI by clicking and dragging
GUI componentssuch as axes, panels, buttons, text fields, sliders, and so oninto
the layout area. You also can create menus and context menus for the GUI. From
the Layout Editor, you can size the GUI, modify component look and feel, align
components, set tab order, view a hierarchical list of the component objects and
set GUI options.

Figure 6.1: Inverted pendulum GUI

GUIDE automatically generates a program file containing MATLAB functions


that controls how the GUI operates. This code file provides code to initialize the
GUI and contains a framework for the GUI callbacksthe routines that execute
when a user interacts with a GUI component. Use the MATLAB Editor to add
code to the callbacks to perform the actions you want the GUI to perform.
44

The Figure(6.1) shows the gui of the inverted pendulum setup. This gui con-
sists of display panel, control panel , and setting panel.
Display panel shows in which mode this IP is operating i.e. in swing up mode or
controlling mode etc It also shows connection status and small 2D animation of
IP.It will also be capable of displaying different graphs i.e residues step responses.
Control panel is used for online updation of difference equations in the micro
controller.It really saves our time and reduces complexity of burning code in the
controller again and again.We can either write discrete differential equation up to
eighth order obtained from different robust control techniques like LQG ,H∞ etc.
or use sliders to adjust the PID gain of the system.
In hardware projects the generic work always safe your lot of effort and helps you
to achieve maximum with minimum effort.So setting panels is provided that helps
you to change any parameter in the code i.e. sampling time, cycles per revolutions,
gains etc.
45

Chapter 7

CONCLUSION AND FUTURE


WORK

7.1 Conclusion

The work presented in the thesis consist of three parts.

1. Mechanical Design of IP

2. Electronic of IP

3. Controller design

In implementation phase we observe that controllers designed in MATLAB were


unable to provide good stabilizing margins because of missing dynamics, and as-
sumptions that we made in mathematical model. This project highlights both
perspectives of good thesis i.e. theory and its implementation. Availability, Cost
and Durability; we used these three methods to shortlist our choices and had to
compromise between them. Thats why our mathematical model and hardware
were unable to equate each other. But despite of these issues we were able to
stabilize the pendulum. In implementation of fuzzy control we were facing out of
plane vibrations, thats why this work is still pending.
46

7.2 Future Work

This work can be extended to many practical setups.


In double inverted pendulum setup our pendulum has one more pivot point at top
of it and second pendulum is attached there. And in same way, triple inverted
pendulum can be constructed. Another type is varying mass inverted pendulum.
In varying mass inverted pendulum, we have long tube filled with fluid behaving
as pendulum and fluid discharge with passage of time. This problem is somewhat
more similar to rocket propulsion system where mass of rocket also varies. In all
above mentioned setups we can validate our modern control theory and research
work, and can have insight to practical problems that we face in implementation
of controller.
47

Appendices
48

Appendix A

Mathematical Model

clc
close all
clear all
numk=1;
denk=1;

%% initializations
s=0
M=1.250; %mass of cart Kg
m=0.250; %mass of pendulum Kg
Mt=M+m; %total mass of system
l=0.24; %length of pendulum m i.e 24cm
r=0.047/2; %radius of pully m
J=0; %inertia of pendulum
Jpul=Mt∗rˆ2; %inertia of complete systrm concentrated on pulley
t=0.1; %time constant of motor s
g=9.8; %gravity
B=0; %friction of cart
K=1;
%% state space model
DDNN=(M+m)∗(J+m∗lˆ2)−(m∗l)ˆ2;
49

AA=[0 1 0 0 0; m∗g∗l∗(M+m)/DDNN 0 0 B∗m∗l/DDNN


−m∗l∗(B∗r∗t−Mt∗r)/(t∗DDNN); 0 0 0 1 0;
−g∗(m∗l)ˆ2/DDNN 0 0 −B∗(J+m∗lˆ2)/DDNN
(B∗r∗t−Mt∗r)∗(J+m∗lˆ2)/(t∗DDNN);0 0 0 0 −1/t]
BB=[0 ;−Mt∗r∗K∗m∗l/(DDNN∗t) ;0 ; Mt∗r∗K∗(J+m∗lˆ2)/(t∗DDNN) ; K/t];
CC=[1 0 0 0 0;0 0 1 0 0];

http://sdrv.ms/Q6XLXI simulink linear,nonlinear models and pic18f4431


codes are available here. http://www.youtube.com/watch?v=7FVDxNI3NAg
actual hardware and result of controllers can be seen here.
50

References

[1] K. Ogata and Y. Yang, Modern control engineering, vol. 4. Prentice Hall
Upper Saddle River, NJ, USA, 1990.

[2] A. Technologies, “HCTL 2000 Datasheet.” http://www.boondog.com/


tutorials/mouse/hctl2000.pdf/, 2010.

[3] J. Artiuch, “I2C vs SPI.” http://dev.emcelettronica.com/


i2c-or-spi-serial-communication-which-one-to-go/, 2010.

[4] S. Skogestad and I. Postlethwaite, Multivariable feedback control: analysis


and design, vol. 2. Wiley, 2007.

[5] B. Kuo and M. Golnaraghi, Automatic control systems, vol. 4. John Wiley &
Sons, 2003.

[6] R. Bishop and R. Dorf, Modern Control Systems. Prentice Hall College Di-
vision, 2004.

[7] J. Slotine, W. Li, et al., Applied nonlinear control, vol. 199. Prentice-Hall
Englewood Cliffs, NJ, 1991.

[8] D. L. Jones, “PCB design Tutorial.” http://www.alternatezone.com/


electronics/files/PCBDesignTutorialRevA.pdf/, 2010.

[9] U. of Michigan, “Inverted Pendulum Analysis and Design.” http://www.


engin.umich.edu/group/ctm/examples/pend/invpen.html, 1999.
51

[10] MicroChip, “PIC18f4431 Data Sheet.” http://ww1.microchip.com/


downloads/en/devicedoc/39616b.pdf, 1999.

[11] J. Yi and N. Yubazaki, “Stabilization fuzzy control of inverted pendulum


systems,” Artificial Intelligence in Engineering, vol. 14, no. 2, pp. 153–163,
2000.

[12] MATLAB, “Fuzzy control toolbox.” http://www.mathworks.com/


products/fuzzy-logic/, 1999.

[13] Microchip, “C18 libraries.” http://ww1.microchip.com/downloads/en/


devicedoc/mplab_c18_libraries_51297f.pdf/, 2010.

[14] Wikipedia, “H-infinity loop shaping.” http://en.wikipedia.org/wiki/


H-infinity_loop-shaping, 2010.
52

About the Author

Arslan Tahir, live in Lahore, Pakistan. Graduated from FAST(NUCES)


Lahore in Telecommunication Engineering, Post Graduated from PIEAS
Islamabad in System Engineering, having interests in development of elctro-
mechanical systems and their instrumentation. He also has rich experience in Web
Designing, Application Development (Joomla,Sharepoint 2013/16, PHP, MySQ,
Jquery, AngularJS), Server Administration (ADDS, ADCS, DNS DHCP, OOS 2016,
ADRMS, Sharepoint 2013), and Cyber Security Policy Compliance .

You might also like