Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

Types of waves£1.50

Short Notes of Electrostatics£2.50

Total£4.00

Title: Inverted Pendulum Report
Description: Classic inverted pendulum control problem is of interest that can be solved using a variety of systems and solutions. This problem is similar to trying to balance the broomstick practice. This problem invites those who are interested in the design of the system, control theory, and just plain problem-solving try to develop a working system. For this project, the motivation is to translate the mathematical models developed in control theory teaching real-time system. The design process of this project has required a great deal of planning and testing before deciding on a final design because there were so many alternatives to choose from. The design problem can be broken down into subsystems that are highly interdependent. The actual design of each subsystem is an iterative process of component testing and implementation of simple solutions until the solution "optimal" was found. The solution "optimum" may be defined as the solution, which can be developed at minimum cost that balances the pendulum better. During the design process, many obstacles have been encountered. The setbacks of the most important and time-all related to engine choice. When the first motor has been omitted, an engine torque faster and higher was obtained because the original one was not able to react fast enough in order to balance the pendulum. Since the new engine has different dimensions than the first, the entire mechanical system had to be redesigned. The next two engines broke when the control effort was too high and the direction changing rapidly, putting too much stress on the internal gears. To solve this problem, the controller has been redesigned with a closer bond on the control effort. The model is obtained on the basis of mathematical analysis of the physical system. Unknown parameters of the model are obtained from experiments in real time on the system inverted pendulum. The model was created with respect to the most nonlinearity in the system. Linearity is caused by fundamental principles of the system and by friction between the individual parts of the system. Therefore, the model is highly nonlinear and then linearization around the point of work has been performed and continuous linearized model was calculated as well as its discrete version. A controller has been constructed that has also been verified by experiments in real time.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


FINAL YEAR PROJECT REPORT

“Design and Implementation of Control
System for Inverted Pendulum”

Project Advisor
Asst
...
Saleem Ata
Co-Advisor
Asst
...
Jameel Ahmad

Submitted by
(Raheel Tariq
ID: 081220-089)
(Sajid Ali
ID: 081220-097)
(Saad Rasheed
ID: 081220-130)

Department of Electrical Engineering,
School of Science and Technology,
University of Management and Technology,
Lahore, Islamic Republic Pakistan

Page 1

Abstract

“Design and Implementation of Control System for Inverted
Pendulum”
Project Report submitted to the
Department of Electrical Engineering, University of Management and Technology
in partial fulfillment of the requirements for the degree of
Bachelor of Science
in
Electrical Engineering

(Raheel Tariq
(Sajid Ali
(Saad Rasheed

ID: 081220-089)
ID: 081220-097)
ID: 081220-130)

The inverted pendulum is a classic control problem, which involves the development of
balance the pendulum system
...
To study this problem, we have to take into account the experimental system which
consists of a pendulum, which is free to rotate 360 degrees
...
Three major
subsystems that make this design: (1) a mechanical system, (2) feedback network which includes
sensors and methods for reading and (3) a driver and its interface with mechanical system
...
We consider several models of stick-slip friction
between the car and track and measure the parameters of the experimental friction
...


Page 2

Summary
Classic inverted pendulum control problem is of interest that can be solved using a
variety of systems and solutions
...
This problem invites those who are interested in the design of the system,
control theory, and just plain problem solving try to develop a working system
...

The design process of this project has required a great deal of planning and testing before
deciding on a final design because there were so many alternatives to choose from
...
The actual design
of each subsystem is an iterative process of component testing and implementation of simple
solutions until the solution "optimal" was found
...

During the design process, many obstacles have been encountered
...
When the first motor has been omitted, an
engine torque faster and higher was obtained because the original one was not able to react fast
enough in order to balance the pendulum
...
The next two engines broke when the
control effort was too high and the direction changing rapidly, putting too much stress on the
internal gears
...

The model is obtained on the basis of mathematical analysis of the physical system
...
The model was created with respect to the most nonlinearity in the system
...
Therefore, the model is highly nonlinear and then linearization
around the point of work has been performed and continuous linearized model was calculated as
well as its discrete version
...


Page 3

CONTENTS:
INSIDE THE REPORT

Page 4

Table of Contents:
Design and implementation of Control System for Inverted Pendulum
ABSTRACT …………
...
3
TABLE OF CONTENT…………………………………………………………………………………
...
7

CHAPTER 1:

INTRODUCTION ……………
...
1
...
11

CHAPTER 2:

PROBLEM SETUP ……………………………………………
...
1 Design Problem and Requirements ………………………………………………………
...
1
...
14
2
...
2
The Requirements …………
...
2 Problem Definition …………………………
...
3 Range of Possible Solutions ……
...
17
3
...
18
3
...
1 Modeling Assumptions ………………………………………
...
1
...
…………………19
3
...
……………… …22
3
...
……………………………25
3
...
29

CHAPTER 4:

ANALYSIS OF UNCOMPENSATED SYSTEM ………………………………
...
1 Pole Zero Map of Uncompensated Open Loop System …………
...
2 Impulse Response of Uncompensated Open Loop System ……
...
3 Root Locus of Uncompensated Open Loop System …………………
...
4 Step Response of Uncompensated Open Loop System ………………………
...
34
5
...
35
5
...
36
5
...
1 Why Compensation is Required? ………
...
3 Root Locus Design with SISO Design Tool …………………………………
...
40
6
...
41
6
...
3 Pole Zero Map of Compensated Closed Loop System …………………
...
4 Impulse response of PID Compensated System ……………………
...
5 Step Response of PID Compensated System ……………
...
6 Conclusion of Compensation Analysis ………………………
...
45
7
...
………………………………… 46
7
...
…………………… 46
7
...
1 Transfer function of the System ………………
...
3 Selection of Motor …………………………………………………………
...
3
...
………………………………50
7
...
54
7
...
1 Displacement Sensors …………………………………
...
4
...
55
7
...
55
7
...
1 Controller Implementation …………………………………………
...
5
...
55
7
...
3 Methods to design the PID Controller …………………………………………
...
5
...
58

CHAPTER 8:

FABRICATION OF SYSTEM …………………………………………………………………60
8
...
61
8
...
…………………………61
8
...
1 Design of Pendulum …………………………………………………… …
...
2
...
1 Shaft Collar Assembly ………………………………………
...
2
...
2 Bearing Mount Assembly …
...
2
...
3 Rotary Shaft …………………………………………………………
...
2
...
4 Strut Clamp Assembly ………………………………………………
...
3 Fixture Design ……………………………………………………………………………
...
3
...
64
8
...
64
8
...
1 Sensor Design and Specifications ………………………………………………64
8
...
……………………………… 65

CHAPTER 9: ELECTRONIC CIRCUIT ………………………………………………………………………
...
1 Introduction ………………………………………………
...
2 Motor Driver (Hybrid-Bridge) …………………;……;;;;………
...
2
...
68
9
...
2 Turning on the MOSFETS ………………
...
3 CMOS Microcontroller ………………
...
4 Final Schematic ………………………
...
5 PCB Layout of the System ……………………
...
77
ACKNOWLEDGE
...
80
BIBLIOGRAPHY ………………………………………………………………
...


