# For Yang

penmetsa chandra (satipandu@hotmail.com)
Mon, 16 Mar 1998 00:24:31 +0100 (MET)

Hello Mr Yang,

It was nice to hear from u that u too are interested in Fuzzy Logic. In
reply to ur letter asking for help on fuzzy logic, Bart Kosko's 'Neural
Networks and Fuzzy Logic - Aconceptual approach to machine intelligence
would be of lot of help.

As for the program u have asked, I send along a program for an
automatic car parking system - a very simple example. The aim is to park
a car at the position (150,0) and at an angle 90 degrees irrespective of
the initial position in the x-plane and the initial starting angle . The
y=position is however 150. The inputs to the system are the x-position
and the angle of the car wrt. the final angle of the car. The parameter
to be controlled is the wheel angle of the car. Remember taht the
present position can be between 0 and 300 only - in the x - plane.

I hope this program will be of help to you. Please compile on a turboc
compiler. Feel free to contact me if u have any problems with the code
or the execution - for that matter anything which I could be of any help
- for knowledge comes only when u keep questioning for better answers.
If u have any suggestions for a better FAM rule base or better fuzzy set

With warm regards
P. SATISH CHANDRA,INDIA.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>

void main(void)
{
int gdriver = DETECT,ch,gmode,i,j,asdf,p,choice;

/* Fam RULE TABLE */

int famm={{4,5,5,6,6},
{2,4,5,6,6},
{1,2,4,5,6},
{1,2,3,4,5},
{0,1,2,4,5},
{0,0,1,2,4},
{0,0,1,1,2}};

float y1,x1,x2,y2,q,aa=acos(-1)/180;
float area,tot=0,ca=0,ppo,pan,l1,l2,h,m1,m2;
double centroid;

/* defining FUzzy input sets */

/* present x - position */
float xp={{0,130},{100,150},{140,160},{150,200},{170,300}};

/* present angle */
float pa={{-95,5},{-5,60},{50,90},
{85,95},{90,130},{120,185},{175,300}};

/* output - wheel angle */

float wa={{-20,-8},{-10,-3},{-3.5,0},
{-2,2},{0,3.5},{3,10},{8,20}};

char ccc='y';
while(ccc!='n')
{
printf("Enter the presernt position and angle:");
scanf("%f %f",&ppo,&pan);
x1=ppo; y1=150;
clrscr();
initgraph(&gdriver,&gmode,"c:\\tcc");
putpixel(150,0,1);
while(y1>=0) {
tot=0; ca=0;
putpixel(x1,y1,3);

/* fuzzifying the inputs */

for(i=0;i<5;i++)
{
if(x1>xp[i]&&xp[i]>x1)
if(x1-xp[i]<=xp[i]-x1)
m1[i]=((x1-xp[i])*2)/(xp[i]-xp[i]);
else
m1[i]=((xp[i]-x1)*2)/(xp[i]-xp[i]);
else
m1[i]=0;
}

for(i=0;i<7;i++)
{
if(pan>pa[i]&&pa[i]>pan)
if(pan-pa[i]<=pa[i]-pan)
m2[i]=((pan-pa[i])*2)/(pa[i]-pa[i]);
else
m2[i]=((pa[i]-pan)*2)/(pa[i]-pa[i]);
else
m2[i]=0;
}

/* end of fuzzification */

for(i=0;i<7;i++)
for(j=0;j<5;j++)
{

/* finding output membership function */

if(m2[i]<=m1[j])
h=m2[i];
else
h=m1[j];

/* defuzzification */

p=famm[i][j];
l1=wa[p]-wa[p];
l2=((1-h)*l1);
area=(h*(l1+l2)/2);
tot=tot+area;
ca=ca+(area*(wa[p]+wa[p])/2);}
centroid=ca/tot;
pan=pan+centroid;

/* altering the present position */

x1=x1+(2*(cos((pan*aa))));
y1=y1-(2*(sin((pan*aa))));}
ccc=getch();
}
}

/************************ THE END *************************/

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com