Sie sind auf Seite 1von 4

IMPLEMENTING BALL BALANCING BEAM USING DIGITAL IMAGE

PROCESSING AND FUZZY LOGIC


Javaid Iqbal, Mehmood Anwar Khan, Saadia Tarar, Mariam Khan & Zeasth Sabahat
Department of Mechatronics, College of E&ME, National University of Sciences & Technology, Pakistan.
18th Annual Canadian Conference on Electrical and Computer Engineering 2005

Abstract
Fuzzy logic is a paradigm for an alternative design
technique, which can be applied in both linear and non linear
systems for embedded control. It is a problem-solving control
system methodology that can be built into anything from small,
embedded controller and hand-held products to large
computerized process control systems.
This paper proposes and analyses methods to control
a ball balancing system using fuzzy logic. It is a nonlinear
dynamic system which is quite difficult to control using
conventional methods. It has delayed feedback associated with
control actions; however, control system based on fuzzy logic
requires less mathematical derivation in design and has a high
noise tolerance. Image of the ball taken from an Audio/Video
(AV) camera is processed to determine the coordinates of its
centre. This input data is fed into the 68HCS12
microcontroller, which has the most efficient implementation of
fuzzy logic instruction sets. Built-in PWM channels, A to D
converters, 32kb flash memory and in-system programming
make this controller ideal for the system considered. The
controller processes this input using the fuzzy logic rule base
and sends consequent signals to the servo motor controlling
the beam motion.
Keywords: Ball on beam; 68HCS12; fuzzy logic; digital image
processing; non-linear control theory.
1. INTRODUCTION
An important set of contemporary industrial processes
and systems are unstable by nature and essentially require
feedback control for effective and safe performance [1].
However the crucial problem that exits in the study of such
real, unstable systems is that they cannot be brought into the
laboratory for analyses. Due to its simplistic design and
relevant, dynamic characteristics, ball balancing beam has
become an ideal model for complex, non-linear control
methods.
Although PID control is an efficient technique for the
handling of non-linear systems but modeling these systems is
often troublesome and sometimes impossible using the laws of
physics. Therefore, using a classical controller is not suitable
for nonlinear control application [2].

0-7803-8886-0/05/$20.00 2005 IEEE


CCECE/CCGEI, Saskatoon, May 2005

On the other hand the concept of fuzzy logic has


opened a whole new avenue for control methodology. PID
control requires the design of a model with sensors and
actuators, determination of the parameters of PID controller
using control theory and finally the development of an
algorithm for the controller. Whereas in case of fuzzy logic the
system behavior is characterized using human knowledge
which directly leads to the design of control algorithm on the
basis of fuzzy rules. These rules are in terms of the relationship
of inputs to their corresponding outputs, and precisely
determine the controller parameters. Any adjustment or
debugging only requires modification in these fuzzy rules
instead of the redesigning the controller. Hence control
technique based on fuzzy logic not only simplifies the design,
but also reduces the tedious task of solving complex
mathematical equations for nonlinear systems. Consequently,
fuzzy logic controller delivers a better performance in cases
where the conventional controller does not cope well with the
non-linearity of a process under control [3].
Despite adding filter circuitry, the noise in the output
of distance or other analog sensors cannot be completely
eliminated. In comparison, digital image processing provides a
much more reliable source of input to any controller. It also
eliminates the task of A to D conversion of analog input and
computation of equations on the basis of graphs obtained from
experimental results. Thus visually acquiring the position of
the ball and developing a fuzzy rule base to design a control
system to govern the PWM of the servo motor on the basis of
this input proves to be a more efficient technique with fewer
chances of errors.
2. BASICS OF BALL AND BEAM
2.1. Mechanical Structure
The system design consists of a ball which can roll with one

2241

Ball

Beam

Lever
Arm
Gear

Figure1: Mechanical Design of Ball and Beam System.

degree of freedom along the length of a side pivoted beam. The


structure is similar to a four-bar mechanism. The beam can be
tilted by applying an electrical control signal to a servo motor
attached at the other end through a gear system of ratio 1:5.5.
Servo motor is an intelligent selection where precise speed
control is an issue.
2.2. Control Theory
The Lagrangian equation of motion for the ball of
mass m, moment of inertia J, input angle and ball position r
is given as [9]:

(m + )r + mg sin mr ( )
J
R2

=0

(1)

where R is the radius of the ball. Hence the transfer function of


the gear angle Y(s) to the ball position R(s) is:

R (s )
mgd
1
=

Y (s )
J
s2
L 2 + m
R

Ball position (cm)

Plot of this transfer function indicates ball position as a


function of time:
80
60
40
20
0
1

Time (sec)

Figure 2: Open loop response of ball and beam system

From this plot it is clear that the system is unstable


and open-loop in response. Such a system proves to be a
challenging control problem. The task is to design a robust
controller that manipulates the ball position by varying the
angle of the beam in minimal time period.

