Create a Fuzzy Inference System Using Commands in M-file (t&p ": In Matlab )ain consol& *in%o*+ s&l&ct ,Fil& N&*M Fil&-. Th& M Fil& • E%itor *in%o* is pop/up. (t&p $: Typ& Typ& th& 0ollo*ing co%& into your M Fil& E%itor an% sa1& it as M".)at. • Notic& that th& sa)& co%& can b& obtain&% by (&l&ct ,Fil&#p&n2 MFil&".)at- in M Fil& E%itor Win%o*. a n&*0is450is".0is567 8cr&at& a n&* FI( 0il& in 9*ork9 0ol%&r 8a%% an% input 1ariabl& 5'5 into th& FI( a a%%1ar4a+ 5input5+ 5'5+ $ ;<67 8r&)o1& th& 3 MFs cr&at&% by %&0ault *h&n *& a%% an input 1ariabl& a r))04a+ 5input5+ "+ 5)0"5+ "67 a r))04a+ 5input5+ "+ 5)0$5+ "67 a r))04a+ 5input5+ "+ 5)035+ "67 8a%% $ MFs into th& 1ariabl& ' a a%%)04a+ 5input5+ "+ 5="5+ 5tri)05+ $ > ?<67 a a%%)04a+ 5input5+ "+ 5=$5+ 5tri)05+ 3 @ ;<67 8a%% an% input 1ariabl& 5'5 into th& FI( a a%%1ar4a+ 5input5+ 5y5+ A ""<67 8r&)o1& th& 3 MFs cr&at&% by %&0ault *h&n *& a%% an input 1ariabl& a r))04a+ 5input5+ $+ 5)0"5+ "67 a r))04a+ 5input5+ $+ 5)0$5+ "67 a r))04a+ 5input5+ $+ 5)035+ "67 8a%% $ MFs into th& 1ariabl& y a a%%)04a+ 5input5+ $+ 5B"5+ 5tri)05+ > ? ""<67 a a%%)04a+ 5input5+ $+ 5B$5+ 5tri)05+ A "<67 8a%% an% output 1ariabl& 5y5 into th& FI( a a%%1ar4a+ 5output5+ 5z5+ " ;<67 8r&)o1& th& 3 MFs cr&at&% by %&0ault *h&n *& a%% an output 1ariabl& a r))04a+ 5output5+ "+ 5)0"5+ "67 a r))04a+ 5output5+ "+ 5)0$5+ "67 a r))04a+ 5output5+ "+ 5)035+ "67 8a%% $ MFs into th& 1ariabl& ' a a%%)04a+ 5output5+ "+ 5C"5+ 5tri)05+ " A <67 a a%%)04a+ 5output5+ "+ 5C$5+ 5tri)05+ 3 @ ;<67 8" rul& is %&0in&% an% a%%&% into FI( rul& " " " " "<7 a a%%rul&4a+ rul&67 8Th& "st 5"5 is )&an that th& "st MF o0 "st input 1ariabl& *ill b& us& in this rul&+ in this cas&+ =" *ill b& us& 8Dou 8Dou can put 5$5 i0 you *ant to us& $n% MF o0 "st input 1ariabl&+ us& 55 i0 you %o not *is& th& rul& in1ol1& *ith "st input 1ariabl& 8Th& $n% 5"5 is )&an that th& "st MF o0 $n% input 1ariabl& *ill b& us& in this rul&+ in this cas&+ B" *ill b& us& 8Dou 8Dou can put 5$5 i0 you *ant to us& $n% MF o0 "st input 1ariabl&+ us& 55 i0 you %o not *is& th& rul& in1ol1& *ith $n% input 1ariabl& 8Th& 3r% 5"5 is )&an that th& "st MF o0 output 1ariabl& *ill b& us& in this rul&+ in this cas&+ C" *ill b& us& 8Dou 8Dou can put 5$5 i0 you *ant to us& $n% MF o0 output 1ariabl& 8Th& Ath 5"5 is )&an that this rul& is cr&at& an% Enabl&+ us& 55 to to cr&at& th& rul& but isabl& it. 8Th& >th 5"5 is )&an that th& r&lationship b&t*&&n MF o0 "st input 1ariabl& an% MF $n% input 1ariabl& is 9=N9 8Us& 5$5 is you *ant it to b& 9#9 8Conclusion+ this *ill a%% a 0ul&+ i0 ' is =" an% y is B" Th&n z is C"
Mo%ul& 3: Matlab Fuzzy Logic Toolbo' ! (i)ulink *rit&0is4a+ 50is".0is567 %isp45= n&* FI( is cr&at&% an% sa1& as H*orkH0is".0is567 %isp45Typ& %isp45Typ& 9Fuzzy 0is".0is9 in c onsol& *in%o* to s&& th& n&* FI( cr&at&%567 %isp45En% o0 th& progra) )0il&".)567
To View the FIS created This can b& %on& by Typ& ,Fuzzy 0is"- 4th& .0is in b&hin% can b& ignor&6. • Th& FI( E%itor *ill b& sho*n as in Figur& " b&lo*. •
Figur& " •
•
•
Dou Dou can chang& th& s&tting o0 th& FI( h&r&+ such as chang& th& &0uzzi0ication to M#M rath&r using C#= 4(&& Figur& "6. oubl& Click on th& part sho* th& MFs o0 ' in or%&r to s&& 4an% chang&6 th& %&tail in0or)ation o0 MFs o0 input 'J cr&at&% cr&at&% in th& co%& as sho*n in Figur& $. (a)& st&ps can b& %on& to 0or 1ariabl&s y an% z.
(&l&ct ,Ki&*(ur0ac&- to s&& th& %&cision sur0ac& bas& on th& rul&4s6 cr&at&%. Th& (ur0ac& Ki&*&r is sho*n in Figur& A b&lo*.
Figur& A •
(&l&ct ,Ki&*ul&s- to s&& ho* to in0&r&nc& syst&) *ork in or%&r to pro%uct an% output bas&% on th& inputs gi1&n. W& can us& to )ous& to %rag an% plac& th& r&% lin&s in or%&r to chang& th& inputs an% to s&& th& n&* output as *&ll. (&& Figur& > 0or %&tail
=s a conclusion+ to cr&at& a n&* FI( 1ia co))an% is slo*. Th& FI( E%it actually can b& us& to cr&at& or )o%i0y FI( in 1&ry short ti)& co)par& to co))an% co%ing )&tho%.
•
Exercise: Mo%i0y th& co%& in MFil&".) abo1& so that it can tak& thr&& rul&s as b&lo*. ": I0 ' is =" an% y is B" th&n z is C" $: I0 ' is =$ an% y is B$ th&n z is C$ 3: I0 ' is =" or y is B$ th&n z is C$ • Solution : Mo%i0y only on& lin& in to co%& rul& " " " " "7 $ $ $ " "7 " $ $ " $<7 •
Dou can us& FI( &%itor to ch&ck your ans*&r+ notic& that th& sur0ac& 1i&*&r *ill not b& th& sa)& as b&0or& sinc& rul&s ar& a%%&%. =noth&r *ay to s&& th& r&sult is typing co))an% in consol& *in%o*s. F r&a%0is40is".0isJ6 8r&ss &nt&r k&y 8in0or)ation o0 th& FI( *ill b& sho*. (ho*rul&4F67 8th& rul& o0 this FI( *ill b& sho*. Create common FIS use for Control Systems Using FIS Editor • (t&p ": Typ& ,Fuzzy- in th& Matlab consol& *in%o*. Th& FI( &%it *ill b& sho*. • (t&p $: (&l&ct E%it =%% Kariabl&Input- to a%% th& s&con% input 1ariabl&. • (t&p 3: ighlight on input"+ chang& th& na)& o0 input" to EJ 4&rror6+ as sho*n in pictur& b&lo*. Th& r&st o0 in0or)ation is no chang&. (&& Figur& @ 0or %&tail
(t&p A: &p&at st&p 3 0or input$ b&co)& E 4chang& o0 &rror6 an% th& output b&co)& U 4control signal6. • (t&p >: oubl& click on th& pictur& o0 MFs 0or 1ariabl& E+ as sho*n in ar&a in Figur& @+ in or%&r to sho*n th& MFs o0 1ariabl& E. By %&0ault *h&n a 1ariabl& is a%%&%+ 3 MFs *ill b& auto)atically. (&& Figur& . • (t&p @: It *ill b& &asy 0or us to %&l&t& all th& %&0ault MFs+ this can b& %on& by s&l&ct ,E%it&)o1& =ll MFs- as sho*n in Figur& . =0t&r this+ no )or& MFs 0or input 1ariabl& E. •
Figur& •
(t&p : No* *& plan to a%% MFs to input 1ariabl& E+ this can b& %on& by s&l&ct ,E%it=%% MFs2-. =0t&r s&l&ct this+ anoth&r %ialog bo' is pop up as sho*n in Figur& ?. (&l&ct Typ& MFs as gaussmf an% nu)b&r o0 MFs is . (&& Figur& ? 0or %&tail.
(t&p ;: ighlight th& )0" as sho*n in Figur& ;. Chang& th& na)& o0 )0" to NB as sho*n in ar&a O • (t&p ": &p&at (t&p ; 0or )0$ to )0+ to chang& th&ir na)&s b&co)& NM+ N(+ P+ (+ M an% B. • (t&p "": Chang& th& rang& o0 th& 1ariabl& to /" "< as sho*n in ar&a D. • (t&p "$: &p&at (t&p > to (t&p "" but 0or input 1ariabl& E. • (t&p "3: &p&at (t&p > to (t&p "$ but 0or output 1ariabl& U. • (t&p "A: (&l&ct ,E%itul&-+ th& rul& &%itor *in%o*s is sho*n as Figur& ". •
Figur& " Figur& " (t&p ">: =%% th& "st rul& into rul& &%itor bas& on *hat *& ha1& l&arn in Mo%ul& 3. E.g th& "st rul& is: I0 E is NB an% E is NB th&n U is NB n% th • (t&p "@: &p&at (t&p "@ to cr&at& $ until A; rul&s. • (t&p ": No* *& can s&l&ct ,Ki&*(ur0ac&s- to s&& th& %&cision sur0ac& o0 this g&n&ral 0uzzy logic control+ or s&l&ct ,Ki&*ul&s- to s&& th& in0&r&nc& proc&ss an% th& output *h&n inputs ar& gi1&n. • (t&p "?: (&l&ct ,Fil&E'portisk2- to sa1& th& FI( cr&at&% into %isk. o typ& a 0il& na)& *h&n you ar& b&ing as to %o so. (&& Figur& "" 0or %&tail. •
Mo%ul& 3: Matlab Fuzzy Logic Toolbo' ! (i)ulink QQ &1al0is4.$ .;<+ 06 8co))an% that you typ&+ )&aning i0 E .$ an% E .;+ *hat is UR
ans
8ans*&r calculat&% by Matlab+ U .>3
.>3
! Fuzzy "ogic Controller for #ater $ath Tem%erature Control robl&) stat&)&nt: In this %&)onstration+ *& shall %&sign a 0uzzy logic controll&r 0or th& t&)p&ratur& control o0 a *at&r bath. Th& plant to b& controll&% is %&scrib&% by: y 4k + "6
=
b 4T 6u 4k 6
a 4T 6 y 4k 6 +
Wh&r& a 4T 6
=
+ 4" − a 4T 66Y " + &'p4.> y 4k 6 − γ 6 β 4" − &'p4 −α T 66 &'p4−α T 6 an% b4T 6 = . Th& para)&t&rs o0 th& plant
α o ar& s&t as α = "x" A + β ?.C x" + γ = A an% Y = $> C . Th& plant input u4k6 is li)it&% to b&t*&&n an% > 1olts. Th& sa)pling p&rio%+ T+ is s&t as $> s&con%s. Th& goal is to %&sign a 0uzzy controll&r *hat *ill control th& *at&r t&)p&ratur& to 0ollo* a r&0&r&nc& pro0il& as clos&ly as possibl&. This r&0&r&nc& pro0il& is 3> o C 0or ≤ t ≤ A )inut&s+ > o C 0or A ≤ t ≤ ? )inut&s+ @> o C 0or ? ≤ t ≤ "$ )inut&s an% ? o C 0or "$ ≤ t ≤ "? )inut&s. −
3
−
=
Th& input 1ariabl&s 0or this controll&r ar& chos&n as &4k6+ %&4k6 *h&r& &4k6 is th& p&r0or)anc& &rror in%icating th& &rror b&t*&&n th& %&sir& output an% th& actually output. Th& %&4k6 is th& chang& o0 th& &rror. Th& output o0 th& controll&r is th& 1oltag& that li)it&% to b&t*&&n to > 1olts. Th& sourc& co%& is sho*n as b&lo*+ *h&r& *& us& th& FI( 40is$.0is6 %&sign&% in pr&1ious s&ction in this application. Notic& that th& sa)& sourc& co%& can b& 0oun% in H*orkH)0il&$.) 8 8 Fil&na)& : )0il&$ 8 cl&ar7 8cl&ar th& )&)ory o0 )atlab &cho on7 8to sho* r&sult o0 &1&ry co))an% clc78to cl&ar th& )atlab consol& scr&&n
to b& controll&% ar& %&scrib&% in Mo%ul& 3. Th& goal is to %&sign a 0uzzy controll&r that *ill control th& *at&r t&)p&ratur& to 0ollo* a r&0&r&nc& pro0il& as clos& as possibl&.
8 8 Notic& that th& FI( us&% is %&sgin&% using FI( &%itor. 8 8 8 8
T&st progra)
paus& 8 it any k&y to b&gin this progra). 8 &a% th& FI( 0il& . 0 r&a%0is450is$.0is567 paus& 8 it any k&y to %&0in& th& plant para)&t&rs. T $>7 p ""4/A67 S ?."4/367 r A.7 yo $>7 y4"6 yo7 a &'p4/pT67 b4SVp64"/&'p4/pT667 paus& 8 it any k&y to %&0in& th& r&0&r&nc& output. 0or k ":"? i0 4k A6 r&04k6 3>7 &ls&i0 4k Q A ! k ?6 r&04k6 >7 &ls&i0 4k Q ? ! k "$6 r&04k6 @>7 &ls&i0 4k Q "$6 r&04k6 ?7 &n%7 &n%7 paus& 8 it any k&y to %&0in& th& gain constanT. XE "V">7 XE "V">7 XU ?7 paus& 8 it any k&y to t&st this 0uzzy controll&r. 0or k ":"; &4k64r&04k6/y4k667 8&rror &04k6&4k6XE7 8scal&% o0 &rror i0 k " %&4k6 7 8chang& o0 &rror &ls&
Figur& "$ #ater "e&el Control in a Surge Tan' Using Fuzzy "ogic Controller In this s&ction *& us& a *at&r l&1&l probl&) 0or a surg& tank to sho* ho* to th& 0uzzy logic controll&r *ork &1&n though th& r&0&r&nc& point is k&&p changing 0ast all th& ti)&. Th& %iscr&t& ti)& &Suation o0 a surg& tank *& us& is: h4k + "6
=
h4 k 6 + T :
−
";.@h4 k 6 $
h 4 k 6 + "
+
u 4k 6 $
h 4 k 6 + "
< *h&r& T is th& sa)pling rat& that *& s&t as
.> s&con%. o*&1&r+ *& ha1& oth&r r&strictions on th& plant %yna)ic. In particular+ *& assu)& th& plant input+ u4k6 saturat&s as Y> an% />. This )&an u4k6 *ill b& li)it&% in b&t*&&n /> to Y>. =lso to &nsur& that th& liSui% l&1&l n&1&r go&s n &gati1& 4*hich is physically i)possibl&6+ *& si)ulat& our plant using:
For this application *& try to t&st th& ability o0 0uzzy logic controll&r on a 0ast r&spons& plant+ th&r&0or& th& %&sir& output is also chang& *ith ti)& such as: r 4 k 6
=
cos4.C k 6 + sin4.>k 6 + $.C
Th& input an% output 1ariabl&s ar& &4k6+ %&4k6 an% %u4k6.&r& th& u4k6 can b& obtain bas& on th& &Suation: u4k6 u4k/"6 Y %u4k6. Th& co%& is gi1&n as b&lo*. Notic& that th& sa)& co%& can b& 0oun% in )Fil&3.). 8r&a% FI( 0ro) 0il& 0 r&a%0is450is$.0is567 80 r&a%0is45)0is".0is567 8%&0in& th& plant para)&t&rs T .>7 h 3.>7 p "7 S $7 8%&0in& th& gain or scaling 0actor 0or all 1ariabl&s XE .37 XE "7 XU "7 8nu)b&r o0 int&r1al in%&' @7 8initial th& l&1&l o0 *at&r to h h4"6 h7 0or k " : 4in%&'/"6 r&04k6 4cos4.k66 Y 4sin4.>k66 Y $.7 &4k6 r&04k6/h4k67 8th& &rror us& 0or FI( )ust b& scal&%V0uzzi0y &04k6 &4k6XE7 i0 k " %&4k6 7 &ls& %&4k6 &4k6 / &4k/"67 &n%7 8th& chang& o0 &rror us& 0or FI( )ust b& scal&%V0uzzi0y %&04k6 %&4k6XE7 8to 1oi% *arning )&ssag& b&caus& o0 bigg&r than " or s)all&r than /"
Th& absolut& &rror obtain&% 0or this syst&) is $$.;?$". Th& r&sult o0 this application is gi1&n in Figur& "3.
Figur& "3
Exercise For both *at&r l&1&l an% *at&r t&)p&ratur& control applications+ try to 0in& tun& th& scalingVgain para)&t&rs o0 th& inputVoutput 1ariabl&s so that th& absolut& &rrors ar& s)all&r.
Using Fuzzy "ogic Controller in Simulin' for Single "in' (o$ot !rm Control In this %&)o+ th& ob]&cti1& is to control th& )o1&)&nt o0 a si)pl&+ singl&/link robot ar)+ as sho*n in th& 0ollo*ing 0igur&.
'
Figur& "A $
Th& &Suation o0 )otion 0or th& ar) is
d x4t 6
dx4t 6
+ u 4t 6 . Wh&r& dt dt $ '4t6 is th& angl& an% u4t6 is th& control signal 4torSu&6. &r& *& )o%&l th& singl& link ar) as a library b&0or& us& it as a plant to t&st th& 0uzzy controll&r in (i)ulink. This library is th&n sa1&% as ,)yrobotar).)%l-. Typ& ,)yrobotar)- in Matlab consol& *in%o* *ill actually call it out. Figur& "> b&lo* sho*n this robot ar) has b&&n )o%&l as a library.
Figur& "> In (i)ulink+ 0uzzy logic controll&r has b&&n )o%&l as a library. I0 *& n&&% to us& FI( in (i)ulink+ "st+ typ& ,0uzblock- in Matlab consol& *in%o*. Th& 0uzzy )o%&ls ar& loa%&% as sho*n in Figur& ">.
#nc& *& ha1& both librari&s 4robot ar) an% 0uzzy controll&r6+ start a n&* (i)ulink )o%&l+ right click robot ar) library an% s&l&ct copy-+ past& it into th& n&* (i)ulink )o%&l. &p&at th& copy an% past& but 0or th& 0uzzy logic controll&r. (&& Figur& "@ 0or %&tail. =0t&r that+ a%% oth&r )o%&l in (i)ulink such as (u)+ Xain an% &lay. Notic& that th& (i)ulink )o%&l sho*n in Figur& "@ is can b& 0oun% in sim1.mdl .
Figur& "@ o*&1&r+ th& (i)ulink )o%&l sho*n in Figur& "@ has not y&t r&a%y to run. This is b&caus& th& 0uzzy logic control )ust b& sp&ci0ic th& FI( )atri'+ *h&r& th& FI( us&% to b& %&sign using FI( E%itor. To %o this+ %&sign a n&* FI( or op&n a &'isting FI( *ith FI( E%itor+ s&l&ct ,Fil&E'portWork(pac&2-. Dou shall typ& in a na)& as you ar& b&ing as to %o so. E.g.+ you ha% ]ust %&sign&% an FI(+ an% you &'port it to *orkspac& *ith na)& 0is3.0is. Th& n&'t thing to %o is co)& back to your (i)ulink )o%&l+ %oubl& click th& FLC library+ a %ialog bo' is sho*. (&& Figur& " 0or %&tail.
Figur& " =s sho* in Figur& "+ you )ust typ& in a 1ali% FI( such as 0is3.0is *hich is you ]ust &'port to *orkspac& 1ia FI( E%itor.
Finally *& can start run th& (i)ulink )o%&l by s&l&ct ,(i)ulink (tart-+ a OD plots sho*n th& output o0 th& 0uzzy controll&% robot ar) co)par& to ran%o) r&0&r&nc& points. Th& r&sult is sho*n in Figur& "? b&lo*.
Figur& "? !d&antage Techni)ue* !da%ti&e +euro-Fuzzy-Inference-Systems ,!+FIS This )o%ul& is &n% *ith a short %iscussion on =NFI(. =NFI( *as "st propos&% by og&r ^ang as a hybri% syst&) b&t*&&n Fuzzy In0&r&nc& (yst&)s but *ith n&ural n&t*ork archit&ctur&. Th& l&arning is r&Suir&% in or%&r to 0in&/tun& th& para)&t&rs o0 th& )&)b&rship 0unctions as *&ll as th& para)&t&rs o0 %&0uzzi0ication. For % &tail o0 th& =NFI(+ pl&as& s&& "<.
#n& o0 th& us&% o0 =NFI( in control syst&) is to l&arn th& in1&rs& o0 th& plant+ so that I can b& us&% as a controll&r a0t&r training phas&. Figur& "; has sho*n th& l&arning phas& o0 =NFI(. =s an &'a)pl&+ *& tak& th& *at&r bath t&)p&ratur& syst&) as th& targ&t plant to b& controll&%. Notic& that th& l&arning o0 =NFI( is bas&% on &rror back propagation as *&ll.
=0t&r th& l&arning phas& is 0inish&%+ th& train&% =NFI( is th&n to b& us&% as a controll&r 0or th& plant. Th& con0iguration o0 block to %o this is sho*n in Figur& $. "
−
z y 4k 6
u 4k 6 =NFI(
lant+ 0
y 4k + "6
y d 4k + "6 Figur& $
Th& Matlab sourc& co%& 0or training o0 =NFI( is list out as b&lo*. Notic& that sa)& sourc& co%& can b& 0oun% )Fil&A.). 8 8 Fil&na)& : )Fil&A.) 8 cl&ar7 &cho on7 clc7 8 8 =NFI( Controll&r 0or th& Wat&r Bath T&)p&ratur& Control 8 8 8 robl&) (tat&)&nt: To %&sign an =NFI( controll&r 0or th& 8 t&)p&ratur& control o0 a bath %&scrib&% in Mo%ul& 3. 8 W& shall i)pl&)&nt th& =NFI( controll&r using 8 th& %ir&ct in1&rs& control strat&gy sho*n in Fig "; an% $. 8 W& 0irst obtain th& training %ata by i)posing ran%o) input 1oltag&s to 8 th& *at&r bath syst&) an% r&cor%ing th& corr&spon%ing t&)p&ratur&s. 8 Th& =NFI( is th&n train&% to i%&nti0y th& in1&rs& )o%&l 8 o0 th& *at&r bath syst&) using th& gath&r&% training %ata. 8 To start th& =NFI( training+ *& n&&% an FI( )atri' that sp&ci0i&s 8 th& structur& an% initial para)&t&rs o0 th& FI( 0or l&arning. 8 Th& us&r can us& th& co))an% __g&n0is"9 to g&n&rat& an FI( )atri' 8 0ro) th& training %ata using th& gri%/typ& partition 8 accor%ing to th& gi1&n nu)b&r an% typ&s o0 )&)b&rship 0unctions. 8 In this %&)onstration+ *& us& 0i1& 8 __gauss)055/typ& )&)b&rship 0unctions. 8
Th& total absolut& &rror o0 this =NFI( controll&r 0or this plant is 3@;.?;>$+ *hich is s)all&r than 0uzzy logic controll&r that *& %iscuss&% abo 1&. =lso it pro%uc&s a stabl& control signal u4k6. (&& Figur& $" 0or %&tail.