Figure1
...


Figure 2: Analysis Inverted Pendulum System

19

03
...


Figure 4: Pole Zero Map of Open Loop System

31

05
...


Figure 6: Step Response of Open Loop System

32

07
...


Figure 8: Root Locus After Introducing Pole

38

09
...


Figure 10: Root Locus after Settling Gain

39

11
...


Figure 12: Root Locus of Compensated Open Loop System

42

13
...


Figure 14: Impulse Response of PID Compensated System

43

15
...


Figure 16: Armature Controlled DC Motor

51

17
...


Figure 18: Block Diagram of Series PID Controller

56

19
...


Figure 20: Block Diagram of Parallel PID Controller Design

57

21
...


Figure 22: Shaft Collar Assembly

62

23
...


Figure 24: Rotary Shaft

63

25
...


Figure 26: Work Plate

64

27
...


Figure 28: Final Physical System Model

65

29
...


Figure 30: Final Physical System Configuration (ii)

66

31
...


Figure 32: Schematic Level View of H-Bridge

69

33
...


Figure 34: Pin Description of 16f684 Microcontroller

71

35
...


Figure 36: PCB Layout of H-Bridge (1)

73

37
...


Figure 38: PCB Layout of Controller Board (1)

74

39
...


Figure 40: PCB Layout of LCD Interface Circuit (1)

75

41
...


Figure 42: Inverted Pendulum System

76

43
...


Figure 44: Schematic of Series PID Design

82

45

Figure 45: Schematic of Parallel PID Design

83

Page 9

CHAPTER 1:
INTRODUCTION

Page 10

