Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* FUZZY LOGIC */ float input1 = 2.5; float input2 = 40; char *LINE[] = { NULL, UP, FLAT, DOWN }; char *OUTPUUT[] = {

/*
FUZZY LOGIC
*/
float input1 = 2.5;
float input2 = 40;
char *LINE[] = { "NULL", "UP", "FLAT", "DOWN" };
char *OUTPUUT[] = { "IN THE RANGE", "CLOSE", "DANGEROUSLY NEAR" };
float MFoutput = {60,80,100};
// membership function SENSOR-1
float MF1 [3][4] = { { 1, 1.5, 2.3, 2.5},
{ 2.5, 2.7, 3.4, 3.5},
{ 3.4, 3.8, 4.0, 4.0}};
char *MF1_condition[] = {"NEAR", "MODERATE", "FAR"};
char *MF1_line[] = {"", "", ""};
float MF1_value[3];
// membership function SENSOR-2
float MF2 [3][4] = { { 10, 10, 45, 60},
{ 60, 65, 75, 80},
{ 80, 85, 100, 100}};
char *MF2_condition[] = {"NORMAL", "SPEED", "FASTEST"};
char *MF2_line[] = {"", "", ""};
float MF2_value[3];
//RULES
char *flowRULES[9] = {"CLOSE", "DANGEROUSLY NEAR", "DANGEROUSLY NEAR"
"IN THE RANGE", "CLOSE", "CLOSE"
"IN THE RANGE", "IN THE RANGE", "CLOSE"};
float RULESdetail [9][4] = { { 1, 1.5, 2.3, 2.5},
{ 2.5, 2.7, 3.4, 3.5},
{ 3.4, 3.8, 4.0, 4.0}};
float RULESfindMAX [9][4]
float RULESMAX [4]
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
searchMF();
tableRulesDetail();
}
void loop()
{
delay(2000); //wait for 1000 milisecond(s)
//print_MF1and2();
for (int i = 0; i < 9; i++) {
Serial.print("ke-");Serial.print(i+1); Serial.print("\t");
for (int j = 0; i < 4; i++) {
Serial.print("aa"); Serial.print("\t");
}
Serial.println("");
}
Serial.println("--------------------------------");
}
void tableRulesDetail(){
int i=0, j=0;
for (int i = 0; i < 9; i++) {
// column 1
if(i<3) {RULESdetail[i][0]=MF_value[0];}
else if (i<6){RULESdetail[i][0]}= MF_value[1];}
else {RULESdetail[i][0]= MF_value[2];}
// column 2
RULESdetail[i][1]= MF_value[j];}
j++; if(j==5)j=0;
// column 3 MIN
if(RULESdetail[i][0]>RULESdetail[i][1]) RULESdetail[i][2]=RULESdetail[i][0];
else RULESdetail[i][2]=RULESdetail[i][0];
// column 4 condition 1=IN THE RANGE 2=CLOSE 3=DANGEROUSLY NEAR
if(flowRULES[i]=="IN THE RANGE") RULESdetail[i][3] = 1;
else if(flowRULES[i]=="CLOSE") RULESdetail[i][3] = 2;
else if(flowRULES[i]=="DANGEROUSLY NEAR") RULESdetail[i][3] = 3;
}
}
}
//print_MF1and2();
void print_MF1and2(){
Serial.print(MF1_line[0]);Serial.print(", ");Serial.print(MF1_line[1]);Serial.print(", ");Serial.print(MF1_line[2]); Serial.print("===");
Serial.print(MF1_value[0]);Serial.print(", ");Serial.print(MF1_value[1]);Serial.print(", ");Serial.print(MF1_value[2]);
Serial.print(MF2_line[0]);Serial.print(", ");Serial.print(MF2_line[1]);Serial.print(", ");Serial.print(MF2_line[2]); Serial.print("===");
Serial.print(MF2_value[0]);Serial.print(", ");Serial.print(MF2_value[1]);Serial.print(", ");Serial.println(MF2_value[2]);Serial.println();
}
void searchMF(){
// SENSOR-1
if(input1<=MF1[0][0] {MF1_line[0]= LINE[0];MF1_value[0] = 0;}
else if (input1<=MF1[0][1] {MF1_line[0]= LINE[1];MF1_value[0] = (input1-MF1[0][0])/(MF1[0][1]-MF1[0][0]);}
else if (input1<=MF1[0][2] {MF1_line[0]= LINE[2];MF1_value[0] = 1;}
else if (input1<=MF1[0][3] {MF1_line[0]= LINE[3];MF1_value[0] = (MF1[0][3]-input2)/(MF1[0][3]-MF1[0][2]);}
else {MF1_line[0]= LINE[0];MF1_value[0] = 0;}
if(input1<=MF1[1][0] {MF1_line[1]= LINE[0];MF1_value[1] = 0;}
else if (input1<=MF1[1][1] {MF1_line[1]= LINE[1];MF1_value[1] = (input1-MF1[1][0])/(MF1[1][1]-MF1[1][0]);}
else if (input1<=MF1[1][2] {MF1_line[1]= LINE[2];MF1_value[1] = 1;}
else if (input1<=MF1[1][3] {MF1_line[1]= LINE[3];MF1_value[1] = (MF1[1][3]-input2)/(MF1[1][3]-MF1[1][2]);}
else {MF1_line[1]= LINE[0];MF1_value[1] = 0;}
if(input1<=MF1[2][0] {MF1_line[2]= LINE[0];MF1_value[2] = 0;}
else if (input1<=MF1[2][1] {MF1_line[2]= LINE[1];MF1_value[2] = (input1-MF1[2][0])/(MF1[2][1]-MF1[2][0]);}
else if (input1<=MF1[2][2] {MF1_line[2]= LINE[2];MF1_value[2] = 1;}
else if (input1<=MF1[2][3] {MF1_line[2]= LINE[3];MF1_value[2] = (MF1[2][3]-input2)/(MF1[2][3]-MF1[2][2]);}
else {MF1_line[2]= LINE[0];MF1_value[2] = 0;}
// SENSOR-2
//in the range
if(input1<=MF2[0][0] {MF2_line[0]= LINE[0];MF2_value[0] = 0;}
else if (input1<=MF2[0][1] {MF2_line[0]= LINE[1];MF2_value[0] = (input1-MF2[0][0])/(MF2[0][1]-MF2[0][0]);}
else if (input1<=MF2[0][2] {MF2_line[0]= LINE[2];MF2_value[0] = 1;}
else if (input1<=MF2[0][3] {MF2_line[0]= LINE[3];MF2_value[0] = (MF2[0][3]-input2)/(MF2[0][3]-MF2[0][2]);}
else {MF2_line[0]= LINE[0];MF2_value[0] = 0;}
//close
if(input1<=MF2[1][0] {MF2_line[1]= LINE[0];MF2_value[1] = 0;}
else if (input1<=MF2[1][1] {MF2_line[1]= LINE[1];MF2_value[1] = (input1-MF2[1][0])/(MF2[1][1]-MF2[1][0]);}
else if (input1<=MF2[1][2] {MF2_line[1]= LINE[2];MF2_value[1] = 1;}
else if (input1<=MF2[1][3] {MF2_line[1]= LINE[3];MF2_value[1] = (MF2[1][3]-input2)/(MF2[1][3]-MF2[1][2]);}
else {MF2_line[1]= LINE[0];MF2_value[1] = 0;}
//dangerously near
if(input1<=MF2[2][0] {MF2_line[2]= LINE[0];MF2_value[2] = 0;}
else if (input1<=MF2[2][1] {MF2_line[2]= LINE[1];MF2_value[2] = (input1-MF2[2][0])/(MF2[2][1]-MF2[2][0]);}
else if (input1<=MF2[2][2] {MF2_line[2]= LINE[2];MF2_value[2] = 1;}
else if (input1<=MF2[2][3] {MF2_line[2]= LINE[3];MF2_value[2] = (MF2[2][3]-input2)/(MF2[2][3]-MF2[2][2]);}
else {MF2_line[2]= LINE[0];MF2_value[2] = 0;}
}
can you identify the error of this code for arduino ... ? this is fuzzy function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago