Contoh Penerapan Fuzzy Logic Untuk Pengontrol Kecepatan Motor Servo Pada Aplikasi Simple Color Tracking



Diagram block.
Pada post sebelumnya, telah dibahas tentang aplikasi Simple Color Tracking. Pada kesempatan kali ini saya coba mengembangkan controller untuk servo dengan menggunakan Fuzzy Control System. Berikut rancangannya.
Fuzzy Control Design
System terdiri dari dua input yaitu error dan del_error_prev. error adalah nilai koordinat warna yang di-tracking yang diolah di PC dan dikirim ke mikrokontroler. Sedangkan del_error_prev adalah nilai error dikurangi error sebelumnya. Dan terdiri dari satu output berupa nilai kecepatan respon servo.
Fungsi keanggotaan untuk error.
TKI : Terlalu Kiri
AKI : Agak Kiri
P : Pas
AKA : Agak Kanan
TKA : Terlalu Kanan
Fungsi keanggotaan untuk del_error_prev.
PTKI : Previous Terlalu Kiri
PAKI : Previous Agak Kiri
PP : Previous Pas
PAKA : Previous Agak Kanan
PTKA : Previous Terlalu Kanan
Fuzzy Rule.
 
Fungsi keanggotaan untuk Output Kecepatan Servo.
SI : Sangat Kiri (di bagian lain disebut KIC : Kiri Cepat)
KI : Kiri
D : Diam
KA : Kanan
SA : Sangat Kanan (di bagian lain disebut KAC : Kanan Cepat)
Electronics Design
Pada post sebelumnya mikrokontroler yang digunakan adalah attiny2313. Akan tetapi karena keterbatasan memori maka untuk versi kali ini digunakanlah ATmega8.