Introduction
The uniqueness and the widespread application of technologies derived from this
unstable system has attracted interest from a lot of research and robotics enthusiasts from around
the world an inverted pendulum is a pendulum which has its mass above its pivot point
...
The inverted pendulum is a classic problem in dynamics and control
theory and is widely used as a benchmark for testing control algorithms (PID, neural networks,
fuzzy control, genetic algorithms etc
...
The
objective of this project is to build a controller that is able to perform the balancing act with the
available configuration, preferably with minimum of bike setup
...

The practical part of this project was performed at the University of Management And
Technology, Lahore Pakistan, at the Department of Electrical Engineering, under the supervision
of Asst
...
Saleem Ata and Asst
...
Jameel Ahmad
...
Prof
...


Page 11

1
...
In this system,
a pendulum is connected to the side of a carriage by means of a pivot that allows the pendulum
to swing in the xy plane
...
This system is adherently unstable since even the minimal
disturbance may cause the pendulum began to fall
...
A controller would be ideal to keep the pendulum balanced with very little
change in angle, θ, or moving cart, x
...
Therefore a kind of control is necessary to
maintain a balanced pendulum
...
Obviously, limitation would be required under
current parameters of the system and the method for implementing a controller
...
Inverted Pendulum System with an input force

Page 12

CHAPTER 2:
PROBLEM SETUP

Page 13

PROBLEM SETUP
2
...
1
...
The controller should minimize
both the displacement of the carriage and the angle of the pendulum
...

2
...
2 The Requirements
To design any system, you need to have guidelines when making decisions on the
implementation
...
A set of requirements and goals for this project was
set up as follows:







Settling time of less than 5 seconds
Pendulum angle never more than 0
...

Wireless Sensors (if time permits)
...
A revised list of requirements will be included at the end of the section of the project
that illustrates what has actually been achieved
...
2 Problem Definition
It is practically impossible for the pendulum to balance in the inverted position without
applying an external force to the system
...
The outputs from basket IP can be:





Cart position
Cart velocity
Pendulum angle
Pendulum angular velocity

Page 14

Dynamic modeling of the inverted pendulum is a simple task
...

Therefore, the angle will be fed to the controller which will control our IP in a vertical position
...

This problem affects a cart and pendulum hinged to the bottom of the length of the
pendulum can move in the same plane cart
...
This system must be controlled so that the pendulum
remains balanced and vertical and resistant to the passage disorder
...

If the exit angle of the pendulum is on the vertical axis, we realize that the system is
unstable
...
To stabilize the
system, a system of feedback control is required
...
The control
objective is to move the carriage to the commanded position without causing the pendulum to
fall over
...
This configuration can be used to study the
control of the open loop system unstable
...
A range of control techniques ranging from simple phase-lead compensator to
neural network-controller can be applied
...
3 Range of Possible Solutions
An inverted pendulum is a classic example of control
...
The objective is to balance the system vertically on
the trolley
...

Following is brief description of some approaches to understand and solve the system
...
This is the simplest approach possible
...
A much more complex method to understand and streamline the
system
...

Method 3:
Observer is standing outside the system and observing the system as free-body diagrams
involved in the inverted pendulum system
...

A classical and best approach to solve this system because of free body diagrams
...
A servo motor is controlling
the movement of translation of the carriage, through a rail mechanism
...
The engine is derived from servo electronics; circuits
process controller of the error signal, which then pushes the cart through the servomotor and the
driving rail mechanism
...


3
...
The process is non-linear and unstable with a signal input and output different
...
1
...
This might not seem like the right approach because the
system has in fact friction
...
Therefore, ignoring friction coefficient is not
influencing the dynamics of the system to a large extent
...
1
...
The first system will be modeled
with the assumptions required such that the system is linear and fairly simple to design a
controller
...

Nonlinear equations can be derived as follows
...
There is an externally x-directed force on the cart, u(t), and a gravity
force acts on the point mass at all times

Figure 2: Analysis Inverted Pendulum System

According to Newton's second law, force is equal to mass times acceleration
...
 2  ml cos 
...
g  a

Figure 3: Vector Diagram for Force Components in Torque Balance

In a similar way, you run a balance of torque on the system, where the torque is the
product of the perpendicular component of the force and the distance from the point of rotation
...
(6) and simplifying results,

mx cos   ml  mg sin   eq(7)
Therefore the equations that define this system are given by Eqns
...
These
equations certainly represent a non-linear system that is relatively complicated from the
mathematical point of view
...
We'll do it later and actually compare the linear and
nonlinear dynamics of the system, but first, we need to put the non-linear equations in standard
form state space
...
3 Nonlinear State Equations (Inverted Pendulum)
To numerically simulate the nonlinear model for the inverted pendulum we need to put it into
standard state form,

d
z  f ( z, u, t )  eq(8)
dt
To put equations
...
From eqn
...
(5) gives

x( M  m)  ml sin 
...
mx   
x( M  m)  ml sin 
...
 2  mg cos  sin 
x( M  m  cos 2 
...
 2  mg cos  sin   eq(9)
From relation

ml  mg sin   mx cos 
x

g sin   l
 eq ( x)
cos 

We have Eq (5)

x( M  m)  ml sin 
...
mx     eq(5)
Substitute Eq (x) in Eq (5)

Page 22

 g sin   l 
2
( M  m) 
  ml sin 
...
  
 cos  
Multiplying “ cos  ” on both sides

( M  m)  g sin   l   ml sin 
...
cos   ml cos 2 
...
(9) and (10) gives

  ml sin  2  mg cos  sin 
x
 eq(11)
M  m  m cos2 
And



 cos   ( M  m) g sin   ml (cos  sin  )
 eq(12)
2
ml cos   ( M  m)l

To put the nonlinear equations into standard state space form, we assume

z1   z2    z1
z3  x z 4  x  z 3
Since the general form is

For final state space equations

d
z  f ( z , u, t )
dt

Page 23

 
 z1 
 
 
d
d  z2  d  
z

 eq(13)
dt
dt  z3  dt  x 
 
 
z4 
x

 
We have equation (12),



 cos   ( M  m) g sin   ml (cos  sin  )
ml cos 2   ( M  m)l

Substituting the assumptions in equation

 

 cos z1  ( M  m) g sin z1  ml (cos z1 sin z1 ) z2 2
ml cos 2 z1  ( M  m)l

Again, substituting these assumptions in equation(11) and simplifying,

x

  ml (sin z1 ) z2 2  mg cos z1 sin z1
M  m  m cos 2 z1

“Simply playing the derivatives”

z2



    cos z1  ( M  m) g sin z1  ml (cos z1 sin z1 ) z2 2 
 

ml cos 2 z1  ( M  m)l
d   

  eq(14)
dt  x   z4

  

2
x
     ml (sin z1 ) z2  mg cos z1 sin z1

2
M  m  m cos z1




This expression is now in the desired form given in equation
...
58)
...
This is the system implemented in the subsequent Matlab simulation

3
...
Since the normal matrices are zero in this case (i
...
In these conditions, zo  0, uo  0
...

 Jf1
 Jz
 1
 Jf 2
 Jz
1
J z (z ,u )  
 Jf 3

 Jz1
 Jf 4

 Jz1

Jf1 Jf1 Jf1 
Jz2 Jz3 Jz4 

Jf 2 Jf 2 Jf 2 
Jz2 Jz3 Jz4 

Jf 3 Jf 3 Jf 3 

Jz2 Jz3 Jz4 
Jf 4 Jf 4 Jf 4 

Jz2 Jz3 Jz4 

Now determining the elements of jacobian matrices

Page 25

Jf1
Jz1


( z ,u )

J
z2  0
Jz1

Using quotient rule’s result and simplifying,
Jf 2
Jz1

( M  m) g
Ml


z ,u

And

Jf3
Jz1

J
z4  0
Jz


z ,u

Since

Jf 4
J  u  ml (sin z1 ) z2 2  mg cos z1 sin z1 
 

Jz1 Jz 
M  m  m cos 2 z1

Simplifying these expressions and re-arranging results into following

Jf 4
Jz1


z ,u

Jf1
Jz2

Jf3
Jz4

mg
mg

M mm
M

( z ,u )

J

J
z2  1
Jz

Jz

( z4 )  1

z ,u

Thus, combining all these separate terms gives System
0

 ( M  m) g

Ml
J z (z , u )  

0

  mg


M

1 0 0

0 0 0

0 0 1

0 0 0



eq(17)

Page 26

Now derivative of the non linear terms with respect to 

J

z

,u



 Jf1
 Ju

 Jf 2
 Ju
 
 Jf 3
 Ju
 Jf
4

 Ju













Now determining the elements of Jacobian matrices 
Jf1
Ju

J
( z ,u )

Ju

( z2 )  1

2
Jf 2 J  u cos z1  ( M  m) g sin z1  ml (cos z1
...
r
...
(16) explicitly as

Page 27

0

 ( M  m) g

d
 z   Ml

0
dt

  mg


M

1 0 0
 0 

 1 
 
0 0 0
  z   Ml 
 0 
0 0 1

 
 1 
0 0 0

M 

 

eq(19)

What is the form of LTI state standards required for the implementation in Matlab
...
(15) represents the final linear
model of inverted pendulum system
...
5 SYSTEM PARAMETERS
For the project under consideration, we will have following parameters of the inverted-pendulum
system,
M
M
B
L
I
R

Mass of the Cart
Mass of the Pendulum
Friction of the Cart
Length of pendulum to Center of Gravity
Moment of Inertia (Pendulum)
Radius of Pulley,

900 gm
100 gm
0
...
5 cm
5
...
3 cm

m

Time Constant of motor

0
...
1 Pole Zero Map of Open Loop System
The poles position of the linearized model of the inverted pendulum (in open-loop configuration)
indicates that the system is unstable, as one of the poles of the transfer function is located on the
right half of the s-plane
...


Figure 4: Pole Zero Map of Open Loop System

4
...
The system is highly unstable
as theta diverges very rapidly
...


Page 31

Figure 5: Impulse Response of Open Loop System

4
...
Even here, theta
diverges very quickly the system is highly unstable
...


Figure 6: Step Response of Open Loop System

Page 32

4
...
Many systems are unstable in open loop
stable but in closed loop configuration
...
The closed-loop system can be
studied viewing uncompensated root locus of the system graphic Ofthe
...


Figure 7: Root Locus of Open Loop System

The plot reveals that the system cannot be controlled by a simple loop unity feedback
...
This makes it impossible to control by unity feedback
...

From the analysis above, it is concluded that using only the closed loop gain
compensation cannot check IP
...


Page 33

CHAPTER 5:
COMPENSATION
DESIGN

Page 34

5
...

Compensation can be designed using one of the following control analysis and design
techniques
...
One can use it according to his convenience
...


Page 35

5
...

5
...
1 Why Compensation is Required?
The system analysis of the system shows that using only the gain compensation in closed
loop can not control the IP
...

That is, as the given system is unstable for all values of gain, so that the root locus must
be reshaped so that the part of each branch falls in the left half s-plane, making the system stable
...

Compensation Goals
The desired TRANSIENT response for the system has following characteristics:
1
...
Overshoot should be < 20%, it implies that
3
...
5
The desired STEADY-STATE response for the system has following characteristics:
1
...


Compensation Design
The compensation of the system with the introduction of poles and zeros is used to
improve the operational performance
...

Design Specifications
We need to design a controller so that the step response of the closed loop system
meets the following specifications:
1
...
5 second
...
The maximum overshoot is less than 20%
...
3 Root Locus Design with SISO Design Tool
One of the most common techniques to meet the design criteria is a place of design root
...

The root locus diagram shows the trajectories of the poles of a closed loop feedback
system as a single system parameter varies in a continuous range of values
...

The technique consists in the root locus plot closed loop trajectories poles in the complex
plane as k varies
...


Adding Poles and Zeros to Compensator
You'll note that whatever the value of loop gain, ("K), a branch of the locus remains RHS
(in the unstable region) s plane
...
The root locus has a branch on the right side of the axis
imaginary, which indicates that the system is unstable in closed loop for all values of K
...






Transient (settling) time of ½ second
Overshoot should be < 20%
...
5
Steady-state error must be zero
...
We introduce a pole at origin to cancel the effect of zero of the plant at the origin
...
The root locus now becomes as

Page 37

Figure 8: Root Locus after Introducing Pole

2
...
These zeros terminus provide over indicates the two
branches of the locus on the left side of the s-plane which were, otherwise, approaches
infinity
...

3
...
The resulting root locus has the following form
...
8
...


Figure 9: Root Locus after Adding 2 Real Poles

Page 38

For the loop stability it is required that the loop gain should be greater than the given value
(i
...
, K > KMIN = 0
...

4
...
75 and
TS MAX = 0
...
These roots correspond
to value of k = 8
...
So the final values of the gains are

KC  30; K P  20 K I  100 K D  1

Page 39

CHAPTER 6:
ANALYSIS OF
COMPENSATED
SYSTEM

Page 40

6
...
In addition to the poles and zeros of the plant,
we pole PID controller to cancel the zero at the origin of plant origin
...


Figure 11: PZ Map of Compensated Open Loop System

6
...
The integral has deleted the zero origin
...
However, for the stability of the loop is necessary that the
loop gain should be greater than the given value (i
...
For our given data, Kmin = 0
...
8; the system is stable since all the roots are on the left-hand-side of the imaginary axis
...
3 POLE-ZERO MAP OF COMPENSATED CLOSED-LOOP SYSTEM
The Pole-zero location of the compensated model of inverted pendulum (in closed loop
configuration) is shown in the following figure
...
5359, -13
...
8242
0, -10, -10

6
...

The impulse response of the compensated system is shown in Fig
...
The settling time is very small i
...
0
...


Figure 14: Impulse Response of PID Compensated System

6
...
The
DC Gain of the closed-loop system compensated inverted pendulum is 0
...
The passing
percentage is 8
...
The steady state error is zero
...
6 CONCLUSION OF COMPENSATION ANALYSIS
Following compensation goals have been achieved
...
028 SEC FOR IMPULSE RESPONSE
0
...
48% FOR STEP RESPONSE
Ø The damping ratio  > 0
...


Page 44

CHAPTER 7:
PRACTICAL
IMPLEMENTAION

Page 45

7
...
There are many ways to implement them, even if each component is very dependent
on the other three
...

 The cart motion needs to be limited to one degree of freedom which is in the horizontal
plane
...

 The friction that impedes the cart and pendulum motion must be reduced as much as
possible
...
2 Track, Cart, and Pendulum Solutions
An option for mechanical design might have the motor as a main component of the carriage
...

The engine was a gear unit mounted on his tree falling in a toothed track which is flat on the
surface
...

A guide can be a steel rod along the cart that may have an arm to wrap
...

o Could be self contained if controller is mounted on the cart as well
...

o Good ability to change direction quickly
...

o Guide may be hard to integrate
...

A variant of the second option would be to have a track is not just a cart-pendulum
still mounted on the upper part
...
The motor may control a set of wheels that move to maintain the pendulum balanced
...
A gear assembly may be required to drive the wheels simultaneously
...

Page 46

 Pros
o Overall System is compact
...

 Cons
o Reaction time is dependent on motor torque
o Cart may have more than 1 degree of freedom
...

o Displacement may be hard to measure since there is no reference point to
measure against
...
Attached to the end of this tree
would be the pendulum
...

 Pros
o Cart is simply the rod
...

o System must be well built such that the rod is strongly attached to the motor
shaft
...

Other variants of the mechanical system include using any of the solutions proposed with
pendulums of various shapes, lengths, mass distributions, etc
...
This allows the approximation of the moment of inertia of the pendulum to zero
...
2
...
The sum of the forces in the vertical direction is not considered
because there is no movement in this direction and it is considered that the reaction force of the
earth balances all the vertical forces
...

I
...

F

The component of the centripetal force acting along the horizontal axis is as follows:

I 2
 mI 2
r
Component of this force in the direction of N is mI 2 sin 
F

Summing the forces in the horizontal direction, you can get an equation for N:

N  mx  mI cos   mI 2 sin 

Equation (2)

If you substitute this equation [2] into the first equation [1], you get the first equation of motion
for this system:


(M  m) x  b x mI cos   mI 2 sin   F

Equation (3)

To get the second equation of motion, sum the forces perpendicular to the pendulum
...


P sin   N cos   mg sin   ml  mx cos 

Equation (4)

To get rid of the P and N terms in the equation above, sum the moments around the centroid of
the pendulum to get the following equation
...


( I  mI )  mgI sin   mIx cos 

Equation (6)

The set of equations that define the dynamics of the system are equations (3) and (6)
...
Since the pendulum is
Page 48

stabilized in a position of unstable equilibrium, which is 'PI' radiating from the position of stable
equilibrium, this set of equations should be linearized about theta = Pi
...

After linearization the two equations of motion become (where u represents the input)
and using small angle identities


(M  m) x  b x mI  u

Equation (7)

( I  mI )  mgI  mIx

Equation (8)

2

To obtain the transfer function of the linearized system equations analytically, we must
first take the Laplace transform of the system equations
...
s 2  bX (s )
...
s 2  U (s )
( I  mI 2 ) ( s)
...
s 2
Since we will be looking at the angle Phi as the output of interest and the input force, rearranging, the transfer function is:

 ( s)
U ( s)



mI
...
s  b( I  mI )
...
s  bmgI
3

2

2

where

q  ( M  m)( I  mI 2 )  (mI ) 2

7
...
The two major considerations in choosing a motor are high
torque and high speed
...
High speed is required so that the carriage can move faster the pendulum
can fall
...
First of all, when
the torque and the speed of a DC motor increase, which requires more energy to start the engine
...
The control circuitry for a DC
motor is typically an H-bridge that controls the direction of current through the motor according
to the direction signal
...
A
bipolar stepper would be necessary to ensure that the motor rotates both directions
...

This control can be done externally through the use of digital logic components that would
require only a direction signal and a speed control, but this would make the design more
complex
...
First of all, servomotors in general are able to rotate 360 °
...
Note also that the control of a servo motor can be bit 'difficult in this
application because the level of the voltage applied to the motor indicates that the motor angle to
be at
...

Regardless of which engine is chosen, a separate power supply will only be necessary for
the engine
...


7
...
1 DC SERVO MOTOR MODELING
Introduction:
DC-motors that are used in feedback devices controlled are called DC-servomotors
...
DC motors are classified as controlled DC-motor
armature and field controlled DC-motors

Modeling
For the armature controlled DC motor, field current is constant and torque generated is
given

  kt
...
For this motor back-emf is
produced in armature due to armature rotation, which is directly proportional to angular velocity
of the armature
...


dm
dt

Equation 2

kb is motor constant (V
...


Figure 16: Armature Controlled DC Motor

Applying KVL, (Fig1), we get following equation

L
...
I a  Vb  Va
dt

Equation 3

This differential equation is governing the motion of mechanical load
...
e
...
J l
2
kg

Therefore, application of Newton’s moment balance equation at motor output shaft yields
F  ma
  I
...


d 2 m
d 2
1
1
d
 2
...
2 m  2
...

2
d t kg
d t kg
dt

Simplifying,

d 2l
d
J eq
...
l  k g
...
J m  J l
Jeq is total load inertia reflected at motor’s shaft where bt = rotational friction constant
Taking Laplace transform of equation (1) and equation (4)
From equation 1,   kt
...
I  s 

Equation a

From equation (4)
J eq ( s)
...
s  k g
...
I a

Equation b

To eliminate the central variables (Tm, Vb, Ia), Take Laplace transform of the equation (3)

Page 52

L
...
s  R
...
s  R

Substitute these into equation (b)

J eq (s)
...
s  k g
...


Va  Vb
L
...
s  R)  J eq ( s )
...
s   k g
...
(Va  Vb )



...



...


kg 

and

m


...


l


...
l

Vb  kb
...
 (s)
...
J eq , s 3  s 2 (bt
...
J eq )  s (bt
...
kt
...
ktVa



 ( s)
Va



k g
...
 L
...
L  R
...
R  k g 2
...
kb ) 



Equation 5

This is transfer function of the angular displacement to the applied voltage
...
e
...
kt
 L
...
(bt
...
J eq )  (bt
...
kt
...
Therefore, neglecting
the inductance effect, gives the first order transfer function that is related to the angular velocity
response to input of armor
...
kt
R
...
bt  k g 2
...
kb

Page 53

Alternatively, this can be written as

l ( s)
Va ( s)



k

...


7
...
Thus the
sensors must be relatively quiet and have a quick response so that the information retrieved from
sensors accurately reflects the state of the system
...
They are (1) the
angle, (2) the angle of speed, (3) the displacement of the carriage, and (4) the speed of the
trolley
...
More conventional approaches to this
problem only measure the angle and displacement and the other two parameters are derived from
these
...
4
...
The
voltage on the wiper of the potentiometer would then be converted into a digital signal by an
ADC
...

Another way to detect the displacement of the trolley is to use light sensors spaced parallel to
the track with a receiver on the side of the track
...

 Pros
o Simple Concept
 Cons
o Accuracy is limited to the spacing of the sensors
Radar and sonar sensors are also possible
...
The time required for a reflection should be used to calculate
the distance
...
Thus, they will not be considered for
this project
...
4
...
Ideally, the pot would have little friction
...
This has the
advantage of easy implementation but may cause non-linear output voltage
...

A rotary encoder could be another practical solution
...
This is available in a greater precision, but there is a
compromise between the costs
...
5 Controller Solutions
Once a mechanical system is developed with a feedback network accurate and simple
interface for the control of the carriage, a controller can be designed
...
The largest design constraint of a
controller of work is how well the system is modeled
...

7
...
1 Controller Implementation
The PID controller, that was implemented, was Analog in nature and was implemented
by Analog Circuitry
...

These networks are discussed in the following section
...

7
...
2 Analog PID Controller
The PID controller works in a closed loop
...
An
integral control (Ki) will have the effect of eliminating the error of steady state, but can make the
transient response worse
...


Page 55

DESIGN 1: IDEAL PID ALGORITHM
This ideal PID algorithm has similarities with general operational amplifier
...


Figure 17: Ideal PID Controller Design

Overall transfer function of this amplifier is
V2 / V1 = – {(Rf / Ri + Ci / Cf) + (1 / RiCfD) + (RfCi) * D} = – {Kp + Ki / D + Kd D} Appendix
Through this equation we can have
PROPORTIONAL GAIN is
INTEGRAL GAIN is
DERIVATIVE GAIN is

Kp = (Rf / Ri + Ci / Cf),
Ki = (1 / RiCf), and
Kd = RfCi
...
Then follows this configuration is PI and PD cascade to get PID
...


DESIGN 3: PARALLEL PID ALGORITHM
This design may be regarded as the simplest approach to design an Analogue PID Circuit
...


Figure 20: Block Diagram of Parallel PID Controller Design

Page 57

The advantage of using this configuration is that we can have separate controls to adjust
KP, KI, KD and KC (not possible in any other design)
...
We have
also adopted this design to make a PID CONTROLLER ANALOG TUNABLE with different
gain ranges as follows:
KP = 1 TO 1001; KI = 1 TO 20; KD = 0 TO 10; KC = 0 TO 100

And the transfer function of the design is

Gc (s) 

K
U ( s)
 K p  I  KD
E ( s)
s

Appendix

Through this transfer function we have
PROPORTIONAL GAIN is
INTEGRAL GAIN is
DERIVATIVE GAIN is
CASCADED GAIN is

Kp = (R2p / R1p),
Ki= 1 / (R1i C1i),
Kd = (R1d C1d),
Kc = (R2C / R1C)
...
5
...
Obtain an open loop response and determine what needs to be improved
...
Add a proportional control to improve rise time
...
Add a derivative control to improve the overshoot
...
Add an integral control to eliminate the steady state error
...
Adjust each of Kp, Kiand Kd until you obtain a desired overall response
...
Keep the controller as simple as possible
...
5
...
This
sets all the constants to zero
...


Page 58

3) Holding the Reset button down, lift the pendulum to the vertical position and release the
Reset button and pendulum at the same time
...
This verifies that all constants
are properly read as zeros
...

6) Keep repeating steps 3-5 until there's a bit 'of oscillation in the base
...

KP will be too large if the drive wheel is free base or oscillates at a high rate of speed
...
When the KI is added, the base will now
accelerate faster than the pendulum causing Θ to change from a positive angle in a
negative angle (or vice versa)
...
The base should
change direction and, again, accelerate faster signs of the pendulum until Θ changes and
the repetitions of the cycle
...

8) Increase KD in the same manner as KP and Ki until the Overshoot condition is gone and
the pendulum remains balanced
...


Page 59

CHAPTER 8:
FABRICATION
OF SYSTEM

Page 60

8
...
No generally-accepted definition of "design" exists, and the term has
different connotations in different fields (see design disciplines below

8
...
Utilizing this pre-existing physical system, the design team engineered a
modular inverted pendulum configuration that was to be integrated into the current design
...
2
...
This of Aluminum allows for a low-cost,
light-weight, yet strong option to sustain the forces exhibited within the system
...

Selecting the bar in Aluminum also allows for more adjustability with weight fluctuation

Figure 21: Pendulum Rod

8
...
1
...
These shaft
collars have set screws spaced 90 degrees apart that secure it to the pendulum bar
...
One-Piece
Clamping Collars are designed to handle applications that require a greater axial load capacity
than Set Screw Collars without marring the shaft
...
The surface treatment
is electrolysis nickel plating which prevents surface corrosion and increases durability
...
2
...
2 Bearing Mount Assembly
The bearing mount assembly consists of an aluminum housing made from Aluminum
...
This
particular design allows for ease of replacement of bearings as well as ease of assembly with its
mounting tabs and holes

Figure 23: Bearing Mount Assembly

8
...
1
...
Shaft features stepped bearing mount
surfaces with machined grooves for retaining rings
...
The retaining rings hold the outer bearings
in place within the bearing mount housings
...


Page 62

Figure 24: Rotary Shaft

8
...
1
...
The strut clamp assembly shown below features a “bolt together”
design that locates the pendulum bar to the rotating shaft securely
...


Figure 25: Strut Clamp Assembly

8
...
The overall fixture
design required the allowing for future additions of angle sensors as well as the sensors to couple
at the ends of the rotating shaft
...


Page 63

8
...
1 Components and Materials
To allow for proper sensor installed height, work plates were needed as spacers under the
bearing mounts
...
Material was not as crucial in this application as the desired
performance was small, thus the plates were specified as low carbon steel allowing for strength
at minimal cost

Figure 26: Work Plate

MATERIAL SELECTION
We mainly use aluminum as a material in the fabrication of our project
...
Also, we have used Teflon for coupling the rod of the pendulum
...


8
...
4
...
It was determined through simulation that resolution was very
important on the stability of the system
...

LCD
LCD was needed for the interfacing purposes to display the angle of the pendulum read
through the angle encoder
...
5 Final Physical System Configuration
Finally, we have come across through the following design
...
1 Introduction
In this chapter we will be discussing the Electronic circuitry used as to stabilize the pendulum in
upright position
...


9
...
Often motors are controlled from some kind of “brain” or micro controller to
accomplish a mechanical goal
...
An H-bridge circuit inputs the micro
controller instructions and amplifies them to drive a mechanical motor
...

9
...
1 Direction Control (Hybrid-Bridge Topology)
Motors can rotate in two directions depending on how the battery is connected to the
motor
...
However, to run the motor in reverse just switch
the connections; connect the positive battery wire to the negative motor wire, and the negative
battery wire to the positive motor wire
...
The H-Bridge electronic structure is explicit
in the name of the circuit - H -Bridge
...
If it is desired to turn the motor on in the reverse direction, switches 2 and 3
must be closed to power the motor
...
2
...
The switches are power MOSFETs (transistors) that have certain properties that
allow them to switch high currents based on an input signal
...
In the H-Bridge case, to put a MOSFET into the Cut-off mode, the
input signal (Gate Voltage) to the MOSFET must be grounded
...
MOSFETS
are three terminal devices with the terminals being the Gate, Drain, and Source
...
3 CMOS Microcontroller
The controller board has 2 main functions, to measure  and to drive the motor
...
The motor is
controlled by an H-bridge which is driven by the PIC16F684 Enhanced Capture/Compare/ PWM
Module (ECCP)
...
There are 5 potentiometers located on the controller board, 3 of which are used for adjusting the PID constants (KP,
KI and KD) and one to measure Θ
...
The input filter is a low-pass Bessel filter with a cut-off frequency of 60 Hz
and has a voltage gain of 6
...

The Bessel filter is used because it has the best response to a step function
...
) The cut-off frequency was chosen to be at least twice the expected frequency of the
pendulum
...
Its task is initialization of
routines i
...
checking which registers are to be read first when power is set on or MCU is set to
be restart
...
Applies a condition to
checks the status of flags whether they’re set or not
...

The interrupt service routine is used to control the speed of the PID loop and is set to set
to run off the Timer0 Interrupt
...
When the TMR0 register overflows, the Timer0 Interrupt Flag is set
...
9 milliseconds (1/256 Hz)
...
5 μs per instruction
...


Figure 34: Pin Description of 16f684 Microcontroller

Page 71

9
...
This
figure demonstrates the component level description of the system that how the different parts of
the circuit are connected to each other
...


Figure 35: Detailed Schematic diagram of the Inverted Pendulum System

Page 72

9
...
Rear side view of the PCB
2
...


Figure 38: PCB Layout of Controller Board (1)

Here is component level view of the Microcontroller board,

Figure 39: PCB Layout of Controller Board (2)

Page 74

This diagram shows the rear side of the LCD Interfaced circuit
...


Figure 41: LCD Interface Circuit (1)

Page 75

This is a final diagram when all the circuit is coupled to the Inverted Pendulum System
...
This
is an ideal exercise to show his talent as an control engineer
...

This exercise provides a chance of designing a controller for a system that has a good
dynamic behavior and hence the consideration for the transient response is emphasized
...
We designed a controller for this system and showed that if the delay time of
sampling is not too large, then still the local controller stabilizes the system
...

The foundation is laid for future research
...

An interface was also created through hardware and software to integrate the controller
...

The most beneficial aspect of this project was that it gave exposure to a full system
design
...

The power of MATLAB and Simulink becomes more evident to one as all these designing would
not have been possible without these tools
...

First of all, we would like to express deepest appreciation to our supervisor Asst
...
Saleem Ata, (EED, UMT) for his continuous effort, guidance and support throughout
this project
...

Special thanks to Asst
...
Jameel Ahmad (EED, UMT) and Muhammad Waqas
(Lect
...

Sincere thanks to Asst
...
Umar Farooq (Basic Physics dept
...

To all lecturers who have taught, thank you for the lesson that has been delivered
...


Last but not least, we would like to express our heartiest appreciation to our parents
and our family, who are always there when it matters most
...
The schematic of the
amplifier is shown below in which the input voltage and impedance are V1 and Z1 respectively,
and V2 is output voltage
...
jC1  1

and

Z2 

R2
...
C2  1
jC2

Substitutes into eq(1) and simplifying we have,
V2 / V1 = – {(Rf / Ri + Ci / Cf) + (1 / RiCfD) + (RfCi) * D}
= – {Kp + Ki / D + Kd D}

Design 2: SERIES PID ALGORITHM
Here the transfer function of the controller is achieved as product of PI and PD controller
...


Page 81

Figure 44: Schematic of Series PID Design

According to the figure,

Gcomb(s) = Gi(s)*Gd(s)


...
D

Gi ( s) 

Simplifying,

and

 i1  i2

VC

Vi1

and

1
CI 1
...
Ci1
...
C1d
...
C1d )
...

GCOMB  ( K PI 

KI
)*( K P 2  K D
...
K P 2  Ki )  (

K P 2
...
K D )
...


Figure 45: Schematic of Parallel PID Design

For Kp,

i1  i2  0

Kp= V0  

So,

Vi
V
 0
Rip
R2 p

leads to

V1

R2 p
R1 p

For Ki,

i3  i4  0
So,

leads to

Ki=

1
V0
C
...
Ci1
...
D

V0
R1D

V1
1/ C1D
...
R1D
...
s
V1
s

This equation has two pole(s) and one zero(s)
...
M
...
9;
m=0
...
47;
l=0
...
0053;
r=0
...
5;
Kf=2
...
8;

%
%
%
%
%
%
%
%
%
%
%

Mass of cart in kg
mass of pendulum in kg
length of pendulum in meter
length of pendulum to centre of gravity
moment of inertiain Kg
...
of motor in sec
feedback gain in V/rad/sec
motor gain in rad/sec/V
friction of cart in N/m/sec
acceleration due to gravity

% Input force=u
% Cart position=x
% Angular displacement= theta

Page 86

(2)
...

num_Th_U = [0 0 Kp];
den_Th_U = [Ap^(-2) 0 -1];
Th_U = tf (num_Th_U, den_Th_U);
% G2(s) = U(s) / E(s)
% u represents the input force on the cart by the pulley chain mechanism,
% e represents the input to the motor driving pulley-chain mechanism
...
M-FILE FOR ANALYSIS OF THE UNCOMPENSATED
INVERTED PENDULUM SYSTEM
%*************************************************************
% DESIGN AND IMPLEMENTAION OF INVERTED PENDULUM
% inverted Pendulum initial data
% Following File will show the response of Uncompansated
% open_loop and closed_loop poles and zeros of Inveted Penduum
% SST UMT, LAHORE, PAKISTAN
%**************************************************************
% variables G, GH, H, Th_U, U_E
load func_ip_uc
%
%
%Part(1)
%pole zero plot of un_cpmpensated poles
figure
pzmap (G)
title ('Pole-Zero Map of Open-Loop Uncompensated Inverted Pendulum System')
grid
%
%Part(II)
%Impulse plot of un_cpmpensated poles
figure
impulse (G)
title ('Impulse Response of Open Loop Uncompensated Inverted Pendulum System')
grid
%
%Part(III)
%Step plot of un_cpmpensated poles
figure
step (G)
title ('Step Response of Open Loop Uncompensated Inverted Pendulum System')
grid
%
%Since for the transfer_Function, we need the output block and an input
%block, so lets go for the transfer_function deffinition, tf=G/(1+GH),
% Root Locus Plot of Uncompensated System
%
%Part(IV)
figure
rlocus (GH)
title ('Root Locus of Uncompensated Inverted Pendulum System')
grid
%
%Part(V)
% Locations of Poles and Zeroes of Closed-Loop Transfer Function in Complex Plane
figure
pzmap (feedback (G, H))
title ('Unity Feedback Closed-Loop Uncompensated Inverted Pendulum System')
grid

Page 88

(4)
...

Kp = 20;
Ki = 100;
Kd = 1;
Kc = 30;
num_PID = Kc * [Kd Kp Ki];
den_PID = [1 0];
disp(' ')
disp ('The transfer function of the PID Controller is:')
disp(' ')
PID = tf (num_PID, den_PID)
% G_comp(s) = PID(s) * G(s)
% Overall Forward Transfer Function
...
M-FILE FOR ANALYSIS OF THE COMPENSATED
INVERTED PENDULUM SYSTEM
%***********************************************
% DESIGN AND IMPLEMENTAION OF INVERTED PENDULUM
% inverted Pendulum initial data
% SST UMT, LAHORE, PAKISTAN
%***********************************************
% variables G_comp, G_comp_H, Gc_comp, PID
load func_ip_comp
%Part(1)
% Locations of Poles and Zeroes of Open-Loop Compensated Transfer Function in Complex Plane
figure
pzmap (G_comp_H)
axis ([-15 10 -1 1])
title ('Pole-Zero Map of Open-Loop Compensated Inverted Pendulum System')
grid
%Part(2)
% Impulse Response of Compensated Inverted Pendulum System
figure
impulse (Gc_comp)
title ('Impulse Response of Closed-Loop Compensated Inverted Pendulum System')
grid
%Part(3)
% Step Response of Compensated Inverted Pendulum System
figure
step (Gc_comp)
title ('Step Response of Closed-Loop Compensated Inverted Pendulum System')
grid
%Part(4)
% Root-Locus Plot of Compensated Inverted Pendulum System
figure
rlocus (G_comp_H)
sgrid (0
...
h>
#include ...
h>
#include ...
2 kHz
// TMR2 Off with no prescale
// Sets Duty Cycle to zero
// Start Timer2

ANSEL = 0b00110101;
VCFG = 0;
ADFM = 1;
ADCS0 = 1;
ADCS1 = 0;
ADCS2 = 1;
CHS0 = 0;
CHS1 = 0;
CHS2 = 0;
ADON = 1;

// Configure AN0,AN2,AN4 and AN5 as analog
// Use Vdd as Ref
// Right justified A/D result
// 16 TOSC prescale

// Channel select AN0

//Turn A/D on

en0 = en1 = en2 = en3 = term1_char = term2_char =0;
ki = kd = 0;
kp = off_set = 0;
temp_int = integral_term = derivative_term = un =0;
SumE_Max = 30000;
SumE_Min = 1 - SumE_Max;
do_PID = 1;
// Allowed to do PID function
T0CS = 0;
// Timer0 as timer not a counter
TMR0 = 10;
// Preload value
PSA = 0;
// Prescaler to Timer0
PS0 = 0;
// Prescale to 32 => 256 Hz
PS1 = 0;
PS2 = 1;
INTCON = 0;
PIE1 = 0;
T0IE = 1;
// Enable Timer0 int
GIE = 1;
return;
}

void PID()

// The from of the PID is C(n) = K(E(n) + (Ts/Ti)SumE + (Td/Ts)[E(n) - E(n-1)])

{
integral_term = derivative_term = 0;
// Calculate the integral term
SumE = SumE + en0;
if(SumE > SumE_Max){
SumE = SumE_Max;
}
if(SumE < SumE_Min){
SumE = SumE_Min;
}

integral_term = SumE / 256;
integral_term = integral_term * ki;
integral_term = integral_term / 16;

// SumE is the summation of the error terms
// Test if the summation is too big

// Test if the summation is too small
// Integral term is (Ts/Ti)*SumE where Ti is Kp/Ki
// and Ts is the sampling period
// Actual equation used to calculate the integral term is
// Ki*SumE/(Kp*Fs*X) where X is an unknown scaling factor
// and Fs is the sampling frequency
// Divide by the sampling frequency
// Multiply Ki
// combination of scaling factor and Kp

Page 93

// Calculate the derivative term
derivative_term = en0 - en3;
if(derivative_term > 120){
derivative_term = 120;
}
if(derivative_term < -120){
derivative_term = -120;
}

derivative_term = derivative_term * kd;
derivative_term = derivative_term >> 5;

// Test if too large

// test if too small
// Calculate derivative term using (Td/Ts)[E(n) - E(n-1)]
// Where Td is Kd/Kp
// Actual equation used is Kd(en0-en3)/(Kp*X*3*Ts)
// Where X is an unknown scaling factor
// divide by 32 precalculated Kp*X*3*Ts

if(derivative_term > 120){
derivative_term = 120;
}
if(derivative_term < -120){
derivative_term = -120;
}
Cn = en0 + integral_term + derivative_term;
Cn = Cn * kp / 1024;
if(Cn >= 1000)
{
Cn = 1000;
}
if(Cn <= -1000)
{
Cn = -1000;
}
if(Cn == 0){
DC1B1 = DC1B1 = 0;
CCPR1L = 0;
}
if(Cn > 0){
P1M1 = 0;
temp = Cn;
if(temp^0b00000001){
DC1B0 = 1;
}
else{
DC1B0 = 0;
}
if(temp^0b00000010){
DC1B1 = 1;
}
else{
DC1B1 = 0;
}
CCPR1L = Cn >> 2;
off_set = off_set +1;
if(off_set > 55){
off_set = 55;

// C(n) = K(E(n) + (Ts/Ti)SumE + (Td/Ts)[E(n) - E(n-1)])
// Sum the terms
// multiply by Kp then scale
// Used to limit duty cycle not to have punch through

// Set the speed of the PWM

// Motor should go forward and set the duty cycle to Cn
// Motor is going forward

// Used to stop the pendulum from continually going around
// the offset is use to adjust the angle of the pendulum to slightly
// larger than it actually is

Page 94

}
}

else {
P1M1 = 1;
temp_int = abs(Cn);
temp = temp_int;
if(temp^0b00000001){
DC1B0 = 1;
}
else{
DC1B0 = 0;
}
if(temp^0b00000010){
DC1B1 = 1;
}
else{
DC1B1 = 0;
}
CCPR1L = temp_int >> 2;
off_set = off_set -1;
if(off_set < -55){
off_set = -55;
}
}
en3 = en2;
en2 = en1;
en1 = en0;
en0 = 0;
do_PID = 0;
RA4 = 0;
return;
}
void Set_Constants()
{
ANS2 = 1;
ANS4 = 1;
ANS5 = 1;

// Motor should go backwards and set the duty cycle to Cn
// Motor is going backwards
// Returns the absolute int value of Cn
// int to char of LS-Byte

// Used to stop the pendulum from continually going around

// Shift error signals

// Done
// Test flag to measure the speed of the loop

// Configure AN2 as analog
// Configure AN4 as analog
// Configure AN5 as analog

ADFM = 1;
CHS0 = 0;
CHS1 = 0;
CHS2 = 1;
temp = 200;
while(temp){
temp--;
}
GODONE = 1;
while(GODONE);{
temp = 0;
}
ki = ADRESH << 8;
ki = ki + ADRESL;

// Right justified A/D result
// Channel select AN4

CHS0 = 1;
CHS1 = 0;
CHS2 = 1;

// Channel select AN5

// Gives delay

// Does nothing
...

// Store the A/D result to Differential Constant

// Channel select AN2

// Gives delay

// Does nothing
...
h>
#include ...
h>
#define XTAL_FREQ

4MHZ

#include "delay
...
c"
#include "lcd
...
c"

/* display on/off, cursor on/off, blinking char at cursor position */
#define LCD_DISP_OFF

0x08 /* display off

#define LCD_DISP_ON

0x0C /* display on, cursor off

#define LCD_DISP_ON_BLINK
#define LCD_DISP_ON_CURSOR

*/
*/

0x0D /* display on, cursor off, blink char
0x0E /* display on, cursor on

*/
*/

#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char

*/

#define testbit(var, bit) ((var) & (1 <<(bit)))
#define set_bit(ADDRESS,BIT) (ADDRESS |= (1<#define clear_bit(ADDRESS,BIT) (ADDRESS &= ~(1<#define flip_bit(ADDRESS,BIT) (ADDRESS ^= (1<#define test_bit(ADDRESS,BIT) (ADDRESS & (1<//set_bit(TRISA, 1);
//To clear a bit it woulld be clear_bit(TRISA, 3); and so on
...
192 MSEC

// INTCON=0b00100000;
// PIE1=0b00000000;
// PIR1=0b00000000;
PEIE=1;
GIE=1;

}
unsigned char ReadADC(unsigned char ADC_Channel)
{
ADCON1 = 0b00000010; // ADC On
//

pic16f676 ADC setting is not same as pic16f87X

//

A new reg ANSEL

// for pic16f87X ADCON0 = (ADC_Channel << 3) + 1;

ADGO = 1;

// for pic16f676 ADCON0 = (ADC_Channel << 2) + 1; GODONE = 1;

Page 104

volatile unsigned int ADC_VALUE;
/* Selecting ADC channel */
ADCON0 = (ADC_Channel << 3) + 1;

ADFM

=0;

ADIE

=

ADIF

/* Enable ADC, */

= 0;

0;

/* ADC interrupt Disable */
/* Resetting the ADC interupt bit */

ADRESL =

0;

ADRESH =

/* Resetting the ADRES value register

0;

*/

// delay for sample and hold capcitor charge
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");

GO_DONE = 1;

/* Staring the ADC process */

while(!ADIF) continue;
ADC_VALUE

/* Wait for conversion complete */
= ADRESH ;

/* Getting LSB of CCP1 */

ADCON1 = 0b00000110; // ADC Off
ADIF =0;
return (ADC_VALUE);

/* Return the value of the ADC process */

}

Page 105

BIBLIOGRAPGHY
1
...

3
...

5
...
Publisher: Prentice Hall
Copyright: 2010
Control System Engineering, 4/E by Norman S
...
(2005)
...
ISBN 0-13-149930-0
Physics for Scientist and Engineers, Raymond A
...
Jewett, Jr
...

Engineering Mechanics - Statics, R
...
Hibbeler, 12th Edition

6
...

8
...

10
...

12
...


http://www
...
umich
...
html
http://en
...
org/wiki/Inverted_pendulum
www
...
com
...
pdf
http://www
...
usyd
...
au/tutorials_online/matlab/examples/pend/invPID
...
ee
...
edu
...
html
https://instruct1
...
cornell
...
htm
http://www
...
com/topic/Inverted_pendulum
http://www
...
com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote
=en021807
14
...
google
...
pk/books?id=UhAAohoqAhAC&printsec=frontcover&dq=inverted+pen
dulum&source=bl&ots=crMGLdDdUb&sig=ECvQEjmF5M_BZ4FPzTBL0tSxzGI&hl=en&sa=
X&ei=3bJTUOK5BoXCtAbGmoHgDA&ved=0CCkQ6AEwAA#v=onepage&q=inverted%20pe
ndulum&f=false

Data Sheets:
1
...

3
...

5
...

7
...

9
...

11
...


http://tinyurl
...
com/8vehszh
http://tinyurl
...
com/9o3qsya
http://tinyurl
...
com/9n3zxmq
http://tinyurl
...
datasheet
...
kr/datasheet-html/I/R/F/IRF9540_HarrisCorporation
...
html
http://tinyurl
...
com/9ems89b
http://tinyurl
...
com/9cdy7bg

Page 106


Title: Inverted Pendulum Report
Description: Classic inverted pendulum control problem is of interest that can be solved using a variety of systems and solutions. This problem is similar to trying to balance the broomstick practice. This problem invites those who are interested in the design of the system, control theory, and just plain problem-solving try to develop a working system. For this project, the motivation is to translate the mathematical models developed in control theory teaching real-time system. The design process of this project has required a great deal of planning and testing before deciding on a final design because there were so many alternatives to choose from. The design problem can be broken down into subsystems that are highly interdependent. The actual design of each subsystem is an iterative process of component testing and implementation of simple solutions until the solution "optimal" was found. The solution "optimum" may be defined as the solution, which can be developed at minimum cost that balances the pendulum better. During the design process, many obstacles have been encountered. The setbacks of the most important and time-all related to engine choice. When the first motor has been omitted, an engine torque faster and higher was obtained because the original one was not able to react fast enough in order to balance the pendulum. Since the new engine has different dimensions than the first, the entire mechanical system had to be redesigned. The next two engines broke when the control effort was too high and the direction changing rapidly, putting too much stress on the internal gears. To solve this problem, the controller has been redesigned with a closer bond on the control effort. The model is obtained on the basis of mathematical analysis of the physical system. Unknown parameters of the model are obtained from experiments in real time on the system inverted pendulum. The model was created with respect to the most nonlinearity in the system. Linearity is caused by fundamental principles of the system and by friction between the individual parts of the system. Therefore, the model is highly nonlinear and then linearization around the point of work has been performed and continuous linearized model was calculated as well as its discrete version. A controller has been constructed that has also been verified by experiments in real time.