determined and serially sent to the controller at a baud rate of


9600. Since it is convenient to detect white color of RGB value
closer to 255, a white ball is used for this purpose. Direct
transfer of serial data fro the PC to the controller expels any
need for filter circuitry to remove noise, leaving the data
completely accurate.
4.

Fuzzy logic controllers can imitate human knowledge


and this approach can be best represented with a set of
linguistic rules [4]. The essence of fuzzy logic control is that
such linguistic fuzzy rules are chosen using some decision
making process, from a rule table constructed using human
control experience [7]. The stages of fuzzy control are:
Fuzzification
Fuzzy inference
Defuzzification
Visually acquired image of the ball is captured and
processed to determine its position on the beam which is then
serially transmitted to the controller to compute error (e) in the
ball position and its derivative (). These entities are then
interpreted to analogous fuzzy inputs by the designed rule base.
The controller is modeled to accept the inputs and map them
into their respective membership functions.
During the fuzzification step, these system input
values are compared against stored input membership functions
to determine the degree of membership. The degree of
membership is the placement in the transition from 0 to 1 of
conditions within a fuzzy set. The inference system analyses
these evaluated functions to trigger an appropriate output state
and assigns a membership value which is then defuzzified into
a crisp control output. The system is validated through retests
for adjustments. Based on this fuzzy inference system the
model of the fuzzy controller can be summarized:
FLC
Fuzzify

Defuzzify
y(t)

r(t)

3. DIGITAL IMAGE PROCESSING

Distance sensor or other similar analog sensors often


have a non linear response to change in physical parameters,
distance in this case. Some relationship has to be developed
between the input and its corresponding output voltage. The
most suitable way to accomplish this task is to experimentally
determine the resulting voltage for some known distances and
compute a relationship between these two parameters using
any numerical computation software.
However, the use of digital image processing not only
eliminates this tedious task of experimentation and
mathematical calculation but also overcomes the limitation of
noise posed by analog sensors. An AV camera takes video
image of the ball. Video image is a sequence of 25 static
images per second. The pixel values of each static bitmap
image are scanned to detect the ball, its centre coordinates

FUZZY LOGIC

e(t)

Fuzzy
Inference
System

Ball &
Beam
System

Figure 3: Model of fuzzy controller

Typically, the measurements used are the error in the


output and its derivative [6]. The fuzzy set is characterized for
this input error variable, and the derivative of change in error,
resulting in the output in term of quadrature encoder steps.
The error vector is [5]:
e(t ) = r (t ) y (t )
(3)
Where r(t) is a set of the desired outputs, and y(t) is the actual
output .

2242

Table 1: Rule base of Fuzzy Logic Controller

Video Image

AV Camera

In-system
programming

PC

Ball &
Beam
System

Ball
coordinate
(serial data)

68HCS12
controller

PWM

Figure 4: Block Diagram of System Control

5. 68HCS12 MICROCONTROLLER
The 68HCS12 is a high-speed processing unit. It is the
first controller that has a separate instruction set to specifically
cope with fuzzy logic, making it highly suitable for the fuzzy
control of the ball balancing beam. Full 16-bit data paths
support efficient arithmetic operation and quick math
execution. It runs on a 16MHz crystal thus executing
instructions faster. 1024 Bytes of RAM and 4096 Bytes of
EEPROM make this controller much more suitable in
comparison to conventionally used controllers. Its on-chip
memory mapping allows expansion to over 5 MB of address
space. Independently clocked on board UARTs can be driven
at speeds up to 38400 enabling faster drive of serial port, which
makes it ideal in dealing with the unstable response of the ball.
5.1. Fuzzy Logic Implementation
The 68HCS12 controller includes instructions that
perform specific fuzzy logic tasks. Its compatibility with Clanguage assists in the development of effective fuzzy logic
programs. The fuzzy inference kernel requires less code space
and executes much faster than a comparable kernel performed
on any other microcontroller. To perform complex instructions
it computes functions including addition, subtraction,
multiplication and comparisons. The MEM instruction receives
and calculates the first fuzzy error input on a membership
function in 625 ns at 8MHz. This result is automatically stored
and the instruction updates two pointers so that the next input,
i.e., error derivative, is evaluated without executing any other
instructions between labels of a system input.
NL

-80 -60

NM

NS

ZO

-40 -20 0

PS

PM

20 40

PL

60

80

Figure 5: Membership Function of Output to the Servo Motor

NL

NS

NL

NL

NL

NS

NL

ZO

Ball
Image

ZO

PS

PL

NL

NM

NS

NL

NL

NS

NS

NM

NS

ZO

PS

PS

PS

PM

PM

PM

PM

PL

PL

PM

PL

PL

PL

PL

One execution pass through the fuzzy inference kernel


