Theses
Thesis/Dissertation Collections
11-20-1991
Pendulum: Controlling an inverted pendulum
using fuzzy logic
Scott Houchin J.
Follow this and additional works at:
http://scholarworks.rit.edu/theses
This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion
in Theses by an authorized administrator of RIT Scholar Works. For more information, please contact
Recommended Citation
Pendulum:
Controlling
an
inverted pendulum
using fuzzy logic
by
J.
Scott Houchin
Thesis committe:
~o
AIOv
1,
Dr. Pratapa V. Reddy (Chariman), Department of Computer Engineering
Controlling
an
inverted pendulum
using
fUzzy
logic
I,
J.
Scott Houchin, hereby deny permission to the Wallace Memorial Library
of RIT to reproduce my thesis in whole or in part.
Computers
occupy
every
aspectof society.Despite
the
cold error sounds ofthe
supermarket cash register and
the
less
than
informative
"Syntax
error"messages
output
by
the
latest
C
compiler,
computer scientists arecontinually
trying
to
teach
computersto
be
morehuman. The
area of computerized control systemshas
seen significantadvances,
atleast
in
the
interface between
system anddesigner.
In traditional
controltheory,
the
system engineer constructs a complexmathematical equation
to
relatethe
input
ofthe
systemto the
desired
output.In
addition
to
being
non-intuitive,
this
methodincurs
alengthy
development time;
the
construction ofthe
equations requiresthat the
entire systembe
analyzedin
great
detail before
the
engineer canbegin
thinking
aboutthe
control equations.Instead
ofbuilding
ontraditional
controltheory,
we will startover,
throwing
outthe
notionthat
a control system evaluates a complex mathematical equationto
determine
the
system output.Instead
ofmathematics,
use common sense:Describe
the
state ofthe
systemin
"human"terms:
the
temperature
is
very
coldthe
pressureis
too
high
Decide
how
the
system shouldbehave
in
each ofthese
situations:if
the temperature
is very
cold,
turn
up
the
heat
if
the
pressureis
too
high,
openthe
outlet vents alot
Teach
the
computer what we meanby
terms
such as"very
cold,""too
high,"Implement
the
control engineusing
these
rules anddescriptions
This is
fuzzy
logic:
"a
way
to
program computersto
mimicthe
imprecise
way
people think."
There
arethree
main goalsin
our mind whendeveloping
afuzzy
system.First,
by
removing
the
complex mathematics andfalling
back
onbasic
commonsense,
we
have
significantly
decreased
the
development
time
for
the
system.Also,
weremove
the
reliance on certain valuesin
the
environment,
such asgravity
andmotor
torque.
The
resulting
systemis
thus
much moretolerant to
fluctuations
in
these
values.Lastly,
by
using
commonsense,
we wishto
increase
the
overall performance ofthe
system.For
example,
fuzzy
logic
would allow usto
design
an elevator controlunit
that
significantly decreased
the
averagewaiting
time,
or atrain
controlsystem
that
provided a much smoother ridethan
possibleby
ahuman
operator.This
thesis
willexplorefuzzy
logic,
specifically
asit
pertainsto
control systems.However,
many
ofthe
concepts presented willdirectly
carry
overto
otherareas,
Pendulum
Pendulum,
afuzzy
logic
simulator createdspecifically
for
this
thesis,
will alsobe
presented.
Pendulum
allowsthe
userto
configure afuzzy
logic
engineto
controlan
inverted
pendulum.By
allowing
usersto
modify
the
system,
they
canexperiment with
fuzzy
logic
andlearn
first-hand
how
a system willbehave
withdifferent
rulesets,
different
fuzzy
membership
functions,
and underdifferent
conditions.
Pendulum
willbe
usedto
demonstrate:
a
methodology
for
designing fuzzy
systemsthe
effect of variationsin
the
fuzzy
system,
such as curve shapeThe inverted
pendulum
The
systemthat
willbe developed
throughout
this
entirethesis
willbe
aninverted
pendulum controller.The
system consists of a stick mountedto
amotor,
and aprocessing
unit of sometype to
controlthe torque
providedby
the
motor.
The
goalis
to
balance
the
stickin
the
upward position with minimumovershoot and
settling
time.
To
do this,
the
system will causethe
motorto
apply
torque to the stick,
causing
the
stickto
rotate.The
motor will work with oragainst
gravity
andthe
momentum ofthe
stickto
stabilizeit
in
the
upwardposition
(see figure
0 for
several situationsthe
system will encounter).^RN
M.
Figure
0(a)
the
controllerhas brought the
pendulumto the
uprightposition, but
it is
oscillating.The controller must nowtry
to
bring
the
pendulumto
a complete stop,(b)
here
the
pendulumis
offto the
left,
but it is
moving
toward the
desired angle,
sothe
controllermust
try
to
bring
it to
astop
asit
reaches90.
(c)
In this
case,
the
pendulumhas
passedthe desired
angle andis
moving
farther
away.The
controller mustapply
enoughtorque
tothe
pendulum tostop
the pendulum and startIt
moving
in the
otherdirection
before
it
cantry
to balance in the
upright position,(d)
This
Is
the ultimate goal ofthe
controller: toOne:
Fuzzy
logic
1
Fuzzy
sets3
Partial
membership
meanspossibility
4
Operations
onfuzzy
sets5
Union
6
Intersection
6
Inverse
7
Fuzzy
numbers8
Decision
making logic
8
Determination
ofthe
system variables9
Determination
ofthe
quantizationlevel
10
Is
less
quantization alwaysbetter?
11
Determination
ofthe
rulebase
12
Fuzzification
ofthe
systeminputs
16
Curve
shape and art20
Evaluation
ofthe
fuzzy
rulebase
21
Evaluating
the
logical
terms
21
Evaluation
ofthe
antecedent22
Defuzzification
ofthe
decisions
23
Max-Product
23
Max-Dot
26
Nominal
Average
28
Other
methods30
How
can we allow art?30
Two: Pendulum
32
Pendulum
physics33
Fuzzy
algorithm36
Displaying
information
37
Pendulum
window38
Rule
editor39
Membership
editor40
Strip
charts41
Variable
diaplay
42
Menus
42
Apple
Menu
43
File
Menu
43
Edit
Menu
44
Simulation
Menu
45
Start
(or
Stop)
45
Step
45
Set Target Angle
46
Set
Tolerance
46
Set
Environment
46
Set
Position
andVelocity
47
Reset
Position
andVelocity
47
Change membership
X
scale48
Edit
Membership
Menu
48
Display
Menu
49
Editing
the
rulebase
50
Editing
membership
functions
51
Changing
the
environment54
Running
the
system54
Saving
the
system55
Three: System Creation
56
Desired
environment57
Design
goals57
First
attempt58
First
attempt performance61
Second
attempt61
Second
attempt performance63
Four:
Fixing
what ain't
broke
65
Changing
the
normalization scales66
Angle
normalization scale66
Changing
the
speed normalization scale68
Changing
the
curve shape69
Changing
the
rulebase
70
Five: Non-ideal
worlds
74
Changes in
gravity
75
Changes in
motortorque
76
Noise in
sensor measurements76
Constant
random noise77
Spikes
78
Why
sotolerant
79
oo;
That's
all
folks!.
80
What
welearned
81
Applying
the
solutionto
other problems85
Is
fuzzy
logic
for
everyone?85
1.
Possibility
vs.probability
5
2.
Sample
Rule
Table
15
3.
Meaningful
ruletable
16
4.
First
attempt atdefining
zero17
5.
Definition
ofzeroexcluding
values notin
the
domain
18
6.
Useful
definition
of zero19
7.
Definition
ofthe
linguistic
terms
negative, zero,
and positive19
8.
Alternate definition
of zerousing
sine andcosing
segments20
9.
Fuzzification
oftwo
rules22
10.
Summary
ofthe
fuzzy
logic
operations23
11.
Max-Product
method25
12.
Max-Dot
method27
13.
Free
body
diagram
of a pendulum34
14.
Pendulum
window38
15.
Rule
editor39
16.
Membership
editor40
17.
Strip
chart41
18.
Variable
window42
19.
Apple
menu43
20.
File
menu43
21.
Edit
menu44
22.
Simulation
menu45
23.
Change
membership
X
submenu48
24.
Edit
Membership
menu48
25.
Display
menu49
26.
Setting
a rule50
27.
Opening
a chartfor
a rule51
28.
Using
overlap
in
a curvedefinition
52
29.
Set
Environment...
dialog
box
54
30.
First
attempt rule set60
31.
First
attemptmembership functions
60
32.
First
attempt performance61
33.
Second
attempt rule set andmembership functions
63
34.
Second
attempt performance64
35.
Backwards
sinemembership
function
70
36.
Backwards
sine performance70
37.
Reduced
rule set73
38.
Reduced
rule setperformance73
39.
System
performance82
40.
Effect
ofchanging
the
normalizationfactors
82
41.
Backwards
sine performance83
42.
Reduce
rule set performance84
43.
Usable
values ofgravity
and motortorque
84
Fuzzy
logic is
not an attemptto
make computersthat
can "think."Although
it
has
rootsin
artificialintelligence,
purefuzzy
logic
systems(not
including
self-organizing
systems)
try
only
to
mimicthe
human
thought
process asspecifically
determined
by
the
human
designer.
When
designing
afuzzy
system,
two
goalsare
in
mind:to
programthe
systemto
describe
things the
sameway
wedo
to
instruct
the
system what action shouldbe
taken
whenthe
systemis in
aparticular state
The later is
nothing
newto
systemdesigners;
almostevery deterministic
computer program ever written
has
this
goal(at
least implicitly). It is
the
former
that
brings
something
newto
control systemtheory.
What
is
neededis
a newway
to
describe
things
away
that
allowsfor
doubt
anduncertainty;
fuzzy
settheory
providesthis.
Once
the
systemis
described,
decision-making
logic
that
candeal
withthe
"fuzziness"
in
the
systemis
needed.In
additionto
a method(set
ofrules)
for
translating
the
fuzzy
descriptions
ofthe
systeminto
the
desired
actions,
we alsoneed a method
to
deal
withconflicting decisions
madeby
different
rulesin
the
Fuzzy
sets
The
basis
offuzzy
logic is
the
fuzzy
set,
an extension ofthe
conventional set.In
conventional set
theory,
a set(S)
has
asits
members objectsfrom
the
universe ofdiscourse
(U).
Each
objectin U is
either a member ofS
oris
not a member ofS;
there
is
noin-between
ground:-ax{(xeS)A(xeS))
Consider,
for
example,
the
set old.Conventional
settheory
statesthat
a particularperson
is
eitherold,
orthat
personis
not old.But
we ashumans do
notthink
in
that
manor.When
wethink
ofold,
wethink
ofsomething
that
peoplebecome
gradually,
not all at once at some magic age.Instead
ofrequiring
this
all ornothing membership
rule,
we wouldlike
to
allowan object
to
be
a partial member of a set.This
fits
ourdefinition
ofold nicely.Different
people are(members
ofthe
fuzzy
set)
oldto
different
degrees;
somepeople are more old
(old
to
ahigher
degree)
than
others.Let
afuzzy
setF
be
characterizedby
amembership
function
\If(x),
whichrepresents
the
degree
ofmembership
ofthe
object xin F. The
membership
function is defined in
the
range0
<u.f(x)
<1,
U-pOt)
=0
meaning
that
xis
not atall a member of
F
andUf
(x)
=1
meaning
that
xis
definitely
a member.The
terms
"measure
of belief" or"measure
ofconfidence"
are also used
for
the
function
u.j
(x)
because
the
degree
ofmembership
in
the
setis
often usedto
representthe
degree
to
whichwebelieve
orthe
confidencethat
an object couldbe
a member ofFor example, if
\i0id(joe)
=0.1
and\i0id(fred)
=0.7
then
we cansay
that
the
measureofconfidence
in
fred
being
oldis
strongerthan the
measure of confidencein
joe,
or
fred is
older(more
old) than
joe.
Partial
membership
means
possibility
This
definition
of afuzzy
setbrings up
the
question of what we want partialmembership
in
afuzzy
setto
represent.The interpretation
that
willbe
usedin
this
thesis
is
that
given a conventional setS
and an"equivalent
(in
meaning)"
fuzzy
setF:
M*)
=possibility
(jc
eS)
=nx(S)
Note
that this
is
notthe
same asthe
probability
that
xis
a member ofS.
For
example,
it is
very
possiblethat
a new personal computer releasedtoday
willnotbecome
obsoletefor
severalyears;
however,
it
is
notvery
probable.The
possibility
nx
(S)
representsthe
easethat
xmay
take
S
as avalue.In
ourcase,
it
time
untilobsolete
(years)
Figure
1athe
probability
of a personal computerbecoming
obsolete vs. time:According
to the
curve,
It
Is
mostprobablethat the
computer willbecome
obsolete aftertwo years;
however,
the
probability
for the time
being
shorter orlonger
Is
much smaller.time
until obsolete(years)
Figure 1b
the
possibility
of a personal computerbecoming
obsolete vs. time:According
tothe curve, it is
equally
possiblefor
thecomputertobecome
obsoletefrom
zeroto threeyears; these
caseshave
already
been
seenIn
thehistory
ofthe computertodate
Notice
alsothe
different
constraints onprobability
(P)
andpossibility
(71):
5>(*,)=i
i
max7iL =1 i '
The
possibility
function defines
an upperbound
onthe
probability
function.
Operations
on
fuzzy
sets
Once
fuzzy
setshave
been
defined
in
the
universe ofdiscourse,
operations onthese
sets mustbe
defined. To fulfill
the
purpose ofthis
thesis,
three
operations mustbe
defined:
union,
intersection,
andinverse.
Since
fuzzy
settheory
is
an extension of conventional settheory,
fuzzy
operations shouldbe
extensions ofUnion
Conventionally,
the
union oftwo
sets(A
andB)
is defined
asthe
set of all x suchthat
xis
amember ofA,
or xis
a member ofB:
AuB
=[x\{x
A)v
(xeB)}
To
expandthis to
fuzzy
settheory,
we must considerthe
fact
that
not all objectsaremembersof
the
setsto the
samedegree.
In addition,
we cansay
that
all objectsaremembers of
any
setto
somedegree;
the
degree
wouldbe
zerofor
those
items
that
"are
not"members of
the
set.The
union operation canbe defined
by
replacing
the
"or"function
withthe
maximum valuefunction. Thus
the
degree
of
membership
in
the
union oftwo
sets(A
andB)
is
the
maximum ofthe
degree
of
membership
in A
andthe
degree
ofmembership
in B:
V-AuB{x)
=max(\LA{x),iLB{x))
Note
that the
fuzzy
union operation stillholds
for
conventional sets.If
an objectx
is in
a conventional setA,
then \Ia(x)
=1.
Since
the
maximum value ofthe
function
u^Oc,)
for any
x\
is
one,
the
degree
ofmembership
ofxin
the
unionis
also
one,
indicating
that
xis in
the
union ofthe two
sets.If
the
object xis in
neither a member of set
A
norB,
\Ia(x)
=\Ib
(x)
=0;
the
maximumis
0,
indicating
that
xis
not a member ofthe
union.Intersection
The
intersection
oftwo
sets(A
andB)
is
conventionally defined
asthe
set of all xsuch
that
a:is
a member ofA
and xis
a member ofB:
AnB
=[x\{x
To
expandthis
definition
to
include
fuzzy
sets,
we will replacethe
"and"operation with
the
minimum valuefunction. Thus
the
degree
ofmembership
in
the
intersection
oftwo
sets(A
andB)
is
the
minimum ofthe
degree
ofmembership
in A
andthe
degree
ofmembership
in
B:
Again
notethat the
fuzzy
intersection
operationholds
for
conventional sets.If
an object xis
notin
a conventional setA,
then u^Oc)
=0.
Since
the
minimumvalue of
P/\(x,)
for
any
x\
is
zero,
the
degree
ofmembership
of xin
the
intersection
is
alsozero,
indicating
that
xis
notin
the
intersection
ofthe two
sets.
If
the
objectxis
a member ofboth
setsA
andB,
\Ia(x)
=\Ib
(x)
=1;
the
minimumis
1,
indicating
that
xis
a member ofthe
intersection.
Inverse
The
conventiondefinition
ofthe
inverse
of a set(A)
is
all x suchthat
xis
not amember of
A:
A
=[x\x
eA]
To
expandthis
definition
ofinverse
to
include
fuzzy
sets requires alittle
morethought.
We
willdefine
the
degree
ofmembership
of xin
the
inverse
ofA
to
represent
the
degree
to
which xis
not a member ofA.
If
an object xis
a member of afuzzy
setto
adegree
\Ia(x),
then,
logically,
the
degree
to
whichit is
not a memberis
the
upperlimit
ofthe
function
\Ia(x)
minus \Ia(x):M*)=1~M*)
This
alsoholds
for
conventional sets.If
an object xis
a member of a setA
then
\Ia(x)
=1. The
degree
ofmembership
in
the
inverse is
thus
1-1
=0,
that
xis
nota memberofthe
inverse.
If
an object xis
not a member ofA,
\ia(x)
=0;
1
-0 is
1,
indicating
that
xis
a member ofthe
inverse.
Fuzzy
numbers
Although
we can continueto
describe
objectsby
giving
the
degree
ofmembership
in
a particularfuzzy
set,
it is
often more convenientto
describe
the
object asbeing
equalto
something.We
will callthis
"something" afuzzyNUMBER:
anentity
that
encompassesboth
the
"name" ofthe
fuzzy
set andthe
degree
ofmembership
in
that
set.On
a more generallevel,
we candescribe
the
object as
being
equalto
a set offuzzy
numbers.For example,
the
objectjoe
couldbe described
by
the
following
statement:joe
={(young
=0.l),(middle
age=0.8),(old
=0.3)}
This
statementis
equivalentto:
V-mwtaSe(pe)
=0.8
(iflU(/oe)
=0.3
Decision
making
logic
In
orderfor
afuzzy
logic
systemto
make adecision,
several steps mustbe
taken.
Although
three
ofthese
steps are alsofound
in
conventionaldecision
making
systems:
the
determination
ofthe
system variablesthe
determination
ofthe
desired
level
of "quantization"the
determination
ofthe
rulebase
three
ofthe
steps are uniqueto
fuzzy
logic
systems:the
fuzzification
ofthe
systeminputs
the
evaluation ofthe
fuzzy
rulebase
the
defuzzification
ofthe
decisions
Determination
of
the
system variables
Like
a conventionaldecision making
system, the
fuzzy
system must gatherdata
and
determine
the
form
ofthe
outputbefore
adecision
canbe
made.To
do
this,
we mustfirst
determine
what elements ofthe
system mustbe
measured.To
controlthe
inverted
pendulum,
for
example:the
control system needsto
know
the
angular position and angularvelocity
of
the
pendulum.the
system wouldthen
usethis
information
to
determine how
muchtorque
(and
in
whatdirection)
shouldbe
appliedto
stabilizeit.
to
adjustthe
torque
output, the
system coulddetermine
the
amount ofIn
this
example,
position,
velocity
and current arelinguistic
VARIABLES: avariable aspect of
the
systemthat
does
not nothave
a number as avalue,
but
afuzzy
number,
or a setoffuzzy
numbers.Determination
of
the
quantization
level
Once
the
linguistic
variables arechosen,
we must choosethe
quantizationlevel
for
each one.In
a conventional controlsystem,
the
quantizationlevel is
oftenanalogous
to
the
binary
representation ofthe
inputs. We
mightchoose,
for
instance,
to
quantizethe
angular position ofthe
pendulumto
an eightbit
binary
value;
the
position wouldbe
readby
ananalog
sensor and convertedby
ananalog
to
digital
converter which would "round"the
analog
signalto
one of256
different
values.In
afuzzy
system,
determining
the
quantizationlevel
goesbeyond
just
determining
the
desired
binary
representation ofthe
input data.
In
additionto
quantizing
the
data
mathematically,
it
mustbe
quantizedlinguistically
as well.Recall
that the
input
variables arelinguistic
variables a set offuzzy
numbers orLINGUISTIC
terms.Each
ofthese terms
shoulddescribe
the
linguistic
variabledifferently,
while stillrelating
to
eachother; these terms
arethe
adjectivesin
a"fuzzy
sentence":the
positionis
small, the
velocity
is
fast.
By
quantizing
the
linguistic
variable,
we aredeciding
the
number ofdifferent linguistic
terms
(fuzzy
numbers)
to
useto
describe
it.
For example,
aninitial
attemptto
stabilizethe
inverted
pendulum might quantizethe
angular position ofthe
penduluminto
three
terms:
to the
left,
center,
andto the
right.Since
the
angle stillhas
adefinite
numericalvalue,
we might choose more generalterms:
negative, zero,
increasing
the
number oflinguistic
terms)
to
sevenlevels:
negativebig,
negativemedium,
negativesmall, zero,
positivesmall,
positivemedium,
and positivebig.
Is less
quantization
alwaysbetter?
When
determining
the
quantizationlevel,
the
designer
mustkeep
the
application
in
mind.Although
a controller with ninelinguistic
terms
mightbe
able
to
bring
the
pendulumto the target
anglevery
quickly
withnegligibleovershoot
from
any
startangle,
if
the
system requirements are much morerelaxed,
muchtime
andmoney
has been
wasted.For
example,
if
the
pendulum will neverstray
outside of90,
and atwo-degree
overshootis
acceptable, the
designer may only
needto
implement
a system withthree
linguistic
terms.
Not
only
willthis
savedevelopment time, but
the
resulting
control software willbe
able
to
be
run onless
sophisticated(and
thus
less
expensive)
hardware.
As
arule,
quantize much asis
allowedby
the
system specifications.It
is
very
easy
to
add rules andlinguistic
terms to
a simple systemto
correctfor
"unacceptable"behavior,
but it
may
be
much moredifficult
to
remove rules andterms
from
aDetermination
of
the
rule
base
Although
notdone
by
all controlsystems,
evaluating
a set of rulesis
a simpleway
to
control anobject;
rules are writtenfor
the
different
states ofthe
systemunder
control,
each ruleinstructing
the
controller onhow
to
respondto
a certainsituation.
In
ourfuzzy
logic
controller,
we will use a set ofif-then
type
rulesto
determine
the
system output.The
rules willfollow
the
conventionalif-then
format:
if
antecedentthen
consequenceThe
antecedentis
a conventionalboolean logic
expression,
using
the
"and," "or,"and "not" operations:
logical
valuei
op logical
valuei
op...Logical
values are comparisons ofthe
systeminputs
to the terms
ofthe
linguistic
variable.
For
the
moment,
forget
that the
value ofalinguistic
variableis
a set offuzzy
numbers.Instead,
for
this
discussion,
the
value of alinguistic
variableis
the
name of one ofits
terms.
For example,
the
value ofthe
linguistic
variableangle mentioned
previously
mightbe
zero.This
allows usto
isolate
the
states ofthe
system and generate rulesfor
each ofthe
statesindependently. To
signify
the
comparison,
we will usethe
"is"operator,
denoting
that the
value ofthe
input
on
the
left
sideis
equalto the
right side:The
consequence
ofthe
rulewillbe
an executableexpression,
using
the
operator"should
be."This
denotes
assignment,
assigning
the
value onthe
rightto the
output on
the
left:
current should
be
positive <=> current<-positiveThe
following
aretwo
possible rulesfor
the
inverted
pendulum controller:if
the
angleis
positivethen
the
current shouldbe
negativeif
the
angleis
zero andthe
speedis
negativethen
the
current shouldbe
positiveTo
list
the
rulesin
afuzzy
logic
controller,
the tabular
method(described
below)
is
often used.In
many
applications,
algorithms such asQuine-McKlusky
orEspresso
wouldbe
usedto
minimizethe
number of operations neededto
evaluate all
the rules;
however,
this
is
prohibitedby
the tabular
method.Although
the
number of rules neededmay
be far from
minimized,
listing
the
rules
in
this
form
allowsthe
individual
states ofthe
systemto
be
scrutinized moreindependently. This in
turn
will makethe
process ofadding
anddeleting
rules andlinguistic
terms to the
system simpler.In
additionto the
abovebenefit,
specifying
the
rulesusing
this
method provides adirect
and simpletranslation
to
programimplementation.
The
tabular
methodfor
listing
rulesinvolves
first representing
the
expression ofeach rule as a
"sum
ofminterms."
In
this
case, "sum
of minterms"is
usedto
mean a sequence of
logical
expressions combinedonly using
the
"or" operation.In
turn,
each ofthese
smallerlogical
expressionsonly
containindividual logical
values combined
using
the
"and"
individual
rules,
onefor
each "minterm."For
example,
the
rule(this
ruleis
notnecessarily
meaningful):if
the
angleis
positiveorthe
angleis
zeroandthe
speedis
negative orthe
speedis
positivethen
the
currentshouldbe
zerowould
be
broken down
into
the
following
six rules(note
that
duplicates
canbe
discarded):
if
the
angleis
positive andthe
speedis
positivethen
the
currentshouldbe
zeroif
the
angleis
positiveandthe
speedis
zerothen
the
current shouldbe
zeroif
the
angleis
positive andthe
speedis
negativethen
the
current shouldbe
zeroif
the
angleis
zero andthe
speedis
negativethen
the
current shouldbe
zeroif
the
awg/eis
zeroandthe
speedis
positivethen
the
current shouldbe
zeroif
the
angleis
negative andthe
speedis
positivethen
the
current shouldbe
zeroBy
looking
atthe
expandedlist
ofrules,
it is
easierto
seehow
listing
the
ruleslike
this
makesmodifying
the
rulebase
andimplementing
it
simpler.For
example,
if
experimentation showedthat the
first
minterm(the first
rulein
the
expanded
set)
shouldbe
deleted,
the
designer
wouldhave
to
find
alllogical
terms
original rule would
have
to
be
modified.Also,
the
form
ofthe
expanded rulelisting
is regular;
the
rules canbe
storedin
a simpletwo
dimensional
array.Instead
oflisting
all ofthe
rulesin
"longhand"like
above,
we willlist
them
in
an n-dimensional
table,
with n equalto the
number ofinput
linguistic
variables.The
sizeofthe
array
is:
mi
xmi
x ...xmn
with
m,-equal
to the
number oflinguistic
terms
oflinguistic
variablei. For
the
inverted
pendulumexample,
withtwo
inputs,
andthree
linguistic
terms,
the
rules would
be listed
in
a3
x3
array.The
rows ofthe table
will representthe
angle,
andthe
columns will representthe
speed.The
value of each cell willbe
the
valuethat
the
current shouldtake
if
that
rulefires. Figure
2
showshow
the
expanded
list
of rules wouldbe listed:
Speed
Ang
Figure
2a ruletable
withtwo
linguistic variables,
each with threelinguistic terms
Neg
Zero
Pos
Neg
Zero
Pos
Zero
Zero
Zero
Neg
Zero
Pos
Neg
Zero
Pos
Pos
Pos
Pos
Pos
Zero
Neg
Neg
Neg
Neg
A
more meaningful set ofrulesfor
the
inverted
pendulum controller wouldbe
as
follows:
Speed
Ang
Figure
3
rulesfor
anInverted
pendulum controllerusing
two
linguistic variables,
each withthree terms
Once
the
rules aredefined,
we can returnto the
fact
that
the
value of alinguistic
variable
is
a set offuzzy
numbers.This
meansthat
whenthe
rules areevaluated,
multiple rules
may
fire,
anddifferent
rulesmay fire
to
different
degrees.
Our
decision making logic
will needto
know
whatto
do
in
these
cases.This
willbe
covered
later.
Fuzzification
of
the
system
inputs
Probably
the
mostimportant
part ofthe
fuzzy
logic
controlleris
the
fuzzification
of
the
input
values.It
is in
this
step
that
wedetermine
the
values ofthe
linguistic
variablesby
converting
the
numerical value ofthe
input
to
a set offuzzy
numbers.Consider
againthe
linguistic
variableangle,
withthree
linguistic
terms:
negative,
zero,
and positive.Common
sense comesin
to
play
now,
for
wemustteach the
computer what we mean when we
say something
is
negative, zero,
orpositive;
wemust
determine
the
functions
\inegative(x),
IWo(*)/
and \ipositive(x).Before
defining
zero,
we needto
determine
what zero will meanto
the
controlpendulum
still; the
controller willbe
trying
to
make small correctionsin
orderto
keep
the
pendulumstable,
notto
try
to
bring
the
pendulumto the target
angle.Next,
we mustdetermine
what we meanby
zero;
clearly,
the
value0.0
is
definitely
amember ofzero(u^^O)
=1.0).
Likewise,
> could notbe
farther from
zero
(u^oC+oo)
=o.O).
Next,
we must now considerthe
valuesin between.
By
definition,
pzero(x)
represents
the
degree
to
whichthe
valuexis
zero,
andthat
values closerto
zeroshould
have
ahigher degree
of membership.Thus,
the
closerthe
value xis
to
0.0,
the
greaterthe
value of \izero(x).Figure
4
represents afirst
attempt atdefining
zero.
1
N
-oo 0 +
angular position of pendulum
We
must now considerthe
application of zeroto the
system.Values
notin
the
universe of
discourse
shouldbe
excluded;
sincethe
domain
ofthe
angularposition of
the
pendulumis
-180 < x <+180,
zero canbe
redefinedto
excludevalues not
in
the
domain (figure
5);
however,
the
definition is
still not practical.1
3>
0 +180
angular position of pendulum
Figure
5Definition
of zero correctedfor the domain
of the angular position of thependulum
Remember
that these
fuzzy
definitions
arethe
basis
on whichthe
controldecisions
willbe
made.Although,
is
more zerothan
-175,do
wereally
wantthe
systemto
behave
differently
whenthe
pendulumis
at either ofthese two
positions?
In
both
cases,
it is
very
far from
the
destination
angle,
andthe
systemshouldn'tneed
to
worry
if
the
pendulumis
closeto the target
angle yet.We
needto
modify
the
definition
of zeroto
exclude anglesthat
"do
notapply."To
do this,
we will use
the
notion ofmembership
in
afuzzy
set as apossibility
distribution.
By
asking
the
question"Could
the angle,
within reasonableuncertainty,
be
0?,"we can
decide
whatangles shouldbe
excludedfrom
adiscussion
of zero.The
following
chart(figure
6)
shows a much more suitabledefinition
ofzerofor
a-45 0 +45
angular position of pendulum
Figure
6asuitabledefinition
ofthe linguistic
termzeroBy
setting
the
cutoff angleto
45,
we areinstructing
the
systemto
starttrying
to
stabilize
the
pendulum whenthe
angleis
withinthis
range.Outside
this range,
other
terms
willbe
trying
to
movethe
pendulumquickly
to
the target
angle.If
the
linguistic
variable wasless
quantized(more
linguistic
terms),
the
cutoffangle (45
in
the
chartabove)
might needto
be
smallerbecause
the
angleis
being
defined
morefinely;
each of ourdefinitions
(zero,
positive,
negative,
...)is
more specific.
Using
the
samemethod,
negative and positive canbe defined.
The
following
chart(figure
7)
showsthe three
linguistic
terms
overlaid:1
negative
y zeroy
positive+45
angular position of pendulum
Figure
7the three linguistic
terms:negative, zero,
and positiveNotice
that
the
three terms
overlap.Although
the
definition
of alinguistic
variable
does
not requirethat the terms overlap,
it
is very
important
to
smoothoperation of
the
fuzzy
system.Consider
eachterm
as aseparatecase,
withrule
contributing
to the
output ofthe
system at onetime.
As
the
pendulumrotated,
sharp
transitions
could occur asthe
angle movesfrom
one caseto
another.
In
actuality,
the
systemdoes
nothave
separatecases;
atany
onetime,
multiple cases
apply
to
different
degrees,
requiring
usto
design
the
systemto
handle
the
naturally occurring
overlap
in
the
states ofthe
system.Consider
the
fuzzy
set oldagain,
and a related setyoung.As
someoneages,
they
become
moreold,
andless
young.At
any
onetime,
wedo
not consider someoneexclusively
either old oryoung,
but
a combinationofboth. It is
naturalthat
they
overlap.
Curve
shape and artAlthough
piecewise-linear curves were usedin
the
previousexamples,
othercurve shapes might
be
more appropriatefor
other situations.For
example,
zerocould
be defined
by
using
sine and cosine segments(figure
8):
1
N
-45 0 +45
angular position of pendulum
Figure
8an alternatedefinition
of zerousing
sine and cosine segmentsAlthough
curve shape and cutoff points effect systembehavior,
there
is
no"science"
in
choosing them;
if
anything,
it is
an artform.
Often,
oncethe
basic
curve shape
is
chosen, the
designer
must usetrial
and errorto
find
the
"perfect"cutoff points and curve shape.
In
othersituations,
it
may be
naturalto
choose aanalyze a curve shape and somewhat
determine how
the
shape will affectthe
system,
it
is
very difficult
to
determine
if
one shapeis
"better"than
another.Again,
there
may
notbe
"perfect"cutoff
points;
afterexperimentation,
wemay
find
that
a cutoffpointfor
zero anywherebetween
40and 50 provides acceptable
performance.
Evaluation
of
the
fuzzy
rule
base
Once
the
systemhas been
set-up,
by defining
the
rules andlinguistic terms,
it
canbegin
processing
the
input. As in
conventional rule-basedsystem, the
controllerconverts
the
systeminputs into
the
form
usedby
the
rulebase.
Next,
it
evaluatesthe
antecedent of each ruleto
determine
which rule(or
rules)
willfire.
It
then
executes
the
consequence of each rulethat
does fire. A
fuzzy
logic
controller stillfollows
this
basic
premise.Evaluating
the
logical
terms
Once
the
system readsthe
inputs
ofthe
system,
it
mustfirst
convertthem
into
aform
that
canbe input
to the
rulebase
for
evaluation.In
ourfuzzy
rulebase,
wehave
written rulesthat take the terms
ofthe
linguistic
variables asinputs.
Although
it
was notexplicitly
stated,
when we wrote"...the
angleis
zero..."
in
arule,
we wereinstructing
the the
rule evaluatorto
determine
the
degree
ofmembership
ofthe
angle ofthe
pendulumin
the
fuzzy
setzeroto fuzzify the
input. This
is done
by
simply evaluating
the
function
u^pCc)
atthe
currentpendulum angle.
Once
eachlinguistic
term
in
the
antecedenthas been
fuzzified,
the
controllervalue
represents
the
weight ofthe
rule(to
whatdegree
webelieve
that this
ruleshould
be
executed).To
moreclearly
showthe
evaluationprocess,
considerthe
following
two rules,
whenthe
angle ofthe
pendulumis
10 andthe
speedis
20%:
if
the
angleis
zero andthe
speedis
positivethen
the
current shouldbe
negativeif
the
angleis
zero andthe
speedis
zerothen
the
current shouldbe
zeroThe
current state ofthe
pendulumin
comparisonto the
antecedent ofthe
rulesis
shownby
the
following
figure (figure
9):
+45'
07s +1807s
angle speed
zero
A
zeroA
0.84U-
h
V
-4-v
V
6.78
-45 0 +45
-1807s 0 +1807s
angle speed
Figure
9fuzzification
of the angle and speedfor the two
rulesEvaluation
ofthe
antecedentOnce
fuzzified,
the
rule evaluator must combinethe
inputs
to
the
ruleusing
operations
are analogousto the
conventional set operations(union,
intersection,
and
inverse),
fuzzy
logic
operations are analogousto the
fuzzy
set operations.The
following
table
(figure
10)
showsthe
boolean
operations andtheir
fuzzy
logic
equivalents:Bool.
Set
Fuzzy
OR
AND
union [.... i^^rfffhpnftfiniintersection
minNOT
inverse
max1-val
A
aB
=max(us(a),u.s(&))
AwB
=min(\is(a),\is(b))
rw mrvvwwwwvyvwvwvvwmn -A=
l-\is(a)
Figure
10Summary
offuzzy
logic
operations andtherelationship
between logic
andfuzzy
settheory
Using
these
definitions
of "or," "and," and "not,"the
weights(value
ofthe
antecedent)
ofthe
two
sample rules are0.16
(the
minimum of0.78
and0.16)
and0.78
(the
minimum of0.78
and0.84),
respectively.Defuzzification
of
the
decisions
After
the
evaluation ofthe
antecedents,
we areleft
with a set of outputlinguistic
terms
andcorresponding
weights(the
current shouldbe
negative with weight0.16
and zero with weight
0.78),
eachcorresponding
to
particular rule.These
weightsand
terms
must nowbe
combinedto
produce a single valueto
outputfrom
the
system.
Although
(like
the
determination
of curve shape and cutoffvalues) the
combination of
the
weights andterms
is
anart,
several established methodsexist.
Two
common methodsfor defuzzification
arethe
Max-Product
andthe
Max-Dot
methods.Another
method,
developed specifically
for
this
thesis
is
the
Nominal
Average
method.Max-Product
In
the
Max-Product defuzzification
method,
the
outputlinguistic
terms
aremaximum of
the
clippedterms
atany
point.By
then
finding
the
centroid(center
of
gravity)
ofthe
resulting
curve,
we can calculatethe
desired
output value.Each
rulei
has
aweightW{
and acorresponding
outputlinguistic
term
T{.
The
resulting
outputmembership
function for
rulei
(R{)
is:
\iRi{x)
=max(wi,\iTi{x))
These
output curves arethen
overlaidto
construct a single output curve.The
value of
the
combined curve at xis
the
maximum ofthe
values ofthe
individual
clippedfunctions
at x:h-M
=maxUjJjM
The
centroidis
determined
by finding
the
value x suchthat
half
ofthe
weight ofthe
overlaidfunctions
is
on each side of x:J*
V-out{v)dv=
j'"
The
following
figure (figure 11)
showshow
the
Max-Product
method wouldbe
used
to
defuzzify
the two
rules given previously:negative
+45'
angle
07s +1807s -1A 0A
speed current
+45
-1807s 0 +1807S -1A
angle speed
0A +1A
current
resulting
curvecentroid=output current
Figure
11Max-Product
method offuzzification. The
antecedent output setsthe
maximumMax-Dot
One
apparent problem withthe
Max-Product
methodis
that
most ofthe
detail
found
in
the
outputlinguistic
terms
is
lost
whenthe
clipping
occurs.To
fix
this
problem, the
Max-Dot
method callsfor
the
outputterms to
be
scaledinstead
ofclipped.
The
disadvantage
is
that
Max-Dot
requiresmultiplication,
which canbe
time
consuming
on small microcontrollers.The
membership
function for
the
fuzzy
setR,-for Max-Dot
is
givenby
the
equation:Aside
from
this
modification,
the
Max-Dot
methodis
identical
to the
The
following
illustration (figure
12)
showshow
the
Max-Dot
method wouldbe
used
to
defuzzify
the
two
rules given previously:negative
+45
angle
07s +1807S -1A 0A
speed current
0 +45
-1807s 0
+1807s -1A 0A +1A
angle speed current
resulting
curvecentroid=output current
Figure
12Max-Dot
method offuzzification.
The
antecedent output setsthe
scale ofthe
output
linguistic
term.The
resulting
curves are thenoverlaid,
the centroid of the resultNominal
Average
One
majordisadvantage
that
both
Max-Product
andMax-Dot
requireis
the
needfor
the
calculation ofthe
centroid,
which requirestwo
integrals.
If
the
systeminputs
arediscrete
values,
such as eight-bitbinary
values convertedby
ananalog
to
digital
converter,
the
integrals
canbe
reducedto
simplesummations;
however,
in
a continuous-valuedsystem,
the
actualintegrals
(or
approximations)
needto
be
calculated.This
is further
calculatedby
the
addition of non-piecewise-linearmembership
functions;
the
calculation ofthe
approximation must
broken down into
many
more sectionsfor
the
resultto
be
accurate.
To
solvethis
problem,
a methodis
neededthat
reducesthe
outputlinguistic
terms to
asingle,
non-fuzzy
valuethe
nominal value.Let
nR
be
the
nominal value of outputlinguistic
term
R;
it is
the
value ofthe
system variable with
the
greatestdegree
ofmembership
in
the
R. The
term
"nominal"comes
from
the
use of namesfor
the
linguistic
terms;
the
nominal valueis
the
valuefor
whichthe
set was named.For example,
the
nominal value ofthe
linguistic
term
zerois
0.0. For
terms that
do
nothave
a single value withthe
highest
degree
ofmembership (such
as positive andnegative),
the
nominal value ofthe
linguistic
term
is
the
value at whichthe
derivative
ofthe
membership
function
changes,
andthe
degree
ofmembership
is
a global maximum.For
some continuousfunctions,
the
nominal value canbe
moresimply
defined
by
the
location
of a unique global maximum:((max(uT)
=uT(x))
a[x'
*
x|ur(x)
>For
the
linguistic
terms
positiveandnegativedefined previously for
the
linguistic
variable
angle, the
nominalvalues wouldbe
+45and respectively.
Note
that this
definition may
nothold
for
allmembership
functions;
this
definitions
assumesthat
the
function
is
not continuous.Functions
using
sinusoids,
for
example(see figure
8),
may be
continuousdespite
the
plateaus afterthe
cutoffpoints; there
is
noinstantaneous
changein
the
derivative. For
casessuch as
this,
the
nominal valueis
the
location
of a global maximum withdifferent
neighboring
values:(pT(x)
=max(uT))A((uT(x
+e)
*\iT(x))
v(pT(x
-e)
*ur(x))),
e>0
The
rules arethen
combined andthe
result convertedto
real world valuesby
computing
the
weighted average ofthe
nominalvalues,
whereW{
is
the
weightof rule
T{
with nominal value nj?,-:7, rules
uout
~!s
rules
The
advantages ofthis
method are clearfor
continuous value systems.The
nominal value of each
linguistic
term
canbe
calculated ahead oftime.
This
leaves only
the
weighted averageto
be
calculated eachiteration
ofthe
controller.Although
this
method requires several multiplications and adivision,
the
time
required
to
calculatethe
average willmostlikely
be dwarfed
by
the
time
to
calculate
the
values ofthe
antecedentsthe
rules,
which couldconceivably
requirefloating
pointtrigonometric
or exponential operations.The
Nominal
Average
methodis
not withoutits
problems.It
cannot,
for
such as not
zero, the
inverse
ofthe
linguistic
term
zero.In
addition,
alldetail in
the
membership
function is
lost.
Other
methods
Just
asthere
is
no "right" shapefor
amembership
curve,
there
is
no right choicefor
the
defuzzification
method.Often,
the
choiceis
made whenthe
hardware for
the
systemis
chosen;
many
methodsmay be simply
too
difficult
to
implement
orcannot
be
performedquickly
enough on a particular system.In
otherinstances,
the
designer may
wishto
modify
an aspect of a methodto take
advantage ofthe
behavior
ofthe
device
under control.How
can we allow art?
With
allthis
uncertainty
in
the system,
how
can webe
surethat the
system willbe
tolerant
of externalvariables,
such asgravity
and motortorque?
The
answerto this
lies
in
the
systemdevelopment
process.Recall
the things
consideredwhen
developing
the
inverted
pendulum control system.When
we constructedthe
rulebase,
the
only
thing
considered wasthe
direction
that
we should pushthe
pendulumfor
a particular angular position and velocity.When
developing
the
membership
functions,
the
actualinput
value wasthe
only
item
discussed.
Nowhere in
the
development
ofthe
systemdid
we considergravity
or motortorque.
Of
course at some point we must considerthese things.
For example,
whenchoosing
a motor and maximum currentoutput,
we mustbe
surethat the
motorwill
be
ableto
overpowergravity (at
least
at critical points).We
must alsobe
sureEven
here,
though,
gravity
and motortorque
areonly
being
examinedin
generalterms.
The
systemdoes
notrely
on a particular value of either ofthese
things,
To
demonstrate
the
principles offuzzy
logic,
Pendulum,
afuzzy
logic
inverted
pendulum
simulator,
wasdeveloped.
Pendulum
allowsthe
userto
experimentwith
fuzzy
logic
principlesby
setting up
the
rules andmembership
functions
used
to
controlthe
inverted
pendulum.The
user canthen
runthe
simulator(either
in
single-step
orfree-running
mode)
and seehow
the
systembehaves
by
watching strip
charts,
a graphicaldisplay
ofthe pendulum,
andthe
numericalvalues of
important
aspectsofthe
system.Pendulum
physics
The
pendulum willbe
simulated on astep
by
step
basis.
Each
iteration
ofthe
simulator,
a new value of angular position(e)
and angularvelocity
(to)
willbe
calculated.
Using
these values, the
simulator will usefuzzy
logic
to
determine
the
amount of currentto
supply
to the
motor.The
simulator willthen
usethis
new value of current
to
determine
the
newtorque
output ofthe motor,
and newangular position and
velocity
ofthe
pendulum afinite
(user
definable)
time
later.
During
this
time,
the torque
due
to
gravity
is
assumedto
be
constant.Because
ofthis,
the
newstatus ofthe
pendulumis
only
anapproximation,
although
the
difference between
the
approximation andthe
actual valueis
negligible
assuming
the
changein
angleis
small.This
willbe
examined moreIn
orderto
simulate an actualinverted
pendulum,
it
was analyzedto
determine
how both
nature andthe
motor affectits
speed and position.The
following
illustration
showsthe
forces affecting
the
pendulum(figure
13):
Figure
13Free
body
diagram
ofthe
inverted
pendulumTwo
torques
affectthe
pendulum:that
due
to gravity,
andthat
suppliedby
the
motor.
First,
considerthe
simpler ofthe two: the
torque
suppliedby
the
motor.The
motorbeing
simulatedis
poweredby
a variable current source with user