:Kode Program:
//==========================================================
// FUZZY CONTROL SYSTEM
//==========================================================
unsigned char equ_aktif_0,equ_aktif_1,equ_aktif_2,equ_aktif_3;
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
//equ_aktif[0-1] kondisi error
//equ_aktif[2-3] kondisi del_error_prev
float TKI_value,AKI_value,P_value,AKA_value,TKA_value;
float PTKI_value,PAKI_value,PP_value,PAKA_value,PTKA_value;
float KIC_value,KI_value,D_value,KA_value,KAC_value;
// Declare your global variables here
void fuzzification(float error, float error_prev)
{
float del_error_prev;
del_error_prev = error - error_prev;
TKI_value = 0;
AKI_value = 0;
P_value = 0;
AKA_value = 0;
TKA_value = 0;
PTKI_value = 0;
PAKI_value = 0;
PP_value = 0;
PAKA_value = 0;
PTKA_value = 0;
//==========================================
//error
//==========================================
if((error<=-9)&&(error>=-10))//=========1
{
//PORTB = 1;
TKI_value = 1;
equ_aktif_0 = 1;//TKI;
equ_aktif_1 = 1;//TKI;
}
else if((error<=-6)&&(error>=-9))//=2
{
//PORTB = 2;
TKI_value = ((-0.333)*error)-2;
AKI_value = ((0.333)*error)+3;
equ_aktif_0 = 1;//TKI;
equ_aktif_1 = 2;//AKI;
}
else if((error<=0)&&(error>=-6))//======3
{
//PORTB = 3;
AKI_value = (-0.167)*error;
P_value = ((0.167)*error)+1;
equ_aktif_0 = 2;//AKI;
equ_aktif_1 = 3;//P;
}
else if((error<=6)&&(error>=0))//=======4
{
//PORTB = 4;
P_value = ((-0.167)*error)+1;
AKA_value = (0.167)*error;
equ_aktif_0 = 3;//P;
equ_aktif_1 = 4;//AKA;
}
else if((error<=9)&&(error>=6))//===5
{
//PORTB = 5;
AKA_value = ((-0.333)*error)+3;
TKA_value = ((0.333)*error)-2;
equ_aktif_0 = 4;//AKA;
equ_aktif_1 = 5;//TKA;
}
else if((error<=10)&&(error>=9))//======6
{
//PORTB = 6;
TKA_value = 1;
equ_aktif_0 = 5;//TKA;
equ_aktif_1 = 5;//TKA;
}
//==========================================
//del_error_prev
//==========================================
if((del_error_prev<=-9)&&(del_error_prev>=-10))//=========1
{
//PORTB = 7;
PTKI_value = 1;
equ_aktif_2 = 6;//PTKI;
equ_aktif_3 = 6;//PTKI;
}
else if((del_error_prev<=-6)&&(del_error_prev>=-9))//=2
{
//PORTB = 8;
PTKI_value = ((-0.333)*del_error_prev)-2;
PAKI_value = ((0.333)*del_error_prev)+3;
equ_aktif_2 = 6;//PTKI;
equ_aktif_3 = 7;//PAKI;
}
else if((del_error_prev<=0)&&(del_error_prev>=-6))//======3
{
//PORTB = 9;
PAKI_value = (-0.167)*del_error_prev;
PP_value = ((0.167)*del_error_prev)+1;
equ_aktif_2 = 7;//PAKI;
equ_aktif_3 = 8;//PP;
}
else if((del_error_prev<=6)&&(del_error_prev>=0))//=======4
{
//PORTB = 10;
PP_value = ((-0.167)*del_error_prev)+1;
PAKA_value = (0.167)*del_error_prev;
equ_aktif_2 = 8;//PP;
equ_aktif_3 = 9;//PAKA;
}
else if((del_error_prev<=9)&&(del_error_prev>=6))//===5
{
//PORTB = 11;
PAKA_value = ((-0.333)*del_error_prev)+3;
PTKA_value = ((0.333)*del_error_prev)-2;
equ_aktif_2 = 9;//PAKA;
equ_aktif_3 = 10;//PTKA;
}
else if((del_error_prev<=10)&&(del_error_prev>=9))//======6
{
//PORTB = 12;
PTKA_value = 1;
equ_aktif_2 = 10;//PTKA;
equ_aktif_3 = 10;//PTKA;
}
}
void inferensi_mamdani_or_sugeno_model()
{
KIC_value = KI_value = D_value = KA_value = KAC_value = 0;
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======1 KIC
{
//CONJUCTION
if(TKI_value < PTKI_value) { KIC_value = TKI_value; } else { KIC_value = PTKI_value; } } if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======2 KI { //CONJUCTION if(TKI_value < PTKA_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > KI_value)
{
KI_value = PTKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======3 KI
{
//CONJUCTION
if(TKI_value < PAKA_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > KI_value)
{
KI_value = PAKA_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======4 KI
{
//CONJUCTION
if(AKI_value < PP_value) { //DISJUNCTION if(AKI_value > KI_value)
{
KI_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KI_value)
{
KI_value = PP_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======5 KI
{
//CONJUCTION
if(TKI_value < PP_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KI_value)
{
KI_value = PP_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======6 KI
{
//CONJUCTION
if(AKI_value < PAKI_value) { //DISJUNCTION if(AKI_value > KI_value)
{
KI_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > KI_value)
{
KI_value = PAKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======7 KI
{
//CONJUCTION
if(TKI_value < PAKI_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > KI_value)
{
KI_value = PAKI_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======8 KI
{
//CONJUCTION
if(AKI_value < PTKI_value) { //DISJUNCTION if(AKI_value > KI_value)
{
KI_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > KI_value)
{
KI_value = PTKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======9 D
{
//CONJUCTION
if(P_value < PTKI_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > D_value)
{
D_value = PTKI_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======10 D
{
//CONJUCTION
if(AKA_value < PTKI_value) { //DISJUNCTION if(AKA_value > D_value)
{
D_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > D_value)
{
D_value = PTKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======11 D
{
//CONJUCTION
if(P_value < PAKI_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > D_value)
{
D_value = PAKI_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======12 D
{
//CONJUCTION
if(AKA_value < PAKI_value) { //DISJUNCTION if(AKA_value > D_value)
{
D_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > D_value)
{
D_value = PAKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======13 D
{
//CONJUCTION
if(P_value < PP_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PP_value > D_value)
{
D_value = PP_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======14 D
{
//CONJUCTION
if(AKI_value < PAKA_value) { //DISJUNCTION if(AKI_value > D_value)
{
D_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > D_value)
{
D_value = PAKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======15 D
{
//CONJUCTION
if(P_value < PAKA_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > D_value)
{
D_value = PAKA_value;
}
}
}
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======16 D
{
//CONJUCTION
if(P_value < PTKA_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > D_value)
{
D_value = PTKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======17 D
{
//CONJUCTION
if(AKI_value < PTKA_value) { //DISJUNCTION if(AKI_value > D_value)
{
D_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > D_value)
{
D_value = PTKA_value;
}
}
}
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======18 KA
{
//CONJUCTION
if(TKA_value < PTKI_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > KA_value)
{
KA_value = PTKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======19 KA
{
//CONJUCTION
if(TKA_value < PAKI_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > KA_value)
{
KA_value = PAKI_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======20 KA
{
//CONJUCTION
if(AKA_value < PP_value) { //DISJUNCTION if(AKA_value > KA_value)
{
KA_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KA_value)
{
KA_value = PP_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======21 KA
{
//CONJUCTION
if(TKA_value < PP_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KA_value)
{
KA_value = PP_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======22 KA
{
//CONJUCTION
if(AKA_value < PAKA_value) { //DISJUNCTION if(AKA_value > KA_value)
{
KA_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > KA_value)
{
KA_value = PAKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======23 KA
{
//CONJUCTION
if(TKA_value < PAKA_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > KA_value)
{
KA_value = PAKA_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======24 KA
{
//CONJUCTION
if(AKA_value < PTKA_value) { //DISJUNCTION if(AKA_value > KA_value)
{
KA_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > KA_value)
{
KA_value = PTKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5
//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======25 KAC
{
//CONJUCTION
if(TKA_value < PTKA_value) { KAC_value = TKA_value; } else { KAC_value = PTKA_value; } } } /========================================================== // DEFUZZYFICATION SB X //========================================================== int defuzzyfication_sugeno()//Height method { int out_pwm; out_pwm = (int)(((KIC_value*(-10))+(KI_value*(-3.73))+(D_value*(0))+(KA_value*(3.73))+(KAC_value*(10)))/(KIC_value + KI_value + D_value + KA_value + KAC_value)); return(out_pwm); } //================================================================= //========================================================== // DEFUZZYFICATION SB Y //========================================================== int defuzzyfication_sugeno_y()//Height method { int out_pwm_y; out_pwm_y = (int)(((KIC_value*(-10))+(KI_value*(-2.95))+(D_value*(0))+(KA_value*(2.95))+(KAC_value*(10)))/(KIC_value + KI_value + D_value + KA_value + KAC_value)); return(out_pwm_y); }



:Program Lengkap:
/*****************************************************
Chip type : ATmega8
Program type : Application
Clock frequency : 12.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/

#include
#include

#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1< #include // Declare your global variables here //========================================================== // FUZZY X //========================================================== unsigned char equ_aktif_0,equ_aktif_1,equ_aktif_2,equ_aktif_3; //TKI 1 //AKI 2 //P 3 //AKA 4 //TKA 5 //PTKI 6 //PAKI 7 //PP 8 //PAKA 9 //PTKA 10 //equ_aktif[0-1] kondisi error //equ_aktif[2-3] kondisi del_error_prev float TKI_value,AKI_value,P_value,AKA_value,TKA_value; float PTKI_value,PAKI_value,PP_value,PAKA_value,PTKA_value; float KIC_value,KI_value,D_value,KA_value,KAC_value; // Declare your global variables here void fuzzification(float error, float error_prev) { float del_error_prev; del_error_prev = error - error_prev; TKI_value = 0; AKI_value = 0; P_value = 0; AKA_value = 0; TKA_value = 0; PTKI_value = 0; PAKI_value = 0; PP_value = 0; PAKA_value = 0; PTKA_value = 0; //========================================== //error //========================================== if((error=-10))//=========1 { //PORTB = 1; TKI_value = 1; equ_aktif_0 = 1;//TKI; equ_aktif_1 = 1;//TKI; } else if((error=-9))//=2 { //PORTB = 2; TKI_value = ((-0.333)*error)-2; AKI_value = ((0.333)*error)+3; equ_aktif_0 = 1;//TKI; equ_aktif_1 = 2;//AKI; } else if((error=-6))//======3 { //PORTB = 3; AKI_value = (-0.167)*error; P_value = ((0.167)*error)+1; equ_aktif_0 = 2;//AKI; equ_aktif_1 = 3;//P; } else if((error=0))//=======4 { //PORTB = 4; P_value = ((-0.167)*error)+1; AKA_value = (0.167)*error; equ_aktif_0 = 3;//P; equ_aktif_1 = 4;//AKA; } else if((error=6))//===5 { //PORTB = 5; AKA_value = ((-0.333)*error)+3; TKA_value = ((0.333)*error)-2; equ_aktif_0 = 4;//AKA; equ_aktif_1 = 5;//TKA; } else if((error=9))//======6 { //PORTB = 6; TKA_value = 1; equ_aktif_0 = 5;//TKA; equ_aktif_1 = 5;//TKA; } //========================================== //del_error_prev //========================================== if((del_error_prev=-10))//=========1 { //PORTB = 7; PTKI_value = 1; equ_aktif_2 = 6;//PTKI; equ_aktif_3 = 6;//PTKI; } else if((del_error_prev=-9))//=2 { //PORTB = 8; PTKI_value = ((-0.333)*del_error_prev)-2; PAKI_value = ((0.333)*del_error_prev)+3; equ_aktif_2 = 6;//PTKI; equ_aktif_3 = 7;//PAKI; } else if((del_error_prev=-6))//======3 { //PORTB = 9; PAKI_value = (-0.167)*del_error_prev; PP_value = ((0.167)*del_error_prev)+1; equ_aktif_2 = 7;//PAKI; equ_aktif_3 = 8;//PP; } else if((del_error_prev=0))//=======4 { //PORTB = 10; PP_value = ((-0.167)*del_error_prev)+1; PAKA_value = (0.167)*del_error_prev; equ_aktif_2 = 8;//PP; equ_aktif_3 = 9;//PAKA; } else if((del_error_prev=6))//===5 { //PORTB = 11; PAKA_value = ((-0.333)*del_error_prev)+3; PTKA_value = ((0.333)*del_error_prev)-2; equ_aktif_2 = 9;//PAKA; equ_aktif_3 = 10;//PTKA; } else if((del_error_prev=9))//======6 { //PORTB = 12; PTKA_value = 1; equ_aktif_2 = 10;//PTKA; equ_aktif_3 = 10;//PTKA; } } void inferensi_mamdani_or_sugeno_model() { KIC_value = KI_value = D_value = KA_value = KAC_value = 0; //TKI 1 //AKI 2 //P 3 //AKA 4 //TKA 5 //PTKI 6 //PAKI 7 //PP 8 //PAKA 9 //PTKA 10 if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======1 KIC { //CONJUCTION if(TKI_value < PTKI_value) { KIC_value = TKI_value; } else { KIC_value = PTKI_value; } } if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======2 KI { //CONJUCTION if(TKI_value < PTKA_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > KI_value)
{
KI_value = PTKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======3 KI
{
//CONJUCTION
if(TKI_value < PAKA_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > KI_value)
{
KI_value = PAKA_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======4 KI
{
//CONJUCTION
if(AKI_value < PP_value) { //DISJUNCTION if(AKI_value > KI_value)
{
KI_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KI_value)
{
KI_value = PP_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======5 KI
{
//CONJUCTION
if(TKI_value < PP_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KI_value)
{
KI_value = PP_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======6 KI
{
//CONJUCTION
if(AKI_value < PAKI_value) { //DISJUNCTION if(AKI_value > KI_value)
{
KI_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > KI_value)
{
KI_value = PAKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==1)||(equ_aktif_1==1)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======7 KI
{
//CONJUCTION
if(TKI_value < PAKI_value) { //DISJUNCTION if(TKI_value > KI_value)
{
KI_value = TKI_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > KI_value)
{
KI_value = PAKI_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======8 KI
{
//CONJUCTION
if(AKI_value < PTKI_value) { //DISJUNCTION if(AKI_value > KI_value)
{
KI_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > KI_value)
{
KI_value = PTKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======9 D
{
//CONJUCTION
if(P_value < PTKI_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > D_value)
{
D_value = PTKI_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======10 D
{
//CONJUCTION
if(AKA_value < PTKI_value) { //DISJUNCTION if(AKA_value > D_value)
{
D_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > D_value)
{
D_value = PTKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======11 D
{
//CONJUCTION
if(P_value < PAKI_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > D_value)
{
D_value = PAKI_value;
}
}
}
if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======12 D
{
//CONJUCTION
if(AKA_value < PAKI_value) { //DISJUNCTION if(AKA_value > D_value)
{
D_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > D_value)
{
D_value = PAKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======13 D
{
//CONJUCTION
if(P_value < PP_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PP_value > D_value)
{
D_value = PP_value;
}
}
}
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======14 D
{
//CONJUCTION
if(AKI_value < PAKA_value) { //DISJUNCTION if(AKI_value > D_value)
{
D_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > D_value)
{
D_value = PAKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======15 D
{
//CONJUCTION
if(P_value < PAKA_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > D_value)
{
D_value = PAKA_value;
}
}
}
if( ((equ_aktif_0==3)||(equ_aktif_1==3)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======16 D
{
//CONJUCTION
if(P_value < PTKA_value) { //DISJUNCTION if(P_value > D_value)
{
D_value = P_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > D_value)
{
D_value = PTKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==2)||(equ_aktif_1==2)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======17 D
{
//CONJUCTION
if(AKI_value < PTKA_value) { //DISJUNCTION if(AKI_value > D_value)
{
D_value = AKI_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > D_value)
{
D_value = PTKA_value;
}
}
}
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==6)||(equ_aktif_3==6))) //=======18 KA
{
//CONJUCTION
if(TKA_value < PTKI_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PTKI_value > KA_value)
{
KA_value = PTKI_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10

if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==7)||(equ_aktif_3==7))) //=======19 KA
{
//CONJUCTION
if(TKA_value < PAKI_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PAKI_value > KA_value)
{
KA_value = PAKI_value;
}
}
}

if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======20 KA
{
//CONJUCTION
if(AKA_value < PP_value) { //DISJUNCTION if(AKA_value > KA_value)
{
KA_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KA_value)
{
KA_value = PP_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==8)||(equ_aktif_3==8))) //=======21 KA
{
//CONJUCTION
if(TKA_value < PP_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PP_value > KA_value)
{
KA_value = PP_value;
}
}
}

if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==9)||(equ_aktif_3==9))) //=======22 KA
{
//CONJUCTION
if(AKA_value < PAKA_value) { //DISJUNCTION if(AKA_value > KA_value)
{
KA_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > KA_value)
{
KA_value = PAKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======23 KA
{
//CONJUCTION
if(TKA_value < PAKA_value) { //DISJUNCTION if(TKA_value > KA_value)
{
KA_value = TKA_value;
}
}
else
{
//DISJUNCTION
if(PAKA_value > KA_value)
{
KA_value = PAKA_value;
}
}
}

if( ((equ_aktif_0==4)||(equ_aktif_1==4)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======24 KA
{
//CONJUCTION
if(AKA_value < PTKA_value) { //DISJUNCTION if(AKA_value > KA_value)
{
KA_value = AKA_value;
}
}
else
{
//DISJUNCTION
if(PTKA_value > KA_value)
{
KA_value = PTKA_value;
}
}
}
//TKI 1
//AKI 2
//P 3
//AKA 4
//TKA 5

//PTKI 6
//PAKI 7
//PP 8
//PAKA 9
//PTKA 10
if( ((equ_aktif_0==5)||(equ_aktif_1==5)) && ((equ_aktif_2==10)||(equ_aktif_3==10))) //=======25 KAC
{
//CONJUCTION
if(TKA_value < PTKA_value) { KAC_value = TKA_value; } else { KAC_value = PTKA_value; } } } int defuzzyfication_sugeno()//Height method { int out_pwm; out_pwm = (int)(((KIC_value*(-10))+(KI_value*(-3.73))+(D_value*(0))+(KA_value*(3.73))+(KAC_value*(10)))/(KIC_value + KI_value + D_value + KA_value + KAC_value)); return(out_pwm); } //================================================================= //========================================================== // FUZZY Y //========================================================== int defuzzyfication_sugeno_y()//Height method { int out_pwm_y; out_pwm_y = (int)(((KIC_value*(-10))+(KI_value*(-2.95))+(D_value*(0))+(KA_value*(2.95))+(KAC_value*(10)))/(KIC_value + KI_value + D_value + KA_value + KAC_value)); return(out_pwm_y); } //================================================================= // Declare your global variables here void my_delay_us(int n) { while (n--) { delay_us(1); } } int i1,j1; void reset_servo() { int i; i1 = 700; j1 = 400; for(i=0;i 0) { PORTB.0 = 1; my_delay_us(i1); PORTB.0 = 0; if(i1 < 1100) i1 = i1 + (out_fuzzy_x); } else if(out_fuzzy_x < 0) { PORTB.0 = 1; my_delay_us(i1); PORTB.0 = 0; if(i1 > 400) i1 = i1 + (out_fuzzy_x);
}
error_act_prev_x = error_act_x;

//===================================
//EXE SB Y
//===================================
fuzzification((float)error_act_y,(float)error_act_prev_y);
inferensi_mamdani_or_sugeno_model();
out_fuzzy_y = defuzzyfication_sugeno_y();
// EXECUTION
if(out_fuzzy_y > 0)
{
PORTB.1 = 1;
my_delay_us(j1);
PORTB.1 = 0;
if(j1 < 700) j1 = j1 + (out_fuzzy_y); } else if(out_fuzzy_y < 0) { PORTB.1 = 1; my_delay_us(j1); PORTB.1 = 0; if(j1 > 340) j1 = j1 + (out_fuzzy_y);
}
error_act_prev_y = error_act_y;

while(getchar() != 69){};
goto awal;
};
}

Berikut file yang bisa didownload.

http://www.mediafire.com/file/rrzk2rrffkcvkdg/Fuzzy-update_simple_color_tracking_servo_controller.rar
http://www.mediafire.com/file/zc7z1l566l7x8w4/1012_–_Penerapan_Fuzzy_Logic_Untuk_Pengontrol_Kecepatan_Motor_Servo_Pada_Aplikasi_Simple_Color_Tracking.rar


Share : http://wangready.wordpress.com/2011/05/20/fuzzy-logic-pada-servo-controller-untuk-aplikasi-simple-color-tracking/#comment-287


Postingan terkait:

Belum ada tanggapan untuk "Contoh Penerapan Fuzzy Logic Untuk Pengontrol Kecepatan Motor Servo Pada Aplikasi Simple Color Tracking"

Kontes Robot

Kontes Robot