generates system output signals in response to current input
conditions. This step processes a list of rules from the
knowledge base using current fuzzy input values to produce a
list of fuzzy outputs. REV facilitates un-weighted min rule
evaluation on the complete rule list for the fuzzy logic system
designed.
5.2. Motor control
The servo motor attached to the beam, has an inbuilt
quadrature encoder which enables speed precision and
determining the direction of rotation. When this encoder
rotates, two of its phases, Phase A and Phase B produce
sinusoidal waveforms which are then converted to square
pulses where each pulse represents a fraction of a turn of the
encoder shaft. The pulses from A and B on the encoder are
always aligned 90 degrees out-of-phase.
Phase A

Phase B

Figure 6: Phase A and Phase B of Quadrature encoder

This special phase relationship aids in determining


both the distance and direction the encoder has rotated from its
previous position. External interrupt is used to sample the
quadrature output from encoder and update current position
register to capture the motor position. To keep track of the
encoder position in software, Phase A is connected to an
external processor interrupt line and Phase B to any I/O pin.
Out of the six PWM channels of the microcontroller,
PWM0 governs the left aligned output signal sent to the servo
motor. The duty rate is selected from software. The duty ratio
between high time () and total time period (T) for one cycle is
given by:

D=

The designed fuzzy rule base can be summarized as [8]:

2243

100

(4)

5.3. Sampling Time


Fuzzy logic controller must operate between regular
time intervals to determine a fixed sampling rate. So the
controller is set to be processed whenever a Real Time
Interrupt (RTI) occurs. A sampling rate of 1sec between each
RTI is set to ensure quick motor response to the motion of the
ball. The sub routine obtains values of the encoder by reading
an inport. The encoder values are used to calculate the
instantaneous velocity of the motor shaft by [4]

u (k ) u (k 1)
u (k ) =
t

[3] Von Altrock, "Fuzzy Logic and NeuroFuzzy Applications Explained",


Prentice Hall pp 82, 1995.
[4] Kim C. Ng and Mohan M. Trivedi, A Neuro-Fuzzy Controller for Mobile
Robot Navigation and Multirobot Convoying, IEEE Transactions on Systems,
Man and Cybernetics, Vol. 28, No. 6, 1998.
[5] Paul H. Eaton, Danil V. Prokhorov, and Donald C. Wunsch, II,
Neurocontroller Alternatives for Fuzzy Ball-and-Beam Systems With
Nonuniform, Nonlinear Friction, IEEE Transactions on Neural Networks, Vol
II, No. 2, March 2000.
[6] J. Glower and J. Munighan, Fuzzy Saturating Control of a Ball & Beam
System, IEEE 39th Midwest Symposium on Circuits & Systems, Vol.3,pp
991-994, 1996.

(5)

5.4. Results
Ball and the beam is a highly unstable system that
requires rapid processing and intelligent algorithm. The
implementation of the designed rule base not only enabled an
intelligent and compact programming for quick response but
also gave a flexible means to design and redesign the control
model upon testing. Using the least possible mathematical
calculations the controller was able to map the input
parameters on to the rule base and suggest an appropriate
output.
The 25MHz bus speed of 68HCS12, in addition to
intelligent fuzzy programming, supported quick execution of
the algorithm. The microcontroller proved to be efficient in the
control of such unstable systems as considered.

[7] Hipolit Moreno Llagostera, Control of pneumatic servo system using


fuzzy logic 3rd FPNI - PhD Symposium on Fluid Power, Barcelona, Spain.
[8] Li Xing Guan, Implementation of fuzzy logic controller on non-linear
systems-PUMA 560 Robot, University of New South Wales.
[9] www.engin.umich.edu/group/ctm/index.html.

6. CONCLUSIONS
While PID is an effective technique to implement
control methodology, however it is often very complicated and
time consuming. Fuzzy logic, on the other hand, provides a
good alternative for a robust and cost-effective servo-controller
for non-linear control where no extra sensors are required and
is hence likely to be the more efficient. Execution of inference
process is based on the membership functions and IF/THEN
rules which result in simpler implementation, and consequently
low design costs. This enables design of complex nonlinear
control functions without the use of mathematical computation.
Although the efficiency of fuzzy controller is similar
in most respects to conventional controllers: But the significant
difference is evident in work time, where the fuzzy control is
faster. Moreover, during the debugging the system can be
rectified by altering rules, instead of redesigning the controller.
It does not require any re-modeling or complex equations
describing the relationship between inputs and outputs. Hence,
fuzzy logic has proved to be reliable substitute to design of
control systems.
7. REFERENCES
[1] Peter Wellstead, Ball and Beam 1: Basics, http://www.control-systemsprinciples.co.uk/whitepapers/ball-and-beam1.
[2] Cihan Karakuzu, Stk ztrk , A Comparison of Fuzzy, Neuro and
Classical Control Techniques Based on an Experimental Application,
University of Quafaquaz, No. 6, pp 189-198,July 2000.

2244

Das könnte Ihnen auch gefallen