Code Monkey home page Code Monkey logo

efll's Introduction


📈 GitHub Stats

Phil's GitHub Stats

efll's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efll's Issues

Energia code for fuzzy speed controller on C language

Hey All,
Its Urgent,

Can anyone provide me C language code for fuzzy logic speed controller. I'm doing this Using ENERGIA interface.
I'm taking my inputs using a ultrasonic sensor and after fuzzy methods the outputs are taken by DC motors as their inputs and then after they are going to control the speed or the rotation speed of DC motor.

Thank You

Energia code for fuzzy speed controller on C language

Fuzzy output limit ?

i have 4 fuzzy output sets and i could only defuzzify 2 . is they a limit because most examples i have seen have maximum of two or arduino uno just isnt cutting it .

`#include <Fuzzy.h>

// For scope, instantiate all objects you will need to access in loop()
// It may be just one Fuzzy, but for demonstration, this sample will print
// all FuzzySet pertinence

// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput : Temperature
FuzzySet *low_temperature = new FuzzySet(0, 30, 35, 38);
FuzzySet *mid_temperature = new FuzzySet(36, 36, 36, 0);
FuzzySet *high_temperature = new FuzzySet(38, 40, 40, 100);
// FuzzyInput : Humidity
FuzzySet *low_humidity = new FuzzySet(0, 20, 20, 40);
FuzzySet *mid_humidity = new FuzzySet(30, 50, 50, 70);
FuzzySet *high_humidity = new FuzzySet(60, 90, 100, 140);
// FuzzyInput : Fog water tank
FuzzySet *low_watertank = new FuzzySet(0, 20, 20, 40);
FuzzySet *mid_watertank = new FuzzySet(30, 50, 50, 70);
FuzzySet *high_watertank = new FuzzySet(60, 80, 100, 100);
// FuzzyInput : pH
FuzzySet *low_ph = new FuzzySet(0, 1, 5,7 );
FuzzySet *mid_ph = new FuzzySet(6, 9, 13, 19);
FuzzySet *high_ph = new FuzzySet(15, 24, 28, 30);
// FuzzyInput : Light
FuzzySet *low_light = new FuzzySet(0, 20, 20, 90);
FuzzySet *mid_light = new FuzzySet(80, 120, 120, 128);
FuzzySet *high_light = new FuzzySet(125, 500,5000 ,5000 );

// FuzzyOutput: Heater
FuzzySet *minimum_heater = new FuzzySet(3, 20, 20, 40);
FuzzySet *average_heater = new FuzzySet(30, 50, 50, 70);
FuzzySet *maximum_heater = new FuzzySet(60, 80, 80, 100);
// FuzzyOutput: Fan
FuzzySet *minimum_fan = new FuzzySet(1000, 1200, 1300, 1400);
FuzzySet *average_fan = new FuzzySet(1350, 1500, 1500, 1700);
FuzzySet *maximum_fan = new FuzzySet(1600, 1800, 1900, 2000);
// FuzzyOutput: Fogger
FuzzySet *minimum_fogger = new FuzzySet(6, 20, 20, 40);
FuzzySet *average_fogger = new FuzzySet(30, 50, 50, 70);
FuzzySet *maximum_fogger = new FuzzySet(60, 80, 80, 100);
// FuzzyOutput: Curtain
FuzzySet *minimum_curtain = new FuzzySet(4, 20, 20, 40);
FuzzySet *average_curtain = new FuzzySet(30, 50, 50, 70);
FuzzySet *maximum_curtain = new FuzzySet(60, 80, 80, 100);
// FuzzyOutput: Light
FuzzySet *minimum_LEDlight = new FuzzySet(5, 20, 20, 40);
FuzzySet *average_LEDlight = new FuzzySet(30, 50, 50, 70);
FuzzySet *maximum_LEDlight = new FuzzySet(60, 80, 80, 100);
// FuzzyOutput: Dosing pump
FuzzySet *minimum_pump = new FuzzySet(2, 20, 20, 40);
FuzzySet *average_pump = new FuzzySet(30, 50, 50, 70);
FuzzySet *maximum_pump = new FuzzySet(60, 80, 80, 100);

void setup()
{
// Set the Serial output
Serial.begin(9600);
// Set a random seed
randomSeed(analogRead(0));

// Every setup must occur in the function setup()

// FuzzyInput
FuzzyInput *temperature = new FuzzyInput(1);

temperature->addFuzzySet(low_temperature);
temperature->addFuzzySet(mid_temperature);
temperature->addFuzzySet(high_temperature);
fuzzy->addFuzzyInput(temperature);

// FuzzyInput for Humidity
FuzzyInput *humidity = new FuzzyInput(2);

humidity->addFuzzySet(low_humidity);
humidity->addFuzzySet(mid_humidity);
humidity->addFuzzySet(high_humidity);
fuzzy->addFuzzyInput(humidity);

// FuzzyInput for fog water tank

FuzzyInput *watertank = new FuzzyInput(3);
watertank->addFuzzySet(low_watertank);
watertank->addFuzzySet(mid_watertank);
watertank->addFuzzySet(high_watertank);
fuzzy->addFuzzyInput(watertank);

    // FuzzyInput fpr pH

FuzzyInput *ph = new FuzzyInput(5);
ph->addFuzzySet(low_ph);
ph->addFuzzySet(mid_ph);
ph->addFuzzySet(high_ph);
fuzzy->addFuzzyInput(ph);

 // FuzzyInput for  lighting Condition

FuzzyInput *light = new FuzzyInput(6);
light->addFuzzySet(low_light);
light->addFuzzySet(mid_light);
light->addFuzzySet(high_light);
fuzzy->addFuzzyInput(light);

// FuzzyOutput
FuzzyOutput *heater = new FuzzyOutput(1);

heater->addFuzzySet(minimum_heater);
heater->addFuzzySet(average_heater);
heater->addFuzzySet(maximum_heater);
fuzzy->addFuzzyOutput(heater);

// FuzzyOutput for Cooling fan
FuzzyOutput *fan = new FuzzyOutput(2);

fan->addFuzzySet(minimum_fan);
fan->addFuzzySet(average_fan);
fan->addFuzzySet(maximum_fan);
fuzzy->addFuzzyOutput(fan);

// FuzzyOutput for Growing Lights

FuzzyOutput *LEDlight = new FuzzyOutput(3);

LEDlight->addFuzzySet(minimum_LEDlight);
LEDlight->addFuzzySet(average_LEDlight);
LEDlight->addFuzzySet(maximum_LEDlight);
fuzzy->addFuzzyOutput(LEDlight);

// FuzzyOutput for Humidifier
FuzzyOutput *fogger = new FuzzyOutput(4);

fogger->addFuzzySet(minimum_fogger);
fogger->addFuzzySet(average_fogger);
fogger->addFuzzySet(maximum_fogger);
fuzzy->addFuzzyOutput(fogger);

// FuzzyOutput for Dosing Pump
FuzzyOutput *pump = new FuzzyOutput(5);
pump->addFuzzySet(minimum_pump);
pump->addFuzzySet(average_pump);
pump->addFuzzySet(maximum_pump);
fuzzy->addFuzzyOutput(pump);

  // FuzzyOutput for Curtain

FuzzyOutput *curtain = new FuzzyOutput(6);
curtain->addFuzzySet(minimum_curtain);
curtain->addFuzzySet(average_curtain);
curtain->addFuzzySet(maximum_curtain);
fuzzy->addFuzzyOutput(curtain);

// Building FuzzyRule 1 for low temperature high humidity,+ low ph (lhlh)

FuzzyRuleAntecedent *temperatureLOWandhumidityHIGH = new FuzzyRuleAntecedent();
temperatureLOWandhumidityHIGH->joinWithAND(low_temperature, high_humidity);

FuzzyRuleAntecedent *phLOWandlightHIGH = new FuzzyRuleAntecedent();
phLOWandlightHIGH->joinWithAND(low_ph, high_light);

FuzzyRuleAntecedent *ifTemperatureLOWandhumidityHIGHandphLOWandlightHIGH = new FuzzyRuleAntecedent();
ifTemperatureLOWandhumidityHIGHandphLOWandlightHIGH->joinWithAND(temperatureLOWandhumidityHIGH, phLOWandlightHIGH);

FuzzyRuleConsequent *thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow = new FuzzyRuleConsequent();
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow->addOutput(maximum_heater);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow->addOutput(maximum_pump);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow->addOutput(minimum_fogger);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow->addOutput(maximum_fan);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow->addOutput(minimum_curtain);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifTemperatureLOWandhumidityHIGHandphLOWandlightHIGH, thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightLow_and_fanLow);
fuzzy->addFuzzyRule(fuzzyRule1);

// Building FuzzyRule 2 for low temperature high humidity,+ low ph (lhll)

FuzzyRuleAntecedent *phLOWandlightLOW = new FuzzyRuleAntecedent();
phLOWandlightLOW->joinWithAND(low_ph, low_light);

FuzzyRuleAntecedent *ifTemperatureLOWandhumidityHIGHandphLOWandlightLOW = new FuzzyRuleAntecedent();
ifTemperatureLOWandhumidityHIGHandphLOWandlightLOW->joinWithAND(temperatureLOWandhumidityHIGH, phLOWandlightLOW);

FuzzyRuleConsequent *thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow = new FuzzyRuleConsequent();
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow->addOutput(maximum_heater);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow->addOutput(maximum_pump);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow->addOutput(minimum_fogger);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow->addOutput(minimum_fan);
thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow->addOutput(maximum_LEDlight);

FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifTemperatureLOWandhumidityHIGHandphLOWandlightLOW, thenHeaterHigh_and_pumpHigh_and_foggerLow_and_lightHigh_and_fanLow);
fuzzy->addFuzzyRule(fuzzyRule2);

}

void loop()
{
// get random entrances
int input1 = 35 ;
int input2 = 95;
int input3 = 3;
int input4 = 400;

fuzzy->setInput(1, input1);
fuzzy->setInput(2, input2);
fuzzy->setInput(5, input3);
fuzzy->setInput(6, input4);

fuzzy->fuzzify();

float heater_output = fuzzy->defuzzify(1);
float light_output = fuzzy->defuzzify(3);
float fan_output = fuzzy->defuzzify(2);
float fogger_output = fuzzy->defuzzify(4);
float dosing_pump_output = fuzzy->defuzzify(5);
float curtain_output = fuzzy->defuzzify(6);

Serial.println("Action : ");
Serial.print("Heater :");
Serial.println(heater_output);
Serial.print("Fan :");
Serial.println(fan_output);
Serial.print("Fogger :");
Serial.println(fogger_output);
Serial.print("Dosing pump :");
Serial.println(dosing_pump_output);
Serial.print("Curtain :");
Serial.println(curtain_output);
Serial.print("Growing light :");
Serial.println(light_output);

// wait 12 seconds
delay(2000);
}`

Help with fuzzy hydroponics

Hi! Loving this library so far! I am trying to recreate the Fuzzy controller seen in the picture here https://imgur.com/a/Rk4qOhe, but I have just started using the library but never implemented a fuzzy controller before, I am pretty sure my outputs are not correct as of now. Here are the membership functions I am trying to recreate https://imgur.com/a/Q20vhaK

I have tried covering the cases in the "The first rules" -> "Acid High" but I am not seeing a proper output. The optimal ph should be 5.5 and the optimal ec range should be 550-600. I was expecting to see something from the output1 and output2 variables, but they are constantly 0. Can you help?
Thank you!

#include <Arduino.h>

#include <Fuzzy.h>

// Instantiating a Fuzzy object
Fuzzy *fuzzy = new Fuzzy();

//FuzzyInput
FuzzyInput *ph = new FuzzyInput(1);
//FuzzySet *phacid = new FuzzySet(0, 0, 5.5, 6.0);
//FuzzySet *phbase = new FuzzySet(5.5, 6.0, 14.0, 14.0);
FuzzySet *phACIDIC = new FuzzySet(0, 0, 5.5, 6.0);
FuzzySet *phALKALINE = new FuzzySet(5.5, 6.0, 14.0, 14.0);

FuzzyInput *ec = new FuzzyInput(2);
FuzzySet *ecLOW = (0, 0, 500, 550);
FuzzySet *ecOPTIMAL = (500, 550, 600, 650);
FuzzySet *ecHIGH = (600, 650, 700, 700);

//FuzzyOutput
FuzzyOutput *ph_pumpaction = new FuzzyOutput(1);
FuzzySet *ph_pumpoff = new FuzzySet(0, 0, 0, 0);
FuzzySet *ph_pumpon = new FuzzySet(0, 1, 1, 1);


FuzzyOutput *ec_pumpaction = new FuzzyOutput(2);
FuzzySet *ec_pumpoff = new FuzzySet(0, 0, 0, 0);
FuzzySet *ec_pumpon = new FuzzySet(0, 1, 1, 1);

void setup()
{
  // Set the Serial output
  Serial.begin(9600);
  // Set a random seed
  randomSeed(analogRead(0));

  ph->addFuzzySet(phACIDIC);
  ph->addFuzzySet(phALKALINE);
  fuzzy->addFuzzyInput(ph);

  ec->addFuzzySet(ecLOW);
  ec->addFuzzySet(ecOPTIMAL);
  ec->addFuzzySet(ecHIGH);
  fuzzy->addFuzzyInput(ec);

  ph_pumpaction->addFuzzySet(ph_pumpoff);
  ph_pumpaction->addFuzzySet(ph_pumpon);
  fuzzy->addFuzzyOutput(ph_pumpaction);

  ec_pumpaction->addFuzzySet(ec_pumpoff);
  ec_pumpaction->addFuzzySet(ec_pumpon);
  fuzzy->addFuzzyOutput(ec_pumpaction);

  //building fuzzy rule for ph AND ec
  // ACIDIC FIRST RULE

  // if ph acidic AND eclow THEN ph pump OFF AND ec pump ON
  FuzzyRuleAntecedent *phAcidicAndEcLow = new FuzzyRuleAntecedent();
  phAcidicAndEcLow->joinWithAND(ecLOW, ec_pumpon);
  FuzzyRuleConsequent *thenPhPumpOffAndEcPumpOn = new FuzzyRuleConsequent();
  thenPhPumpOffAndEcPumpOn->addOutput(ph_pumpoff);
  thenPhPumpOffAndEcPumpOn->addOutput(ec_pumpon);
  FuzzyRule *fuzzyRule1 = new FuzzyRule(1, phAcidicAndEcLow, thenPhPumpOffAndEcPumpOn);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // if ph acidic AND ecOPTIMAL THEN ph pump OFF and ec pump OFF
  FuzzyRuleAntecedent *phAcidicAndEcOptimal = new FuzzyRuleAntecedent();
  phAcidicAndEcOptimal->joinWithAND(ecOPTIMAL, ec_pumpoff);
  FuzzyRuleConsequent *thenPhPumpOffAndEcPumpOff = new FuzzyRuleConsequent();
  thenPhPumpOffAndEcPumpOff->addOutput(ph_pumpoff);
  thenPhPumpOffAndEcPumpOff->addOutput(ec_pumpoff);
  FuzzyRule *fuzzyRule2 = new FuzzyRule(2, phAcidicAndEcOptimal, thenPhPumpOffAndEcPumpOff);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // if ph acidic AND ecHIGH then ph pump OFF and ec pump OFF
  FuzzyRuleAntecedent *phAcidicAndEcHigh = new FuzzyRuleAntecedent();
  phAcidicAndEcHigh->joinWithAND(ecHIGH, ec_pumpoff);
  FuzzyRuleConsequent *thenPhPumpOffAndEcPumpOff2 = new FuzzyRuleConsequent();
  thenPhPumpOffAndEcPumpOff2->addOutput(ph_pumpoff);
  thenPhPumpOffAndEcPumpOff2->addOutput(ec_pumpoff);
  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, phAcidicAndEcHigh, thenPhPumpOffAndEcPumpOff2);
  fuzzy->addFuzzyRule(fuzzyRule3);

}

void loop()
{
  float input1 = 5.7;
  float input2 = 400;
  fuzzy->setInput(1, input1);
  fuzzy->setInput(2, input2);
  fuzzy->fuzzify();
  // Running the Defuzzification
  float output1 = fuzzy->defuzzify(1);
  float output2 = fuzzy->defuzzify(2);
  // Printing something
  Serial.print("\nInput [input1, input2]: ");
  Serial.print("\t[");
  Serial.print(input1);
  Serial.print("\t");
  Serial.print(input2);
  Serial.print("]");
  Serial.print("\nOutput pertinence: ");
  Serial.print("\t\t");
  Serial.print(ph_pumpoff->getPertinence());
  Serial.print("\t");
  Serial.print(ph_pumpon->getPertinence());
  Serial.print("\t");
  Serial.print(ec_pumpoff->getPertinence());
  Serial.print("\t");
  Serial.print(ec_pumpon->getPertinence());
  Serial.println();
  Serial.print("Output ph pump [0=off, 1.0=on]:");
  Serial.print("\t");
  Serial.print(output1);
  Serial.println();
  Serial.print("Output ec pump [0=off, 1.0=on]:");
  Serial.print(output2);
  Serial.println();
  Serial.print("\nInput pertinence [acid, base, eclow, ecoptimal, echigh]");
  Serial.print("\n[");
  Serial.print(phACIDIC->getPertinence());
  Serial.print("\t");
  Serial.print(phALKALINE->getPertinence());
  Serial.print("\t");
  Serial.print(ecLOW->getPertinence());
  Serial.print("\t");
  Serial.print(ecOPTIMAL->getPertinence());
  Serial.print("\t");
  Serial.print(ecHIGH->getPertinence());
  Serial.print("]");
  Serial.print("\n");

  // wait 12 seconds
  delay(12000);
}

Serial output


Input [input1, input2]: 	        [5.70	400.00]
Output pertinence: 		0.00	0.00	0.00	0.00
Output ph pump [0=off, 1.0=on]:	0.00
Output ec pump [0=off, 1.0=on]:   0.00

Input pertinence [acid, base, eclow, ecoptimal, echigh]
[0.60 1.00 0.00 0.00 0.00]

From Arbie: 2 or more fuzzyrule using same fuzzyrule consequent

i've got trouble at result of defuzzyfy when i have 2 or more fuzzyrule using same fuzzyrule consequent but different fuzzyantecedent...

but when i have 1 fuzzyrule using different fuzzyrule consequent it works..

why..??
example i' have 2 input
1.temperature have 5 variable
2.moisture have 3 Variable

and 1 output
1.time have 7 variable

so i must building 3x5 fuzzyrule = 15 fuzzyrule, there 12 fuzzyrule have same fuzzyconsequent... any idea to solve my problem..??

thank you.. for helping me :)

thank

DHT Temperature

#include <DHT.h>
#include <DHT_U.h>
#include <Fuzzy.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
Fuzzy *fuzzy = new Fuzzy();

void setup() {
Serial.begin(9600);
while(!Serial){}

Serial.println("Comfort Meter");
dht.begin();

//FuzzyInput
FuzzyInput *temperature = new FuzzyInput(1);

//FuzzySets - Input
FuzzySet *verycold = new FuzzySet(-10, 0, 0, 10);
temperature->addFuzzySet(verycold);
FuzzySet *cold = new FuzzySet(5, 15, 15, 25);
temperature->addFuzzySet(cold);
FuzzySet *normal = new FuzzySet(20, 30, 30, 40);
temperature->addFuzzySet(normal);
FuzzySet *hot = new FuzzySet(35, 40, 50, 55);
temperature->addFuzzySet(hot);
fuzzy->addFuzzyInput(temperature);

//FuzzyOutput
FuzzyOutput *valve = new FuzzyOutput(1);

//FuzzySets - Output
FuzzySet *ten = new FuzzySet(0, 15, 15, 30);
valve->addFuzzySet(ten);

FuzzySet *fifty = new FuzzySet(25, 40, 40, 55);
valve->addFuzzySet(fifty);

FuzzySet *seventy = new FuzzySet(50, 65, 65, 80);
valve->addFuzzySet(seventy);

FuzzySet *openvalve = new FuzzySet(75, 88, 88, 100);
valve->addFuzzySet(openvalve);
fuzzy->addFuzzyOutput(valve);

//Fuzzy Rules
FuzzyRuleAntecedent *iftempverycold = new FuzzyRuleAntecedent();
iftempverycold->joinSingle(verycold);
FuzzyRuleConsequent *thenvalveten = new FuzzyRuleConsequent();
thenvalveten->addOutput(ten);
FuzzyRule *rule1 = new FuzzyRule(1, iftempverycold, thenvalveten);
fuzzy->addFuzzyRule(rule1);

FuzzyRuleAntecedent *iftempcold = new FuzzyRuleAntecedent();
iftempcold->joinSingle(cold);
FuzzyRuleConsequent *thenvalvefifty = new FuzzyRuleConsequent();
thenvalvefifty->addOutput(fifty);
FuzzyRule *rule2 = new FuzzyRule(1, iftempcold, thenvalvefifty);
fuzzy->addFuzzyRule(rule2);

FuzzyRuleAntecedent *iftempnormal = new FuzzyRuleAntecedent();
iftempnormal->joinSingle(normal);
FuzzyRuleConsequent *thenvalveseventy = new FuzzyRuleConsequent();
thenvalveseventy->addOutput(seventy);
FuzzyRule *rule3 = new FuzzyRule(1, iftempnormal, thenvalveseventy);
fuzzy->addFuzzyRule(rule3);

FuzzyRuleAntecedent *iftemphot = new FuzzyRuleAntecedent();
iftemphot->joinSingle(hot);
FuzzyRuleConsequent *thenvalveopenvalve = new FuzzyRuleConsequent();
thenvalveopenvalve->addOutput(seventy);
FuzzyRule *rule4 = new FuzzyRule(1, iftemphot, thenvalveopenvalve);
fuzzy->addFuzzyRule(rule4);
}

void loop() {
// put your main code here, to run repeatedly:

//float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t)){
Serial.println("Failed to read from DHT");
}
else{

  Serial.println("Temperature:");
  fuzzy->setInput(1, t);
  fuzzy->fuzzify();
  float output = fuzzy->defuzzify(1);
  Serial.println("Valve open:");
  Serial.println(output); 
 
}
delay(12000);

}

Anyone can help me regarding with my output. I'm still a newbie with this library. I want to fetch temperature value then print the result using the given fuzzy rule.

Capture

No Output Crisp

Hi. This is a great library to use. It made simpler and efficient. I'm A newbie in Arduino. I'm triying to compile fuzzy of 3 inputs and 1 output. Input crisps shows no problem at all. But when it came to defuzzification, It Always shows zero. I'm using proteus to simulate, with potentio as the input data. Arduino UNO.

I used to check my code over and over but it looks no problem i think. dunno what happen.

Any solution? thanks :)

`
//------------------------------------------------------------------------------------ Library

#include <Fuzzy.h> // eFLL - A Fuzzy Library for Arduino and Embedded Systems
#include <Wire.h>
#include <DHT.h>;

//------------------------------------------------------------------------------------ Deklarasi Pin

#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int chk;
float hum;
float temp;
int relay = 13;
int soilpin = A1;

//------------------------------------------------------------------------------------ Membuat FIS

Fuzzy *fuzzy = new Fuzzy();

//------------------------------------------------------------------------------------ Membuat anggota MF dari MF input RH

// Anggota Fuzzy Input (Relative Humidity)
FuzzySet *low_RH = new FuzzySet(0, 25, 25, 50);
FuzzySet *average_RH = new FuzzySet(40, 50, 50, 60);
FuzzySet *high_RH = new FuzzySet(50, 75, 75, 100);

//------------------------------------------------------------------------------------ Membuat anggota MF dari MF input SRH.

// Anggota Fuzzy Input (Soil Moisture Relative Humidity)
FuzzySet *low_SRH = new FuzzySet(0, 25, 25, 50);
FuzzySet *average_SRH = new FuzzySet(40, 50, 50, 60);
FuzzySet *high_SRH = new FuzzySet(50, 75, 75, 100);

//------------------------------------------------------------------------------------ Membuat anggota MF dari MF input TEMP.

// Anggota Fuzzy Input (Temperature)
FuzzySet *low_temp = new FuzzySet(0, 11, 11, 22);
FuzzySet *average_temp = new FuzzySet(22, 24.5, 24.5, 27);
FuzzySet *high_temp = new FuzzySet(27, 31, 31, 35);

//------------------------------------------------------------------------------------ Membuat anggota MF dari MF output actions.

// Anggota Fuzzy Output (Actions)
FuzzySet *noact = new FuzzySet(0, 0.175, 0.175, 0.35);
FuzzySet *duadetik = new FuzzySet(0.35, 0.4525, 0.4525, 0.55);
FuzzySet *limadetik = new FuzzySet(0.55, 0.65, 0.65, 0.75);
FuzzySet *tujuhdetik = new FuzzySet(0.75, 0.875, 0.875, 1);

//------------------------------------------------------------------------------------ void setup.

void setup(){

Serial.begin(9600);
dht.begin();
Serial.begin(9600);
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);

//------------------------------------------------------------------------------------ Memasukkan anggota MF ke MF masing-masing.

// FuzzyInput Relative Humidity

FuzzyInput *RH = new FuzzyInput(1);

RH->addFuzzySet(low_RH);
RH->addFuzzySet(average_RH);
RH->addFuzzySet(high_RH);

fuzzy->addFuzzyInput(RH);

//------------------------------------------------------------------------------------ Memasukkan anggota MF ke MF masing-masing.

// FuzzyInput Soil Moisture Relative Humidity

FuzzyInput *SRH = new FuzzyInput(2);

SRH->addFuzzySet(low_SRH);
SRH->addFuzzySet(average_SRH);
SRH->addFuzzySet(high_SRH);

fuzzy->addFuzzyInput(SRH);

//------------------------------------------------------------------------------------ Memasukkan anggota MF ke MF masing-masing.

// FuzzyInput Temperature

FuzzyInput *temp = new FuzzyInput(3);

temp->addFuzzySet(low_temp);
temp->addFuzzySet(average_temp);
temp->addFuzzySet(high_temp);

fuzzy->addFuzzyInput(temp);

//------------------------------------------------------------------------------------ Memasukkan anggota MF ke MF masing-masing.

// Fuzzy Output Actions

FuzzyOutput *actions = new FuzzyOutput(1);

actions->addFuzzySet(noact);
actions->addFuzzySet(duadetik);
actions->addFuzzySet(limadetik);
actions->addFuzzySet(tujuhdetik);

fuzzy->addFuzzyOutput(actions);

//------------------------------------------------------------------------------------ Membuat aturan fuzzy (Fuzzy Rule)

// Antecedent = Penggabungan anggota MF dengan fungsi AND atau OR.
// Consequent = Konsekuensi atau output yang akan dihasilkan dari Antecedent yang sudah dibuat.
// Contoh = Jika Antecedent "Low1 AND Low2" maka Consequent adalah "min"

//------------------------------------------------------------------------------------ Deklarasi Antecedent

FuzzyRuleAntecedent *lowRHlowSRH = new FuzzyRuleAntecedent();
lowRHlowSRH->joinWithAND(low_RH, low_SRH);

FuzzyRuleAntecedent *averageRHaverageSRH = new FuzzyRuleAntecedent();
lowRHlowSRH->joinWithAND(average_RH, average_SRH);

FuzzyRuleAntecedent *highRHhighSRH = new FuzzyRuleAntecedent();
lowRHlowSRH->joinWithAND(high_RH, high_SRH);

FuzzyRuleAntecedent *lowTEMP = new FuzzyRuleAntecedent();
lowTEMP->joinSingle(low_temp);

FuzzyRuleAntecedent *averageTEMP = new FuzzyRuleAntecedent();
lowTEMP->joinSingle(average_temp);

FuzzyRuleAntecedent *highTEMP = new FuzzyRuleAntecedent();
lowTEMP->joinSingle(high_temp);

//------------------------------------------------------------------------------------ Deklarasi Consequent

FuzzyRuleConsequent *thenActduadetik = new FuzzyRuleConsequent();
thenActduadetik->addOutput(duadetik);

FuzzyRuleConsequent *thenActlimadetik = new FuzzyRuleConsequent();
thenActlimadetik->addOutput(limadetik);

FuzzyRuleConsequent *thenActtujuhdetik = new FuzzyRuleConsequent();
thenActlimadetik->addOutput(tujuhdetik);

FuzzyRuleConsequent *thenNoAct = new FuzzyRuleConsequent();
thenActduadetik->addOutput(noact);

//------------------------------------------------------------------------------------ Rule 1.

FuzzyRuleAntecedent *lowRHlowSRHlowTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(lowRHlowSRH, lowTEMP);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, lowRHlowSRHlowTEMP, thenActduadetik);
fuzzy->addFuzzyRule(fuzzyRule1);

//------------------------------------------------------------------------------------ Rule 2.

FuzzyRuleAntecedent *lowRHlowSRHaverageTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(lowRHlowSRH, averageTEMP);

FuzzyRule *fuzzyRule2 = new FuzzyRule(2, lowRHlowSRHaverageTEMP, thenActlimadetik);
fuzzy->addFuzzyRule(fuzzyRule2);

//------------------------------------------------------------------------------------ Rule 3.

FuzzyRuleAntecedent *lowRHlowSRHhighTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(lowRHlowSRH, highTEMP);

FuzzyRule *fuzzyRule3 = new FuzzyRule(3, lowRHlowSRHhighTEMP, thenActtujuhdetik);
fuzzy->addFuzzyRule(fuzzyRule3);

//------------------------------------------------------------------------------------ Rule 4.

FuzzyRuleAntecedent *averageRHaverageSRHlowTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(averageRHaverageSRH, lowTEMP);

FuzzyRule *fuzzyRule4 = new FuzzyRule(4, averageRHaverageSRH, thenActduadetik);
fuzzy->addFuzzyRule(fuzzyRule4);

//------------------------------------------------------------------------------------ Rule 5.

FuzzyRuleAntecedent *averageRHaverageSRHaverageTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(averageRHaverageSRH, averageTEMP);

FuzzyRule *fuzzyRule5 = new FuzzyRule(5, averageRHaverageSRHaverageTEMP, thenActlimadetik);
fuzzy->addFuzzyRule(fuzzyRule5);

//------------------------------------------------------------------------------------ Rule 6.

FuzzyRuleAntecedent *averageRHaverageSRHhighTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(averageRHaverageSRH, highTEMP);

FuzzyRule *fuzzyRule6 = new FuzzyRule(6, averageRHaverageSRHhighTEMP, thenActtujuhdetik);
fuzzy->addFuzzyRule(fuzzyRule6);

//------------------------------------------------------------------------------------ Rule 7.

FuzzyRuleAntecedent *highRHhighSRHlowTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(highRHhighSRH, lowTEMP);

FuzzyRule *fuzzyRule7 = new FuzzyRule(7, highRHhighSRHlowTEMP, thenNoAct);
fuzzy->addFuzzyRule(fuzzyRule7);

//------------------------------------------------------------------------------------ Rule 8.

FuzzyRuleAntecedent *highRHhighSRHaverageTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(highRHhighSRH, averageTEMP);

FuzzyRule *fuzzyRule8 = new FuzzyRule(8, highRHhighSRHaverageTEMP, thenActduadetik);
fuzzy->addFuzzyRule(fuzzyRule8);

//------------------------------------------------------------------------------------ Rule 9.

FuzzyRuleAntecedent *highRHhighSRHhighTEMP = new FuzzyRuleAntecedent();
lowRHlowSRHlowTEMP->joinWithAND(highRHhighSRH, highTEMP);

FuzzyRule *fuzzyRule9 = new FuzzyRule(9, highRHhighSRHhighTEMP, thenActlimadetik);
fuzzy->addFuzzyRule(fuzzyRule9);

}

//------------------------------------------------------------------------------------ void loop

void loop()
{

//------------------------------------------------------------------------------------ Membaca input data

float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

int inputRH = (h);
int inputSRH = map(analogRead(soilpin), 0, 1023, 10, 100);
int inputTEMP = (t);

//------------------------------------------------------------------------------------ Menampilkan ke Serial

String humtext = "RH (%) : ";
String humprint = humtext + inputRH ; //---------------------------------------------------------- Print DHT Relative Humidity
Serial.println(humprint);

String soiltext = "Soil RH (%) : ";
String soilprint = soiltext + inputSRH ; //---------------------------------------------------------- Print SOIL Relative Humidity
Serial.println(soilprint);

String temptext = "TEMP (C) : ";
String tempprint = temptext + inputTEMP ; //---------------------------------------------------------- Print DHT Temperature
Serial.println(tempprint);

//------------------------------------------------------------------------------------ Deklarasi input fuzzy

fuzzy->setInput(1, inputRH);
fuzzy->setInput(2, inputSRH);
fuzzy->setInput(3, inputTEMP);

//------------------------------------------------------------------------------------ Fuzzifikasi dan Menampilkan ke serial monitor

fuzzy->fuzzify();
float outputfuzzy = fuzzy->defuzzify(1);

//------------------------------------------------------------------------------------ Menampilkan derajat keanggotaan dari anggota MF input RH

Serial.println("Input: ");
Serial.print("\tRH: low-> ");
Serial.print(low_RH->getPertinence());
Serial.print(", average-> ");
Serial.print(average_RH->getPertinence());
Serial.print(", high-> ");
Serial.println(high_RH->getPertinence());

//------------------------------------------------------------------------------------ Menampilkan derajat keanggotaan dari anggota MF input SRH

Serial.print("\tSRH: low-> ");
Serial.print(low_SRH->getPertinence());
Serial.print(", average-> ");
Serial.print(average_SRH->getPertinence());
Serial.print(", high-> ");
Serial.println(high_SRH->getPertinence());

//------------------------------------------------------------------------------------ Menampilkan derajat keanggotaan dari anggota MF input TEMP

Serial.print("\tTEMP: low-> ");
Serial.print(low_temp->getPertinence());
Serial.print(", average-> ");
Serial.print(average_temp->getPertinence());
Serial.print(", high-> ");
Serial.println(high_temp->getPertinence());

//------------------------------------------------------------------------------------ Proses Fuzzifikasi

//------------------------------------------------------------------------------------ Menampilkan derajat keanggotaan dari anggota MF output ACTIONS

Serial.println("Output: ");

Serial.println("\tACTIONS: ");
Serial.print("noact->-> ");
Serial.print(noact->getPertinence());
Serial.print(", duadetik-> ");
Serial.print(duadetik->getPertinence());
Serial.print(", limadetik-> ");
Serial.print(limadetik->getPertinence());
Serial.print(", tujuhdetik-> ");
Serial.print(tujuhdetik->getPertinence());

Serial.println("Hasil Fuzzifikasi: ");
Serial.print("\t\t\tACTIONS: ");
Serial.print(outputfuzzy);
delay(60000);
}
`

IMG-20200601-WA0010

The Library works up to the 4th Rule

Hello,
The library works very well up to the 4th rule. When the 5th is added the code stops working. No errors have been appeared during compiling or uploading. Nothing appear in the Monitor Display but if I delete all rules leaving only 4 rules the code works again.

Problem with reach maximal defined value from output set - arduino_simple_sample.ino and not only

Hello,
I can't reach max defined value from output rule - both in my or Your codes placed on github.
For Instance in your sample: arduino_simple_sample.ino please change following line to:
int input = 80;
always will be returned 40 instead of 50. Maximum value is 50 in output set:
FuzzySet *fast = new FuzzySet(30, 40, 40, 50);
but and I can't reach max defined value.
Maybe mistake is on my side or in library
Screenshot 2020-01-20 at 08 48 02
?

Having problem with defuzzification.

I wrote this code and everything seems fine unless the output value. It can be seen that the fired outputs and their values are correct but the output values seem not right.
`
#include <Fuzzy.h>
// For scope, instantiate all objects you will need to access in loop()
// It may be just one Fuzzy, but for demonstration, this sample will print all FuzzySet pertinence
// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// Fuzzy Membership Function names

// Fuzzy Membership Function for input number 1
FuzzySet *NBI1 = new FuzzySet(-2, -2, -1, -0.5);
FuzzySet *NMI1 = new FuzzySet(-1, -0.5, -0.5, 0);
FuzzySet *ZEI1 = new FuzzySet(-0.5, 0, 0, 0.5);
FuzzySet *PMI1 = new FuzzySet(0, 0.5, 0.5, 1);
FuzzySet *PBI1 = new FuzzySet(0.5, 1, 2, 2);

// Fuzzy Membership Function for input number 2
FuzzySet *NBI2 = new FuzzySet(-2, -2, -1, -0.5);
FuzzySet *NMI2 = new FuzzySet(-1, -0.5, -0.5, 0);
FuzzySet *ZEI2 = new FuzzySet(-0.5, 0, 0, 0.5);
FuzzySet *PMI2 = new FuzzySet(0, 0.5, 0.5, 1);
FuzzySet *PBI2 = new FuzzySet(0.5, 1, 2, 2);

// Fuzzy Membership Function for output number 1
FuzzySet *NBO1 = new FuzzySet(-2, -2, -1, -0.5);
FuzzySet *NMO1 = new FuzzySet(-1, -0.5, -0.5, 0);
FuzzySet *ZEO1 = new FuzzySet(-0.5, 0, 0, 0.5);
FuzzySet *PMO1 = new FuzzySet(0, 0.5, 0.5, 1);
FuzzySet *PBO1 = new FuzzySet(0.5, 1, 2, 2);

void setup()
{
// Set the Serial output
Serial.begin(115200);
// Set a random seed
randomSeed(analogRead(0));
// Every setup must occur in the function setup()

FuzzyInput *Input_1 = new FuzzyInput(1);
Input_1->addFuzzySet(NBI1);
Input_1->addFuzzySet(NMI1);
Input_1->addFuzzySet(ZEI1);
Input_1->addFuzzySet(PMI1);
Input_1->addFuzzySet(PBI1);
fuzzy->addFuzzyInput(Input_1);

FuzzyInput *Input_2 = new FuzzyInput(2);
Input_2->addFuzzySet(NBI2);
Input_2->addFuzzySet(NMI2);
Input_2->addFuzzySet(ZEI2);
Input_2->addFuzzySet(PMI2);
Input_2->addFuzzySet(PBI2);
fuzzy->addFuzzyInput(Input_2);

FuzzyOutput *Output_1 = new FuzzyOutput(1);
Output_1->addFuzzySet(NBO1);

FuzzyRuleConsequent *THEN_Output_1_NBO1 = new FuzzyRuleConsequent();
THEN_Output_1_NBO1->addOutput(NBO1);

Output_1->addFuzzySet(NMO1);

FuzzyRuleConsequent *THEN_Output_1_NMO1 = new FuzzyRuleConsequent();
THEN_Output_1_NMO1->addOutput(NMO1);

Output_1->addFuzzySet(ZEO1);

FuzzyRuleConsequent *THEN_Output_1_ZEO1 = new FuzzyRuleConsequent();
THEN_Output_1_ZEO1->addOutput(ZEO1);

Output_1->addFuzzySet(PMO1);

FuzzyRuleConsequent *THEN_Output_1_PMO1 = new FuzzyRuleConsequent();
THEN_Output_1_PMO1->addOutput(PMO1);

Output_1->addFuzzySet(PBO1);

FuzzyRuleConsequent *THEN_Output_1_PBO1 = new FuzzyRuleConsequent();
THEN_Output_1_PBO1->addOutput(PBO1);

fuzzy->addFuzzyOutput(Output_1);

// Add following rules inside setup()

// Building FuzzyRule number: 1
FuzzyRuleAntecedent *IFIn1_NBI1_AND_In2_NBI2 = new FuzzyRuleAntecedent();
IFIn1_NBI1_AND_In2_NBI2->joinWithAND(NBI1,NBI2);
FuzzyRule *fuzzyRule_1 = new FuzzyRule(1,IFIn1_NBI1_AND_In2_NBI2, THEN_Output_1_NBO1);
fuzzy->addFuzzyRule(fuzzyRule_1);

// Building FuzzyRule number: 2
FuzzyRuleAntecedent *IFIn1_NBI1_AND_In2_NMI2 = new FuzzyRuleAntecedent();
IFIn1_NBI1_AND_In2_NMI2->joinWithAND(NBI1,NMI2);
FuzzyRule *fuzzyRule_2 = new FuzzyRule(2,IFIn1_NBI1_AND_In2_NMI2, THEN_Output_1_NBO1);
fuzzy->addFuzzyRule(fuzzyRule_2);

// Building FuzzyRule number: 3
FuzzyRuleAntecedent *IFIn1_NBI1_AND_In2_ZEI2 = new FuzzyRuleAntecedent();
IFIn1_NBI1_AND_In2_ZEI2->joinWithAND(NBI1,ZEI2);
FuzzyRule *fuzzyRule_3 = new FuzzyRule(3,IFIn1_NBI1_AND_In2_ZEI2, THEN_Output_1_NBO1);
fuzzy->addFuzzyRule(fuzzyRule_3);

// Building FuzzyRule number: 4
FuzzyRuleAntecedent *IFIn1_NBI1_AND_In2_PMI2 = new FuzzyRuleAntecedent();
IFIn1_NBI1_AND_In2_PMI2->joinWithAND(NBI1,PMI2);
FuzzyRule *fuzzyRule_4 = new FuzzyRule(4,IFIn1_NBI1_AND_In2_PMI2, THEN_Output_1_NMO1);
fuzzy->addFuzzyRule(fuzzyRule_4);

// Building FuzzyRule number: 5
FuzzyRuleAntecedent *IFIn1_NBI1_AND_In2_PBI2 = new FuzzyRuleAntecedent();
IFIn1_NBI1_AND_In2_PBI2->joinWithAND(NBI1,PBI2);
FuzzyRule *fuzzyRule_5 = new FuzzyRule(5,IFIn1_NBI1_AND_In2_PBI2, THEN_Output_1_ZEO1);
fuzzy->addFuzzyRule(fuzzyRule_5);

// Building FuzzyRule number: 6
FuzzyRuleAntecedent *IFIn1_NMI1_AND_In2_NBI2 = new FuzzyRuleAntecedent();
IFIn1_NMI1_AND_In2_NBI2->joinWithAND(NMI1,NBI2);
FuzzyRule *fuzzyRule_6 = new FuzzyRule(6,IFIn1_NMI1_AND_In2_NBI2, THEN_Output_1_NBO1);
fuzzy->addFuzzyRule(fuzzyRule_6);

// Building FuzzyRule number: 7
FuzzyRuleAntecedent *IFIn1_NMI1_AND_In2_NMI2 = new FuzzyRuleAntecedent();
IFIn1_NMI1_AND_In2_NMI2->joinWithAND(NMI1,NMI2);
FuzzyRule *fuzzyRule_7 = new FuzzyRule(7,IFIn1_NMI1_AND_In2_NMI2, THEN_Output_1_NBO1);
fuzzy->addFuzzyRule(fuzzyRule_7);

// Building FuzzyRule number: 8
FuzzyRuleAntecedent *IFIn1_NMI1_AND_In2_ZEI2 = new FuzzyRuleAntecedent();
IFIn1_NMI1_AND_In2_ZEI2->joinWithAND(NMI1,ZEI2);
FuzzyRule *fuzzyRule_8 = new FuzzyRule(8,IFIn1_NMI1_AND_In2_ZEI2, THEN_Output_1_NMO1);
fuzzy->addFuzzyRule(fuzzyRule_8);

// Building FuzzyRule number: 9
FuzzyRuleAntecedent *IFIn1_NMI1_AND_In2_PMI2 = new FuzzyRuleAntecedent();
IFIn1_NMI1_AND_In2_PMI2->joinWithAND(NMI1,PMI2);
FuzzyRule *fuzzyRule_9 = new FuzzyRule(9,IFIn1_NMI1_AND_In2_PMI2, THEN_Output_1_ZEO1);
fuzzy->addFuzzyRule(fuzzyRule_9);

// Building FuzzyRule number: 10
FuzzyRuleAntecedent *IFIn1_NMI1_AND_In2_PBI2 = new FuzzyRuleAntecedent();
IFIn1_NMI1_AND_In2_PBI2->joinWithAND(NMI1,PBI2);
FuzzyRule *fuzzyRule_10 = new FuzzyRule(10,IFIn1_NMI1_AND_In2_PBI2, THEN_Output_1_PMO1);
fuzzy->addFuzzyRule(fuzzyRule_10);

// Building FuzzyRule number: 11
FuzzyRuleAntecedent *IFIn1_ZEI1_AND_In2_NMI2 = new FuzzyRuleAntecedent();
IFIn1_ZEI1_AND_In2_NMI2->joinWithAND(ZEI1,NMI2);
FuzzyRule *fuzzyRule_11 = new FuzzyRule(11,IFIn1_ZEI1_AND_In2_NMI2, THEN_Output_1_NMO1);
fuzzy->addFuzzyRule(fuzzyRule_11);

// Building FuzzyRule number: 12
FuzzyRuleAntecedent *IFIn1_ZEI1_AND_In2_ZEI2 = new FuzzyRuleAntecedent();
IFIn1_ZEI1_AND_In2_ZEI2->joinWithAND(ZEI1,ZEI2);
FuzzyRule *fuzzyRule_12 = new FuzzyRule(12,IFIn1_ZEI1_AND_In2_ZEI2, THEN_Output_1_ZEO1);
fuzzy->addFuzzyRule(fuzzyRule_12);

// Building FuzzyRule number: 13
FuzzyRuleAntecedent *IFIn1_ZEI1_AND_In2_PMI2 = new FuzzyRuleAntecedent();
IFIn1_ZEI1_AND_In2_PMI2->joinWithAND(ZEI1,PMI2);
FuzzyRule *fuzzyRule_13 = new FuzzyRule(13,IFIn1_ZEI1_AND_In2_PMI2, THEN_Output_1_PMO1);
fuzzy->addFuzzyRule(fuzzyRule_13);

// Building FuzzyRule number: 14
FuzzyRuleAntecedent *IFIn1_ZEI1_AND_In2_PBI2 = new FuzzyRuleAntecedent();
IFIn1_ZEI1_AND_In2_PBI2->joinWithAND(ZEI1,PBI2);
FuzzyRule *fuzzyRule_14 = new FuzzyRule(14,IFIn1_ZEI1_AND_In2_PBI2, THEN_Output_1_PBO1);
fuzzy->addFuzzyRule(fuzzyRule_14);

// Building FuzzyRule number: 15
FuzzyRuleAntecedent *IFIn1_PMI1_AND_In2_NBI2 = new FuzzyRuleAntecedent();
IFIn1_PMI1_AND_In2_NBI2->joinWithAND(PMI1,NBI2);
FuzzyRule *fuzzyRule_15 = new FuzzyRule(15,IFIn1_PMI1_AND_In2_NBI2, THEN_Output_1_NMO1);
fuzzy->addFuzzyRule(fuzzyRule_15);

// Building FuzzyRule number: 16
FuzzyRuleAntecedent *IFIn1_PMI1_AND_In2_NMI2 = new FuzzyRuleAntecedent();
IFIn1_PMI1_AND_In2_NMI2->joinWithAND(PMI1,NMI2);
FuzzyRule *fuzzyRule_16 = new FuzzyRule(16,IFIn1_PMI1_AND_In2_NMI2, THEN_Output_1_ZEO1);
fuzzy->addFuzzyRule(fuzzyRule_16);

// Building FuzzyRule number: 17
FuzzyRuleAntecedent *IFIn1_PMI1_AND_In2_ZEI2 = new FuzzyRuleAntecedent();
IFIn1_PMI1_AND_In2_ZEI2->joinWithAND(PMI1,ZEI2);
FuzzyRule *fuzzyRule_17 = new FuzzyRule(17,IFIn1_PMI1_AND_In2_ZEI2, THEN_Output_1_PMO1);
fuzzy->addFuzzyRule(fuzzyRule_17);

// Building FuzzyRule number: 18
FuzzyRuleAntecedent *IFIn1_PMI1_AND_In2_PMI2 = new FuzzyRuleAntecedent();
IFIn1_PMI1_AND_In2_PMI2->joinWithAND(PMI1,PMI2);
FuzzyRule *fuzzyRule_18 = new FuzzyRule(18,IFIn1_PMI1_AND_In2_PMI2, THEN_Output_1_PBO1);
fuzzy->addFuzzyRule(fuzzyRule_18);

// Building FuzzyRule number: 19
FuzzyRuleAntecedent *IFIn1_PMI1_AND_In2_PBI2 = new FuzzyRuleAntecedent();
IFIn1_PMI1_AND_In2_PBI2->joinWithAND(PMI1,PBI2);
FuzzyRule *fuzzyRule_19 = new FuzzyRule(19,IFIn1_PMI1_AND_In2_PBI2, THEN_Output_1_PBO1);
fuzzy->addFuzzyRule(fuzzyRule_19);

// Building FuzzyRule number: 20
FuzzyRuleAntecedent *IFIn1_PBI1_AND_In2_NBI2 = new FuzzyRuleAntecedent();
IFIn1_PBI1_AND_In2_NBI2->joinWithAND(PBI1,NBI2);
FuzzyRule *fuzzyRule_20 = new FuzzyRule(20,IFIn1_PBI1_AND_In2_NBI2, THEN_Output_1_ZEO1);
fuzzy->addFuzzyRule(fuzzyRule_20);

// Building FuzzyRule number: 21
FuzzyRuleAntecedent *IFIn1_PBI1_AND_In2_NMI2 = new FuzzyRuleAntecedent();
IFIn1_PBI1_AND_In2_NMI2->joinWithAND(PBI1,NMI2);
FuzzyRule *fuzzyRule_21 = new FuzzyRule(21,IFIn1_PBI1_AND_In2_NMI2, THEN_Output_1_PMO1);
fuzzy->addFuzzyRule(fuzzyRule_21);

// Building FuzzyRule number: 22
FuzzyRuleAntecedent *IFIn1_PBI1_AND_In2_ZEI2 = new FuzzyRuleAntecedent();
IFIn1_PBI1_AND_In2_ZEI2->joinWithAND(PBI1,ZEI2);
FuzzyRule *fuzzyRule_22 = new FuzzyRule(22,IFIn1_PBI1_AND_In2_ZEI2, THEN_Output_1_PBO1);
fuzzy->addFuzzyRule(fuzzyRule_22);

// Building FuzzyRule number: 23
FuzzyRuleAntecedent *IFIn1_PBI1_AND_In2_PMI2 = new FuzzyRuleAntecedent();
IFIn1_PBI1_AND_In2_PMI2->joinWithAND(PBI1,PMI2);
FuzzyRule *fuzzyRule_23 = new FuzzyRule(23,IFIn1_PBI1_AND_In2_PMI2, THEN_Output_1_PBO1);
fuzzy->addFuzzyRule(fuzzyRule_23);

// Building FuzzyRule number: 24
FuzzyRuleAntecedent *IFIn1_PBI1_AND_In2_PBI2 = new FuzzyRuleAntecedent();
IFIn1_PBI1_AND_In2_PBI2->joinWithAND(PBI1,PBI2);
FuzzyRule *fuzzyRule_24 = new FuzzyRule(24,IFIn1_PBI1_AND_In2_PBI2, THEN_Output_1_PBO1);
fuzzy->addFuzzyRule(fuzzyRule_24);

// Building FuzzyRule number: 25
FuzzyRuleAntecedent *IFIn1_ZEI1_AND_In2_NBI2 = new FuzzyRuleAntecedent();
IFIn1_ZEI1_AND_In2_NBI2->joinWithAND(ZEI1,NBI2);
FuzzyRule *fuzzyRule_25 = new FuzzyRule(25,IFIn1_ZEI1_AND_In2_NBI2, THEN_Output_1_NBO1);
fuzzy->addFuzzyRule(fuzzyRule_25);

}
void loop() {
// add your codes here

// This part is for testing your code
float input_1 = -0.241;
fuzzy->setInput(1, input_1);
Serial.print("input1 = "); Serial.println(input_1);

float input_2 = 0.672;
fuzzy->setInput(2, input_2);
Serial.print("input1 = "); Serial.println(input_2);

fuzzy->fuzzify();

Serial.println("Inputs: ");
Serial.print("input1 : ");
Serial.print(" NBI1->");
Serial.print(NBI1->getPertinence());
Serial.print(" NMI1->");
Serial.print(NMI1->getPertinence());
Serial.print(" ZEI1->");
Serial.print(ZEI1->getPertinence());
Serial.print(" PMI1->");
Serial.print(PMI1->getPertinence());
Serial.print(" PBI1->");
Serial.print(PBI1->getPertinence());
Serial.println(" ");

Serial.print("input2 : ");
Serial.print(" NBI2->");
Serial.print(NBI2->getPertinence());
Serial.print(" NMI2->");
Serial.print(NMI2->getPertinence());
Serial.print(" ZEI2->");
Serial.print(ZEI2->getPertinence());
Serial.print(" PMI2->");
Serial.print(PMI2->getPertinence());
Serial.print(" PBI2->");
Serial.print(PBI2->getPertinence());
Serial.println(" ");

Serial.println("Outputs: ");
float output_1 = fuzzy->defuzzify(1);
Serial.print(" NBO1->");
Serial.print(NBO1->getPertinence());
Serial.print(" NMO1->");
Serial.print(NMO1->getPertinence());
Serial.print(" ZEO1->");
Serial.print(ZEO1->getPertinence());
Serial.print(" PMO1->");
Serial.print(PMO1->getPertinence());
Serial.print(" PBO1->");
Serial.print(PBO1->getPertinence());
Serial.println(" ");

Serial.println("=========== Results: ===========");
Serial.print("output1: "); Serial.println(output_1);

Serial.println("======== Check Fired Rules ========");
for(int i=1; i<25; i++){
if (fuzzy->isFiredRule(i) ==1){
Serial.print("Rule number ("); Serial.print(i); Serial.println(") is fired.");
}
}
delay(5000);
}
`

Also, this is the output:

input1 = -0.24
input1 = 0.67
Inputs:
input1 : NBI1->0.00 NMI1->0.48 ZEI1->0.52 PMI1->0.00 PBI1->0.00
input2 : NBI2->0.00 NMI2->0.00 ZEI2->0.00 PMI2->0.66 PBI2->0.34
Outputs:
NBO1->0.00 NMO1->0.00 ZEO1->0.48 PMO1->0.52 PBO1->0.34
=========== Results: ===========
output1: -0.06
======== Check Fired Rules ========
Rule number (9) is fired.
Rule number (10) is fired.
Rule number (13) is fired.
Rule number (14) is fired.

Defuzzify output is unexpected

Using the library for temperature control and ran into this issue. The rule fires and the pertinence for the rule is 1.0 yet the value returned from defuzzify is 0.0 - I would expect it to be 1 given the output set is a singleton of 1. I've simplified the input and output sets and rules down to the following and still get the same results:

FuzzyInput *e = new FuzzyInput(1);
FuzzySet *PL = new FuzzySet(6.5, 10, 12, 12);
e->addFuzzySet(PL);
fuzzy->addFuzzyInput(e);

FuzzyOutput *adjust = new FuzzyOutput(1);
FuzzySet *plus100 = new FuzzySet(1, 1, 1, 1);
adjust->addFuzzySet(plus100);
fuzzy->addFuzzyOutput(adjust);

FuzzyRuleAntecedent *PLg = new FuzzyRuleAntecedent();
PLg->joinSingle(PL);
FuzzyRuleConsequent *p100 = new FuzzyRuleConsequent();
p100->addOutput(plus100);

FuzzyRule *FR40 = new FuzzyRule(40, PLg, p100);
fuzzy->addFuzzyRule(FR40);

tError = 11; 
fuzzy->setInput(1, tError);
fuzzy->fuzzify();
float adjustmentFactor = fuzzy->defuzzify(1);

bool wasRuleFired = fuzzy->isFiredRule(40); 
float pert = plus100 -> getPertinence(); 

As noted above, wasRuleFired returns TRUE, and pert=1.0. However, adjustmentFactor returns 0.0. I've modeled this in Octave with fuzzy-logic-toolkit and it works as expected giving an output of 1 with the above conditions.

Of note, changing only the plus100 FuzzySet to the following:

FuzzySet *plus100 = new FuzzySet(.99, 1, 1.01, 1.01);

I get the expected value for adjustmentFactor (1 or 1.01). It appears there is something about using a singleton in the output set and/or consequent of a rule that is problematic.

Thanks for your library and your time to evaluate this.

float output = fuzzy->defuzzyfy(1);

defuzzyfy should probably be defuzzify in the simple arduino example. Sorry for creating issue, should have just forked->pull request immediately. I am still a noob at Git. Sorry again.

C version of fuzzy lab

Hi, I am trying to use stm32 to build a fuzzy control system, so is there any C version of your lib for stm32? Thanks!

Fuzzy Rule not fired

i have 2 fuzzies
first fuzzy is running correctly, but the second fuzzy sometimes Rule not fired.
image

Strange Outptut

Hi AJ,

I'm using the Fuzzy.h code that you defined for a project, but my output is strange. Are you able to check my code?

#include <Fuzzy.h>

// For scope, instantiate all objects you will need to access in loop()
// It may be just one Fuzzy, but for demonstration, this sample will print
// all FuzzySet pertinence

// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// setting up the values our input variables can take

//Inputs (hight, medium, Low) defined in Matlab
// FuzzyInput - Ambient Temperature Inputs
FuzzySet *lowAT = new FuzzySet(0, 20, 20, 40);
FuzzySet *mediumAT = new FuzzySet(30, 50, 50, 70);
FuzzySet *highAT = new FuzzySet(60, 80, 100, 100);

// FuzzyInput - Light Inputs
FuzzySet *lowL = new FuzzySet(5, 15, 20, 25);
FuzzySet *highL = new FuzzySet(20, 30, 30, 50);

// FuzzyInput - Time Inpits
FuzzySet *lowT = new FuzzySet(0, 4, 8, 12);
FuzzySet *highT = new FuzzySet(12, 16, 20, 24);

//Outpits (open or close) defined in Matlab
// FuzzyOutput
FuzzySet *closeBlinds = new FuzzySet(0, 20, 20, 40);
FuzzySet *openBlinds = new FuzzySet(30, 50, 50, 70);

void setup()
{
// Set the Serial output
Serial.begin(9600);
// Set a random seed
randomSeed(analogRead(0));

// Every setup must occur in the function setup()

// FuzzyInput - Declaring our input variables from above with the inputs
FuzzyInput *ambientTemp = new FuzzyInput(1);

ambientTemp->addFuzzySet(lowAT);
ambientTemp->addFuzzySet(mediumAT);
ambientTemp->addFuzzySet(highAT);
fuzzy->addFuzzyInput(ambientTemp);

// FuzzyInput
FuzzyInput *light = new FuzzyInput(2);

light->addFuzzySet(lowL);
light->addFuzzySet(highL);
fuzzy->addFuzzyInput(light);

// FuzzyInput
FuzzyInput *timeOfDay = new FuzzyInput(3);

timeOfDay->addFuzzySet(lowT);
timeOfDay->addFuzzySet(highT);
fuzzy->addFuzzyInput(timeOfDay);

// FuzzyOutput
FuzzyOutput *resultBlinds = new FuzzyOutput(1);

resultBlinds->addFuzzySet(openBlinds);
resultBlinds->addFuzzySet(closeBlinds);

fuzzy->addFuzzyOutput(resultBlinds);

// Building FuzzyRules - Defined on Matlab

//First Rule
FuzzyRuleAntecedent *ifAmbientTempLowAndLightHigh = new FuzzyRuleAntecedent();
ifAmbientTempLowAndLightHigh->joinWithAND(lowAT, highL);

FuzzyRuleConsequent *thenOpenBlinds = new FuzzyRuleConsequent();
thenOpenBlinds->addOutput(openBlinds);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifAmbientTempLowAndLightHigh, thenOpenBlinds);
fuzzy->addFuzzyRule(fuzzyRule1);

//Second Rule
FuzzyRuleAntecedent *ifAmbientTempHighAndLightLow = new FuzzyRuleAntecedent();
ifAmbientTempHighAndLightLow->joinWithAND(highAT, lowL);

FuzzyRuleConsequent *thenCloseBlinds = new FuzzyRuleConsequent();
thenCloseBlinds->addOutput(closeBlinds);

FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifAmbientTempHighAndLightLow, thenCloseBlinds);
fuzzy->addFuzzyRule(fuzzyRule2);

//Third Rule
FuzzyRuleAntecedent *ifAmbientTempMediumAndLightHigh = new FuzzyRuleAntecedent();
ifAmbientTempMediumAndLightHigh->joinWithAND(mediumAT, highL);

// FuzzyRuleConsequent *thenCloseBlinds = new FuzzyRuleConsequent();
thenCloseBlinds->addOutput(closeBlinds);

FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifAmbientTempMediumAndLightHigh, thenCloseBlinds);
fuzzy->addFuzzyRule(fuzzyRule3);
}

void loop()
{
// get random entrances
int input1 = random(0, 100);
int input2 = random(0, 70);
int input3 = random(0, 24);

Serial.println("\n\n\nEntrance: ");
Serial.print("\t\t\tAmbient Temperature: ");
Serial.print(input1);
Serial.print(", Light: ");
Serial.print(input2);
Serial.print(", and Time: ");
Serial.println(input3);

fuzzy->setInput(1, input1);
fuzzy->setInput(2, input2);
fuzzy->setInput(3, input3);

fuzzy->fuzzify();

Serial.println("Input: ");
Serial.print("\tAmbient Temperature: low-> ");
Serial.print(lowAT ->getPertinence());
Serial.print(", medium-> ");
Serial.print(mediumAT->getPertinence());
Serial.print(", high-> ");
Serial.println(highAT->getPertinence());

Serial.print("\tLight: low-> ");
Serial.print(lowL->getPertinence());
Serial.print(", high-> ");
Serial.print(highL->getPertinence());

Serial.print("\tTime: Cold-> ");
Serial.print(highT->getPertinence());
Serial.print(", high-> ");
Serial.print(lowT->getPertinence());
Serial.println(", low-> ");

float output1 = fuzzy->defuzzify(1);

Serial.println("Output: ");
Serial.print("\tBlinds: Open-> ");
Serial.print(openBlinds->getPertinence());
Serial.print(", Close-> ");
Serial.println(closeBlinds->getPertinence());

Serial.println("Result: ");
Serial.print("\t\t\tResult of Blinds: ");
Serial.print(output1);

// wait 12 seconds
delay(12000);
}

image

Fuzzy rules not executed when using input from sensors

I'm doing some simple project by following sample code, up until testing using a random number as input everything is going as it should be. However after I integrated input from DHT22 sensor, the rules is not working at all.
image

then I try to use manual input with the exactly same value from the sensors, and then the rules is working.
image

is there any solution for this case?

here is my code:

#include <Fuzzy.h>
#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput
FuzzySet *dingin = new FuzzySet(0, 0, 20, 22); //trap
FuzzySet *ideal = new FuzzySet(22, 24, 24, 28); // tri
FuzzySet *toleransi = new FuzzySet(26, 31, 31, 31); //tri
FuzzySet *panas = new FuzzySet(30, 31, 32, 32); // trap

// FuzzyInput
FuzzySet *kering = new FuzzySet(0, 0, 50, 65); //trap
FuzzySet *kideal = new FuzzySet(65, 70, 70, 75); // tri
FuzzySet *lembab = new FuzzySet(73, 74, 75, 75); //tri

//output 1 fan out, 2 cooling, 3 cooling, 4 heating
// FuzzyOutput
FuzzySet *fanOn = new FuzzySet(1, 1, 1, 1);
FuzzySet *fanOff = new FuzzySet(0, 0, 0, 0);

FuzzySet *cooling0 = new FuzzySet(0, 0, 0, 0);
FuzzySet *cooling1 = new FuzzySet(0, 2, 2, 2);
FuzzySet *cooling2 = new FuzzySet(1, 2 , 3, 3);

FuzzySet *heatingOn = new FuzzySet(1, 1, 1, 1);
FuzzySet *heatingOff = new FuzzySet(0, 0, 0, 0);

//Relay and Sensors
const int relayKipas = 4; //pin3
const int relayPendingin1 = 5; //pin3
const int relayPendingin2 = 6; //pin3
const int relayLampuPemanas = 7; //pin3
int relayON = LOW; //relay nyala
int relayOFF = HIGH; //relay mati

void setup()
{
pinMode(relayKipas, OUTPUT);
pinMode(relayPendingin1, OUTPUT);
pinMode(relayPendingin2, OUTPUT);
pinMode(relayLampuPemanas, OUTPUT);
dht.begin();
// Set the Serial output
Serial.begin(9600);
// Set a random seed
randomSeed(analogRead(0));

// Every setup must occur in the function setup()

// FuzzyInput
FuzzyInput *temperatur = new FuzzyInput(1);

temperatur->addFuzzySet(dingin);
temperatur->addFuzzySet(ideal);
temperatur->addFuzzySet(toleransi);
temperatur->addFuzzySet(panas);
fuzzy->addFuzzyInput(temperatur);

// FuzzyInput
FuzzyInput *kelembapan = new FuzzyInput(2);

kelembapan->addFuzzySet(kering);
kelembapan->addFuzzySet(kideal);
kelembapan->addFuzzySet(lembab);
fuzzy->addFuzzyInput(kelembapan);

// FuzzyOutput fan mengurangi kelembapan, mengurangi panas sedikit,
FuzzyOutput *fan = new FuzzyOutput(1);
fan->addFuzzySet(fanOn);
fan->addFuzzySet(fanOff);
fuzzy->addFuzzyOutput(fan);

// FuzzyOutput
FuzzyOutput *cooling = new FuzzyOutput(2);
cooling->addFuzzySet(cooling0);
cooling->addFuzzySet(cooling1);
cooling->addFuzzySet(cooling2);
fuzzy->addFuzzyOutput(cooling);

// fuzzy output
FuzzyOutput * heating = new FuzzyOutput(3);
heating->addFuzzySet(heatingOn);
heating->addFuzzySet(heatingOff);
fuzzy->addFuzzyOutput(heating);

// rule 1
FuzzyRuleAntecedent *keringDingin = new FuzzyRuleAntecedent();
keringDingin->joinWithAND(kering, dingin);

FuzzyRuleConsequent *hangatkanSedikit = new FuzzyRuleConsequent();
hangatkanSedikit->addOutput(fanOff);
hangatkanSedikit->addOutput(cooling0);
hangatkanSedikit->addOutput(heatingOn);

FuzzyRule *fuzzyRule01 = new FuzzyRule(1, keringDingin, hangatkanSedikit);
fuzzy->addFuzzyRule(fuzzyRule01);

// rule 2
FuzzyRuleAntecedent *keringIdeal = new FuzzyRuleAntecedent();
keringIdeal->joinWithAND(kering, ideal);

FuzzyRuleConsequent *tahanKondisi = new FuzzyRuleConsequent();
tahanKondisi->addOutput(fanOff);
tahanKondisi->addOutput(cooling0);
tahanKondisi->addOutput(heatingOff);

FuzzyRule *fuzzyRule02 = new FuzzyRule(2, keringDingin, tahanKondisi);
fuzzy->addFuzzyRule(fuzzyRule02);

// rule 3
FuzzyRuleAntecedent *keringtoleransi = new FuzzyRuleAntecedent();
keringtoleransi->joinWithAND(kering, toleransi);

FuzzyRuleConsequent *turunkanSedikit = new FuzzyRuleConsequent();
turunkanSedikit->addOutput(fanOn);
turunkanSedikit->addOutput(cooling1);
turunkanSedikit->addOutput(heatingOff);

FuzzyRule *fuzzyRule03 = new FuzzyRule(3, keringtoleransi, turunkanSedikit);
fuzzy->addFuzzyRule(fuzzyRule03);

// rule 4
FuzzyRuleAntecedent *keringPanas = new FuzzyRuleAntecedent();
keringPanas->joinWithAND(kering, panas);

FuzzyRuleConsequent *dinginkan = new FuzzyRuleConsequent();
dinginkan->addOutput(fanOff);
dinginkan->addOutput(cooling2);
dinginkan->addOutput(heatingOff);

FuzzyRule *fuzzyRule04 = new FuzzyRule(4, keringPanas, dinginkan);
fuzzy->addFuzzyRule(fuzzyRule04);

// rule 5
FuzzyRuleAntecedent *idealDingin = new FuzzyRuleAntecedent();
idealDingin->joinWithAND(kideal, dingin);

FuzzyRule *fuzzyRule05 = new FuzzyRule(5, idealDingin, hangatkanSedikit);
fuzzy->addFuzzyRule(fuzzyRule05);

// rule 6
FuzzyRuleAntecedent *idealIdeal = new FuzzyRuleAntecedent();
idealIdeal->joinWithAND(kideal, ideal);

FuzzyRuleConsequent *tahanDingin = new FuzzyRuleConsequent();
tahanDingin->addOutput(fanOn);
tahanDingin->addOutput(cooling1);
tahanDingin->addOutput(heatingOff);

FuzzyRule *fuzzyRule06 = new FuzzyRule(6, idealIdeal, dinginkan);
fuzzy->addFuzzyRule(fuzzyRule06);

// rule 7-8
FuzzyRuleAntecedent *kidealToleransi = new FuzzyRuleAntecedent();
idealIdeal->joinWithAND(kideal, toleransi);

FuzzyRuleAntecedent *kidealPanas = new FuzzyRuleAntecedent();
kidealPanas->joinWithAND(kideal, panas);

FuzzyRuleConsequent *dinginkan2 = new FuzzyRuleConsequent();
dinginkan2->addOutput(fanOn);
dinginkan2->addOutput(cooling2);
dinginkan2->addOutput(heatingOff);

FuzzyRule *fuzzyRule07 = new FuzzyRule(7, kidealToleransi, dinginkan2);
fuzzy->addFuzzyRule(fuzzyRule07);
FuzzyRule *fuzzyRule08 = new FuzzyRule(8, kidealPanas, dinginkan2);
fuzzy->addFuzzyRule(fuzzyRule08);

FuzzyRuleAntecedent *lembabDingin = new FuzzyRuleAntecedent();
lembabDingin->joinWithAND(lembab, dingin);
FuzzyRuleConsequent *keringHangatkan = new FuzzyRuleConsequent();
keringHangatkan->addOutput(fanOn);
keringHangatkan->addOutput(cooling0);
keringHangatkan->addOutput(heatingOn);
FuzzyRule *fuzzyRule09 = new FuzzyRule(9, lembabDingin, keringHangatkan);
fuzzy->addFuzzyRule(fuzzyRule09);

FuzzyRuleAntecedent *lembabIdeal = new FuzzyRuleAntecedent();
lembabIdeal->joinWithAND(lembab, ideal);
FuzzyRuleConsequent *kurangiKelambapan = new FuzzyRuleConsequent();
kurangiKelambapan->addOutput(fanOn);
kurangiKelambapan->addOutput(cooling1);
kurangiKelambapan->addOutput(heatingOn);
FuzzyRule *fuzzyRule10 = new FuzzyRule(10, lembabIdeal, kurangiKelambapan);
fuzzy->addFuzzyRule(fuzzyRule10);

FuzzyRuleAntecedent *lembabtoleransi = new FuzzyRuleAntecedent();
lembabtoleransi->joinWithAND(lembab, toleransi);
FuzzyRuleAntecedent *lembabpanas = new FuzzyRuleAntecedent();
lembabpanas->joinWithAND(lembab, panas);

FuzzyRuleConsequent *kurangiKelambapanDanDinginkan = new FuzzyRuleConsequent();
kurangiKelambapanDanDinginkan->addOutput(fanOn);
kurangiKelambapanDanDinginkan->addOutput(cooling2);
kurangiKelambapanDanDinginkan->addOutput(heatingOn);

FuzzyRule *fuzzyRule11 = new FuzzyRule(11, lembabtoleransi, kurangiKelambapanDanDinginkan);
fuzzy->addFuzzyRule(fuzzyRule11);

FuzzyRule *fuzzyRule12 = new FuzzyRule(12, lembabpanas, kurangiKelambapanDanDinginkan);
fuzzy->addFuzzyRule(fuzzyRule12);
}

void loop()
{
int input1 = 29;// dht.readTemperature();
int input2 = 77;// dht.readHumidity();

if (isnan(input1) || isnan(input2)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.println("\n\n\tinput: ");
Serial.print("\t\t\tsuhu: ");
Serial.print(input1);
Serial.print(", kelembapan: ");
Serial.println(input2);

fuzzy->setInput(1, input1);
fuzzy->setInput(2, input2);

fuzzy->fuzzify();
cekFuzzyRule();
Serial.println("\nInput Fuzzy: ");
Serial.print("Suhu: dingin-> ");
Serial.print(dingin->getPertinence());
Serial.print(", ideal-> ");
Serial.print(ideal->getPertinence());
Serial.print(", toleransi-> ");
Serial.println(toleransi->getPertinence());
Serial.print(", panas-> ");
Serial.println(panas->getPertinence());

Serial.print("\nKelembapan: kering-> ");
Serial.print(kering->getPertinence());
Serial.print(", ideal-> ");
Serial.print(kideal->getPertinence());
Serial.print(", lembap-> ");
Serial.print(lembab->getPertinence());

float output1 = fuzzy->defuzzify(1);
float output2 = fuzzy->defuzzify(2);
float output3 = fuzzy->defuzzify(3);

Serial.println("\nOutput: ");
Serial.print("\n\tKipas: Mati-> ");
Serial.print(fanOff->getPertinence());
Serial.print(", nyala-> ");
Serial.print(fanOn->getPertinence());

Serial.print("\n\tPendingin: 0-> ");
Serial.print(cooling0->getPertinence());
Serial.print(", 1-> ");
Serial.print(cooling1->getPertinence());
Serial.print(", 2-> ");
Serial.print(cooling2->getPertinence());

Serial.print("\n\tHeating: mati-> ");
Serial.print(heatingOff->getPertinence());
Serial.print(", nyala-> ");
Serial.print(heatingOn->getPertinence());

Serial.println("\nResult: ");
Serial.print("\tKipas: ");
Serial.print(output1);
Serial.print(", Pendingin: ");
Serial.println(output2);
Serial.print(", pemanas: ");
Serial.println(output3);

if(output1>0){
digitalWrite(relayKipas,relayON);
Serial.println("kps nyala");
}else{
digitalWrite(relayKipas,relayOFF);
Serial.println("kps mati");
}
if(output2>1){
digitalWrite(relayPendingin2,relayON);
digitalWrite(relayPendingin1,relayON);
Serial.println("pendingin 1, 2 nyala");
}else if(output2>1){
digitalWrite(relayPendingin2,relayOFF);
digitalWrite(relayPendingin1,relayON);
Serial.println("pendingin 1 nyala, 2 mati");
}else{
digitalWrite(relayPendingin2,relayOFF);
digitalWrite(relayPendingin1,relayOFF);
Serial.println("pendingin mati");
}
if(output3>0){
digitalWrite(relayLampuPemanas,relayON);
Serial.println("pemanas nyala");
}else{
digitalWrite(relayLampuPemanas,relayOFF);
Serial.println("pemanas mati");
}

// wait 12 seconds
delay(2000);
}

void cekFuzzyRule(){
for(int i=1; i<=12; i++){
Serial.print("Fuzzy rule ");
Serial.print(i);
Serial.print(": ");
Serial.println(fuzzy->isFiredRule(i));
}

}

The defuzzification value seems incorrect.

I checked the result with Matlab and a Python library, which is the same (-1.22). But with this library, the result is -0.833557. The fuzzy output seems correct, but I think the fuzzy composition points of the output are incorrectly calculated. Then, the defuzzification process gives an incorrect value.

#include <iostream>
#include "../include/Fuzzy.h"

int main(int argc, char *argv[]) {
  
    //FIS
    Fuzzy *fuzzy = new Fuzzy();

    //INPUTS
    FuzzyInput* temperatura = new FuzzyInput(1);    
    FuzzySet* tbaja         = new FuzzySet( 10, 15, 15, 20);    
    FuzzySet* tnormal       = new FuzzySet( 18, 20, 20, 22);            
    temperatura->addFuzzySet(tbaja);
    temperatura->addFuzzySet(tnormal);      
    fuzzy->addFuzzyInput(temperatura);
    
    FuzzyInput* humedad     = new FuzzyInput(2);        
    FuzzySet* halta         = new FuzzySet( 40, 55,  55,  70);    
    FuzzySet* hmuyalta      = new FuzzySet( 60, 70, 100, 100);    
    humedad->addFuzzySet(halta);
    humedad->addFuzzySet(hmuyalta);
    fuzzy->addFuzzyInput(humedad);
      
    //OUTPUTS
    FuzzyOutput *variacionTemperatura = new FuzzyOutput(1);    
    FuzzySet* bajadapequeña           = new FuzzySet(-7.5, -2.5, -2.5,    0);    
    FuzzySet* mantener                = new FuzzySet(  -1,    0,    0,    1);    
    FuzzySet* subidapequeña           = new FuzzySet(  0,   2.5,  2.5,  7.5);    
    FuzzySet* subidanormal            = new FuzzySet(2.5,    5,     5,   10);            
    variacionTemperatura->addFuzzySet(bajadapequeña);
    variacionTemperatura->addFuzzySet(mantener);
    variacionTemperatura->addFuzzySet(subidapequeña);
    variacionTemperatura->addFuzzySet(subidanormal);
        
    fuzzy->addFuzzyOutput(variacionTemperatura);

    //RULES    
            
    FuzzyRuleAntecedent *ifBA = new FuzzyRuleAntecedent();
    ifBA->joinWithAND(tbaja, halta);        
    FuzzyRuleAntecedent *ifBMA = new FuzzyRuleAntecedent();
    ifBMA->joinWithAND(tbaja, hmuyalta);        
        
    FuzzyRuleAntecedent *ifNA = new FuzzyRuleAntecedent();
    ifNA->joinWithAND(tnormal, halta);        
    FuzzyRuleAntecedent *ifNMA = new FuzzyRuleAntecedent();
    ifNMA->joinWithAND(tnormal, hmuyalta);        
        
    FuzzyRuleConsequent *thenSP = new FuzzyRuleConsequent();
    thenSP->addOutput(subidapequeña);
    FuzzyRuleConsequent *thenSN = new FuzzyRuleConsequent();
    thenSN->addOutput(subidanormal);    
    FuzzyRuleConsequent *thenM = new FuzzyRuleConsequent();
    thenM->addOutput(mantener);
    FuzzyRuleConsequent *thenBP = new FuzzyRuleConsequent();
    thenBP->addOutput(bajadapequeña);    
            
    FuzzyRule *fuzzyRule9  = new FuzzyRule(9, ifBA,  thenSP);
    FuzzyRule *fuzzyRule10 = new FuzzyRule(10, ifBMA, thenSN);    
    FuzzyRule *fuzzyRule14 = new FuzzyRule(14, ifNA,  thenM);
    FuzzyRule *fuzzyRule15 = new FuzzyRule(15, ifNMA, thenBP);
                  
    fuzzy->addFuzzyRule(fuzzyRule9);
    fuzzy->addFuzzyRule(fuzzyRule10);    
    fuzzy->addFuzzyRule(fuzzyRule14);
    fuzzy->addFuzzyRule(fuzzyRule15);
    
    fuzzy->setInput(1, 19.5);
    fuzzy->setInput(2, 65);

    fuzzy->fuzzify();

    //float o = fuzzy->defuzzify(1);
    //std::cout << "Running with: Temperature->" << 19.5 << ", Humidity->" << 65 << ". Result: " << o << std::endl;        
    
    temperatura->calculateFuzzySetPertinences();
    std::cout << "Input: \n\tTemperatura:  Baja->" << tbaja->getPertinence() << ", Normal->" << tnormal->getPertinence() <<  std::endl;
    humedad->calculateFuzzySetPertinences();
    std::cout << "\tHumedad: Alta-> " << halta->getPertinence() << ", Muy Alta->" << hmuyalta->getPertinence() << std::endl;
    
    std::cout << "Output: \n\tVariación temperatura: Bajada pequeña-> " << bajadapequeña->getPertinence()  << ", Mantener-> " << mantener->getPertinence() << std::endl;
    std::cout << "\tVariación temperatura: Subida pequeña-> " << subidapequeña->getPertinence() << ", Subida Normal->" << subidanormal->getPertinence() <<  std::endl;
    
    std::cout << "RESULT: " << variacionTemperatura->getCrispOutput() << std::endl;
    
    return 0;
}

The ouput is:

Input: 
        Temperatura:  Baja->0.1, Normal->0.75
        Humedad: Alta-> 0.333333, Muy Alta->0.5
Output: 
        Variación temperatura: Bajada pequeña-> 0.5, Mantener-> 0.333333
        Variación temperatura: Subida pequeña-> 0.1, Subida Normal->0.1
RESULT: -0.833557

The correct output (MATLAB):
matlabFIS

How to change the .cpp type code into .c

Hello @zerokol . I'm new to programming and I want to learn about this Fuzzy logic on embedded system.

I already read on README.md about the code that written in c++/c, so, I want to ask you:

  1. I will using the code but not .cpp type, do I have to include the #include "stdlib.h" on the source code that I needed? If not, then do I have to change it myself from c++ source code to c?

Thank you and hope you answer this question.

Fuzzy PID Controller Example?

Hi and thanks for your attention!

I've seen the examples, but couldn't figure out if it's possible to use this library with Brett's Beauregard's PID library (or any PID).
Would FuzzyOutputs be Kp, Ki, Kd?
3 outputs and 2 inputs (setpoint and measured variable)?

Thanks!

How do you generate FuzzyInputs?

I have learned about Fuzzy Logic from this article: https://archive.org/details/ControlPIDFuzzyLogic-Fuzzy-LogicSystemSolvesControlProblemOCR.

I look a this code from the simple general example and I'm not a 100% sure what is doing:

// Criando o FuzzyInput distancia
FuzzyInput* distance = new FuzzyInput(1);
// Criando os FuzzySet que compoem o FuzzyInput distancia 
FuzzySet* small = new FuzzySet(0, 20, 20, 40); // Distancia pequena
distance->addFuzzySet(small); // Adicionando o FuzzySet small em distance
FuzzySet* safe = new FuzzySet(30, 50, 50, 70); // Distancia segura
distance->addFuzzySet(safe); // Adicionando o FuzzySet safe em distance
FuzzySet* big = new FuzzySet(60, 80, 80, 80); // Distancia grande
distance->addFuzzySet(big); // Adicionando o FuzzySet big em distance

My problem comes from the constructor of the FuzzySet(float a, float b, float c, float d). Could you help me understand what FuzzySet* small = new FuzzySet(0, 20, 20, 40) exactly means?

error when trying to declare 3 input into 1 and condition

Help me when i try to compile the code it says "Compilation error: no matching function for call to 'FuzzyRuleAntecedent::joinWithAND(FuzzySet*&, FuzzySet*&, FuzzySet*&)"

`#include <Fuzzy.h>

// For scope, instantiate all objects you will need to access in loop()
// It may be just one Fuzzy, but for demonstration, this sample will print
// all FuzzySet pertinence

// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// FuzzyInputHB
FuzzySet *veryslow = new FuzzySet(60, 70, 70, 80);
FuzzySet *slow = new FuzzySet(70, 80, 80, 90);
FuzzySet *fast = new FuzzySet(80, 90, 90, 100);
FuzzySet *veryfast = new FuzzySet(90, 100, 100, 110);

// FuzzyInputTemp
FuzzySet *verycold = new FuzzySet(32, 33, 33, 34);
FuzzySet *cold = new FuzzySet(33, 34, 34, 35);
FuzzySet *hot = new FuzzySet(34, 35, 35, 36);
FuzzySet *veryhot = new FuzzySet(35, 36 , 36, 37);

// FuzzyInputGSR
FuzzySet *verydry= new FuzzySet(0 , 1 , 1 , 2);
FuzzySet *dry = new FuzzySet(1 , 2 , 2, 3);
FuzzySet *moist = new FuzzySet(2 , 3, 3, 4);
FuzzySet *verymoist = new FuzzySet(4 , 5 , 5 , 7);

// Fuzzyoutput
FuzzySet *relax= new FuzzySet(0 , 12.5 , 12.5 , 25);
FuzzySet *tenang = new FuzzySet(25, 37.5, 37.5, 50);
FuzzySet *cemas = new FuzzySet(50, 62.5, 62.5 , 75);
FuzzySet *stress = new FuzzySet(75, 87.5 , 87.5, 100);

void setup()
{
// Set the Serial output
Serial.begin(9600);
// Set a random seed
randomSeed(analogRead(0));

// Every setup must occur in the function setup()

// FuzzyInput
FuzzyInput *Hb = new FuzzyInput(1);

Hb->addFuzzySet(veryslow);
Hb->addFuzzySet(slow);
Hb->addFuzzySet(fast);
Hb->addFuzzySet(veryfast);
fuzzy->addFuzzyInput(Hb);

// FuzzyInput
FuzzyInput *Temp = new FuzzyInput(2);

Temp->addFuzzySet(verycold);
Temp->addFuzzySet(cold);
Temp->addFuzzySet(hot);
Temp->addFuzzySet(veryhot);
fuzzy->addFuzzyInput(Temp);

// FuzzyInput
FuzzyInput *Gsr = new FuzzyInput(3);

Gsr->addFuzzySet(verydry);
Gsr->addFuzzySet(dry);
Gsr->addFuzzySet(moist);
Gsr->addFuzzySet(verymoist);
fuzzy->addFuzzyInput(Gsr);

// FuzzyOutput
FuzzyOutput *Condition = new FuzzyOutput(1);

Condition->addFuzzySet(relax);
Condition->addFuzzySet(tenang);
Condition->addFuzzySet(cemas);
Condition->addFuzzySet(stress);
fuzzy->addFuzzyOutput(Condition);

FuzzyRuleAntecedent *IfHbVeryslowAndTempVeryhotGsrverydry= new FuzzyRuleAntecedent();
IfHbVeryslowAndTempVeryhotGsrverydry->joinWithAND(veryslow, veryhot, verydry );

FuzzyRuleConsequent *thenConditionrelax = new FuzzyRuleConsequent();
thenConditionrelax->addOutput(relax);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, IfHbVeryslowAndTempVeryhotGsrverydry, thenConditionrelax);
fuzzy->addFuzzyRule(fuzzyRule1);
void loop()
{
// get random entrances
int input1 = random(60, 110);
int input2 = random(32, 37);
int input3 = random(1, 7);

Serial.println("\n\n\nEntrance: ");
Serial.print("\t\t\denyut jantung: ");
Serial.print(input1);
Serial.print(", suhu tubuh: ");
Serial.print(input2);
Serial.print(", and kelembaban: ");
Serial.println(input3);

fuzzy->setInput(1, input1);
fuzzy->setInput(2, input2);
fuzzy->setInput(3, input3);

fuzzy->fuzzify();

Serial.println("Input: ");
Serial.print("\tHb: veryslow-> ");
Serial.print(veryslow->getPertinence());
Serial.print("\tHb: slow-> ");
Serial.print(slow->getPertinence());
Serial.print("\tHb: fast-> ");
Serial.print(fast->getPertinence());
Serial.print("\tHb: veryfast-> ");
Serial.print(veryfast->getPertinence());

Serial.println("Input2: ");
Serial.print("\tTemp: veryhot-> ");
Serial.print(veryhot->getPertinence());
Serial.print("\tTemp: hot-> ");
Serial.print(hot->getPertinence());
Serial.print("\tTemp: cold-> ");
Serial.print(cold->getPertinence());
Serial.print("\tTemp: verycold-> ");
Serial.print(verycold->getPertinence());

Serial.println("Input3: ");
Serial.print("\tGsr: verydry-> ");
Serial.print(verydry->getPertinence());
Serial.print("\tGsr: dry-> ");
Serial.print(dry->getPertinence());
Serial.print("\tGsr: moist-> ");
Serial.print(moist->getPertinence());
Serial.print("\tGsr: verymoist-> ");
Serial.print(verymoist->getPertinence());

float output1 = fuzzy->defuzzify(1);

Serial.println("Output: ");
Serial.print("\tKondisi: Relax-> ");
Serial.print(relax->getPertinence());
Serial.print(", Tenang-> ");
Serial.print(tenang->getPertinence());
Serial.print(", Cemas-> ");
Serial.println(cemas->getPertinence());
Serial.print(", Stress-> ");
Serial.println(stress->getPertinence());

// wait 12 seconds
delay(12000);
}`

Floating number of input

Hi, I have tried the code from example and it worked fine. But I have some issues found by changing the input to a pair of floating numbers. it did not give result as its proper calculation of the Fuzzy rule. I try to change the data type of the inputs Int --> float, but it did not work.
How can I use the floating number inputs?

Next issue was, I try to modify the example code to 2 inputs (5 memberships functions each, which give 25 fuzzy rules) and 1 output (also has 5 membership functions), the code I attached below. I have manually tried the code by pairs of different inputs. but some pair of input numbers can not give any result. I dont know why.

Please, can somebody help me?

Thanks in advance

FLC_2input_5stage_e_de.zip

3 ouput

is this library allow to 3 output on fuzzy ?

Does not work on arduino_esp32

Hello, fantastic library, but cannot get it to work on ESP32, it is restarting. I am using simple example and will try to isolate problem since it is compiling in order.

Does it work on Stm32F4 ?

Hello AJ Alves.I want answer a question to you about your eFLL library.I have an stm microcontroller (STM32F429I DISCOVERY Board ) and i want do a project with fuzzy logic. Can i use your eFLL library using STMCube ide on this board for fuzzy logic projects ?

Rename ESP to DENOM_MINIMAL to avoid compiler warning

With compiling with the ESP32 I am getting the following warning:

In file included from .pio/libdeps/ttg_led/eFLL/FuzzyOutput.h:18:0,
                 from .pio/libdeps/ttg_led/eFLL/Fuzzy.h:19,
                 from src/main.cpp:45:
.pio/libdeps/ttg_led/eFLL/FuzzyComposition.h:20:0: warning: "EPS" redefined
 #define EPS 1.0E-3
 ^
In file included from /.../framework-arduinoespressif32/tools/sdk/include/esp32/xtensa/xtruntime.h:30:0,

Would it be possible that we rename EPS to something like DENOM_MINIMAL (by lack of understanding what EPS means :) )?

Can you help me print the output of the condition i cant seem to do it

`#include <Fuzzy.h>

// For scope, instantiate all objects you will need to access in loop()
// It may be just one Fuzzy, but for demonstration, this sample will print
// all FuzzySet pertinence

// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// FuzzyInputHB
FuzzySet *veryslow = new FuzzySet(60, 70, 70, 80);
FuzzySet *slow = new FuzzySet(75, 80, 80, 90);
FuzzySet *fast = new FuzzySet(85 ,90, 90, 100);
FuzzySet *veryfast = new FuzzySet(95, 100, 100, 110);

// FuzzyInputTemp
FuzzySet *verycold = new FuzzySet(31, 32, 32, 33);
FuzzySet *cold = new FuzzySet(33,34 , 34, 35);
FuzzySet *hot = new FuzzySet(35, 36, 36, 37);
FuzzySet *veryhot = new FuzzySet(37, 38 , 38, 39);

// FuzzyInputGSR
FuzzySet *verydry= new FuzzySet(0 , 1 , 1 , 2);
FuzzySet *dry = new FuzzySet(1 , 2 , 2, 3);
FuzzySet *moist = new FuzzySet(2 , 3, 3, 4);
FuzzySet *verymoist = new FuzzySet(4 , 5 ,6 , 7);

// Fuzzyoutput
FuzzySet *relax= new FuzzySet(0 , 12.5 , 12.5 , 25);
FuzzySet *tenang = new FuzzySet(25, 37.5, 37.5, 50);
FuzzySet *cemas = new FuzzySet(50, 62.5, 62.5 , 75);
FuzzySet *stress = new FuzzySet(75, 87.5 , 87.5, 100);

void setup()
{
// Set the Serial output
Serial.begin(9600);
// Set a random seed
randomSeed(analogRead(0));

// Every setup must occur in the function setup()

// FuzzyInput
FuzzyInput *Hb = new FuzzyInput(1);

Hb->addFuzzySet(veryslow);
Hb->addFuzzySet(slow);
Hb->addFuzzySet(fast);
Hb->addFuzzySet(veryfast);
fuzzy->addFuzzyInput(Hb);

// FuzzyInput
FuzzyInput *Temp = new FuzzyInput(2);

Temp->addFuzzySet(verycold);
Temp->addFuzzySet(cold);
Temp->addFuzzySet(hot);
Temp->addFuzzySet(veryhot);
fuzzy->addFuzzyInput(Temp);

// FuzzyInput
FuzzyInput *Gsr = new FuzzyInput(3);

Gsr->addFuzzySet(verydry);
Gsr->addFuzzySet(dry);
Gsr->addFuzzySet(moist);
Gsr->addFuzzySet(verymoist);
fuzzy->addFuzzyInput(Gsr);

// FuzzyOutput
FuzzyOutput *Condition = new FuzzyOutput(1);

Condition->addFuzzySet(relax);
Condition->addFuzzySet(tenang);
Condition->addFuzzySet(cemas);
Condition->addFuzzySet(stress);
fuzzy->addFuzzyOutput(Condition);

// Building FuzzyRule

FuzzyRuleAntecedent *HbveryslowAndTempveryhot = new FuzzyRuleAntecedent();
HbveryslowAndTempveryhot->joinWithAND(veryslow, veryhot);
FuzzyRuleAntecedent *IfHbveryslowAndTempveryhotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryslowAndTempveryhotAndGsrverydry->joinWithAND(HbveryslowAndTempveryhot, verydry);

FuzzyRuleConsequent *thenConditionrelax = new FuzzyRuleConsequent();
thenConditionrelax->addOutput(relax);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, IfHbveryslowAndTempveryhotAndGsrverydry, thenConditionrelax);
fuzzy->addFuzzyRule(fuzzyRule1);

// Building FuzzyRule 2

FuzzyRuleAntecedent *HbveryslowAndTemphot = new FuzzyRuleAntecedent();
HbveryslowAndTemphot->joinWithAND(veryslow, hot);
FuzzyRuleAntecedent *IfHbveryslowAndTemphotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryslowAndTemphotAndGsrverydry->joinWithAND(HbveryslowAndTemphot, verydry);

FuzzyRule *fuzzyRule2 = new FuzzyRule(2, IfHbveryslowAndTemphotAndGsrverydry, thenConditionrelax);
fuzzy->addFuzzyRule(fuzzyRule2);

// Building FuzzyRule 3

FuzzyRuleAntecedent *HbveryslowAndTempcold = new FuzzyRuleAntecedent();
HbveryslowAndTempcold->joinWithAND(veryslow, cold);
FuzzyRuleAntecedent *IfHbveryslowAndTempcoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryslowAndTempcoldAndGsrverydry->joinWithAND(HbveryslowAndTempcold, verydry);

FuzzyRuleConsequent *thenConditiontenang = new FuzzyRuleConsequent();
thenConditionrelax->addOutput(tenang);

FuzzyRule *fuzzyRule3 = new FuzzyRule(3, IfHbveryslowAndTempcoldAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule3);

// Building FuzzyRule 4

FuzzyRuleAntecedent *HbveryslowAndTempverycold = new FuzzyRuleAntecedent();
HbveryslowAndTempverycold->joinWithAND(veryslow, verycold);
FuzzyRuleAntecedent *IfHbveryslowAndTempverycoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryslowAndTempverycoldAndGsrverydry->joinWithAND(HbveryslowAndTempverycold, verydry);

FuzzyRuleConsequent *thenConditioncemas = new FuzzyRuleConsequent();
thenConditioncemas->addOutput(cemas);

FuzzyRule *fuzzyRule4 = new FuzzyRule(4, IfHbveryslowAndTempverycoldAndGsrverydry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule4);

// Building FuzzyRule 5

FuzzyRuleAntecedent *HbslowAndTempveryhot = new FuzzyRuleAntecedent();
HbslowAndTempveryhot->joinWithAND(slow, veryhot);
FuzzyRuleAntecedent *IfHbslowAndTempveryhotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbslowAndTempveryhotAndGsrverydry->joinWithAND(HbslowAndTempveryhot, verydry);

FuzzyRule *fuzzyRule5 = new FuzzyRule(5, IfHbslowAndTempveryhotAndGsrverydry, thenConditionrelax);
fuzzy->addFuzzyRule(fuzzyRule5);

// Building FuzzyRule 6

FuzzyRuleAntecedent *HbslowAndTemphot = new FuzzyRuleAntecedent();
HbslowAndTemphot->joinWithAND(slow, hot);
FuzzyRuleAntecedent *IfHbslowAndTemphotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbslowAndTemphotAndGsrverydry->joinWithAND(HbslowAndTemphot, verydry);

FuzzyRule *fuzzyRule6 = new FuzzyRule(6, IfHbslowAndTemphotAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule6);

// Building FuzzyRule 7

FuzzyRuleAntecedent *HbslowAndTempcold = new FuzzyRuleAntecedent();
HbslowAndTempcold->joinWithAND(slow, cold);
FuzzyRuleAntecedent *IfHbslowAndTempcoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbslowAndTempcoldAndGsrverydry->joinWithAND(HbslowAndTempcold, verydry);

FuzzyRule *fuzzyRule7 = new FuzzyRule(7, IfHbslowAndTempcoldAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule7);

// Building FuzzyRule 8

FuzzyRuleAntecedent *HbslowAndTempverycold = new FuzzyRuleAntecedent();
HbslowAndTempverycold->joinWithAND(slow, verycold);
FuzzyRuleAntecedent *IfHbslowAndTempverycoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbslowAndTempcoldAndGsrverydry->joinWithAND(HbslowAndTempverycold, verydry);

FuzzyRule *fuzzyRule8 = new FuzzyRule(8, IfHbslowAndTempcoldAndGsrverydry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule8);

// Building FuzzyRule 9

FuzzyRuleAntecedent *HbfastAndTempveryhot = new FuzzyRuleAntecedent();
HbfastAndTempveryhot->joinWithAND(fast, veryhot);
FuzzyRuleAntecedent *IfHbfastAndTempveryhotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbfastAndTempveryhotAndGsrverydry->joinWithAND(HbfastAndTempveryhot, verydry);

FuzzyRule *fuzzyRule9 = new FuzzyRule(9, IfHbfastAndTempveryhotAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule9);

// Building FuzzyRule 10

FuzzyRuleAntecedent *HbfastAndTemphot = new FuzzyRuleAntecedent();
HbfastAndTemphot->joinWithAND(fast, hot);
FuzzyRuleAntecedent *IfHbfastAndTemphotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbfastAndTemphotAndGsrverydry->joinWithAND(HbfastAndTemphot, verydry);

FuzzyRule *fuzzyRule10 = new FuzzyRule(10, IfHbfastAndTemphotAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule10);

// Building FuzzyRule 11

FuzzyRuleAntecedent *HbfastAndTempcold = new FuzzyRuleAntecedent();
HbfastAndTempcold->joinWithAND(fast, cold);
FuzzyRuleAntecedent *IfHbfastAndTempcoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbfastAndTempcoldAndGsrverydry->joinWithAND(HbfastAndTempcold, verydry);

FuzzyRule *fuzzyRule11 = new FuzzyRule(11, IfHbfastAndTempcoldAndGsrverydry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule11);

// Building FuzzyRule 12

FuzzyRuleAntecedent *HbfastAndTempverycold = new FuzzyRuleAntecedent();
HbfastAndTempverycold->joinWithAND(fast, verycold);
FuzzyRuleAntecedent *IfHbfastAndTempverycoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbfastAndTempverycoldAndGsrverydry->joinWithAND(HbfastAndTempverycold, verydry);

FuzzyRule *fuzzyRule12 = new FuzzyRule(12, IfHbfastAndTempverycoldAndGsrverydry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule12);

// Building FuzzyRule 13

FuzzyRuleAntecedent *HbveryfastAndTempveryhot = new FuzzyRuleAntecedent();
HbveryfastAndTempveryhot->joinWithAND(veryfast, veryhot);
FuzzyRuleAntecedent *IfHbveryfastAndTempveryhotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryfastAndTempveryhotAndGsrverydry->joinWithAND(HbveryfastAndTempveryhot, verydry);

FuzzyRule *fuzzyRule13 = new FuzzyRule(13, IfHbveryfastAndTempveryhotAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule13);

  // Building FuzzyRule 14

FuzzyRuleAntecedent *HbveryfastAndTemphot = new FuzzyRuleAntecedent();
HbveryfastAndTemphot->joinWithAND(veryfast, hot);
FuzzyRuleAntecedent *IfHbveryfastAndTemphotAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryfastAndTemphotAndGsrverydry->joinWithAND(HbveryfastAndTemphot, verydry);

FuzzyRule *fuzzyRule14 = new FuzzyRule(14, IfHbveryfastAndTemphotAndGsrverydry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule14);

    // Building FuzzyRule 15

FuzzyRuleAntecedent *HbveryfastAndTempcold = new FuzzyRuleAntecedent();
HbveryfastAndTempcold->joinWithAND(veryfast, cold);
FuzzyRuleAntecedent *IfHbveryfastAndTempcoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryfastAndTempcoldAndGsrverydry->joinWithAND(HbveryfastAndTempcold, verydry);

FuzzyRule *fuzzyRule15 = new FuzzyRule(15, IfHbveryfastAndTempcoldAndGsrverydry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule15);

      // Building FuzzyRule 16

FuzzyRuleAntecedent *HbveryfastAndTempverycold = new FuzzyRuleAntecedent();
HbveryfastAndTempverycold->joinWithAND(veryfast, verycold);
FuzzyRuleAntecedent *IfHbveryfastAndTempverycoldAndGsrverydry = new FuzzyRuleAntecedent();
IfHbveryfastAndTempverycoldAndGsrverydry->joinWithAND(HbveryfastAndTempverycold, verydry);

FuzzyRule *fuzzyRule16 = new FuzzyRule(16, IfHbveryfastAndTempverycoldAndGsrverydry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule16);

// Building FuzzyRule 17

HbveryslowAndTempveryhot->joinWithAND(veryslow, veryhot);
FuzzyRuleAntecedent *IfHbveryslowAndTempveryhotAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryslowAndTempveryhotAndGsrdry->joinWithAND(HbveryslowAndTempveryhot, dry);

FuzzyRule *fuzzyRule17 = new FuzzyRule(17, IfHbveryslowAndTempveryhotAndGsrdry, thenConditionrelax);
fuzzy->addFuzzyRule(fuzzyRule17);

// Building FuzzyRule 18

HbveryslowAndTemphot->joinWithAND(veryslow, hot);
FuzzyRuleAntecedent *IfHbveryslowAndTemphotAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryslowAndTemphotAndGsrdry->joinWithAND(HbveryslowAndTemphot, dry);

FuzzyRule *fuzzyRule18 = new FuzzyRule(18, IfHbveryslowAndTemphotAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule18);

// Building FuzzyRule 19

HbveryslowAndTempcold->joinWithAND(veryslow, cold);
FuzzyRuleAntecedent *IfHbveryslowAndTempcoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryslowAndTempcoldAndGsrdry->joinWithAND(HbveryslowAndTempcold, dry);

FuzzyRule *fuzzyRule19 = new FuzzyRule(19, IfHbveryslowAndTempcoldAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule19);

// Building FuzzyRule 20

HbveryslowAndTempverycold->joinWithAND(veryslow, verycold);
FuzzyRuleAntecedent *IfHbveryslowAndTempverycoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryslowAndTempverycoldAndGsrdry->joinWithAND(HbveryslowAndTempverycold, dry);

FuzzyRule *fuzzyRule20 = new FuzzyRule(20, IfHbveryslowAndTempverycoldAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule20);

// Building FuzzyRule 21

HbslowAndTempveryhot->joinWithAND(slow, veryhot);
FuzzyRuleAntecedent *IfHbslowAndTempveryhotAndGsrdry = new FuzzyRuleAntecedent();
IfHbslowAndTempveryhotAndGsrdry->joinWithAND(HbslowAndTempveryhot, dry);

FuzzyRule *fuzzyRule21 = new FuzzyRule(21, IfHbslowAndTempveryhotAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule21);

// Building FuzzyRule 22

HbslowAndTemphot->joinWithAND(slow, hot);
FuzzyRuleAntecedent *IfHbslowAndTemphotAndGsrdry = new FuzzyRuleAntecedent();
IfHbslowAndTemphotAndGsrdry->joinWithAND(HbslowAndTemphot, dry);

FuzzyRule *fuzzyRule22 = new FuzzyRule(22, IfHbslowAndTemphotAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule22);

// Building FuzzyRule 23

HbslowAndTempcold->joinWithAND(slow, cold);
FuzzyRuleAntecedent *IfHbslowAndTempcoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbslowAndTempcoldAndGsrdry->joinWithAND(HbslowAndTempcold, dry);

FuzzyRule *fuzzyRule23 = new FuzzyRule(23, IfHbslowAndTempcoldAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule23);

// Building FuzzyRule 24

HbslowAndTempverycold->joinWithAND(slow, verycold);
FuzzyRuleAntecedent *IfHbslowAndTempverycoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbslowAndTempverycoldAndGsrdry->joinWithAND(HbslowAndTempverycold, dry);

FuzzyRule *fuzzyRule24 = new FuzzyRule(24, IfHbslowAndTempverycoldAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule24);

// Building FuzzyRule 25

HbfastAndTempveryhot->joinWithAND(fast, veryhot);
FuzzyRuleAntecedent *IfHbfastAndTempveryhotAndGsrdry = new FuzzyRuleAntecedent();
IfHbfastAndTempveryhotAndGsrdry->joinWithAND(HbfastAndTempveryhot, dry);

FuzzyRule *fuzzyRule25 = new FuzzyRule(25, IfHbfastAndTempveryhotAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule25);

// Building FuzzyRule 26

HbfastAndTemphot->joinWithAND(fast, hot);
FuzzyRuleAntecedent *IfHbfastAndTemphotAndGsrdry = new FuzzyRuleAntecedent();
IfHbfastAndTemphotAndGsrdry->joinWithAND(HbfastAndTemphot, dry);

FuzzyRule *fuzzyRule26 = new FuzzyRule(26, IfHbfastAndTemphotAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule26);

// Building FuzzyRule 27

HbfastAndTempcold->joinWithAND(fast, cold);
FuzzyRuleAntecedent *IfHbfastAndTempcoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbfastAndTempcoldAndGsrdry->joinWithAND(HbfastAndTempcold, dry);

FuzzyRule *fuzzyRule27 = new FuzzyRule(27, IfHbfastAndTempcoldAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule27);

// Building FuzzyRule 28

HbfastAndTempverycold->joinWithAND(fast, verycold);
FuzzyRuleAntecedent *IfHbfastAndTempverycoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbfastAndTempverycoldAndGsrdry->joinWithAND(HbfastAndTempverycold, dry);

FuzzyRule *fuzzyRule28 = new FuzzyRule(28, IfHbfastAndTempverycoldAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule28);

// Building FuzzyRule 29

HbveryfastAndTempveryhot->joinWithAND(veryfast, veryhot);
FuzzyRuleAntecedent *IfHbveryfastAndTempveryhotAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryfastAndTempveryhotAndGsrdry->joinWithAND(HbveryfastAndTempveryhot, dry);

FuzzyRule *fuzzyRule29 = new FuzzyRule(29, IfHbveryfastAndTempveryhotAndGsrdry, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule29);

  // Building FuzzyRule 30

HbveryfastAndTemphot->joinWithAND(veryfast, hot);
FuzzyRuleAntecedent *IfHbveryfastAndTemphotAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryfastAndTemphotAndGsrdry->joinWithAND(HbveryfastAndTemphot, dry);

FuzzyRule *fuzzyRule30 = new FuzzyRule(30, IfHbveryfastAndTemphotAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule30);

    // Building FuzzyRule 31

HbveryfastAndTempcold->joinWithAND(veryfast, cold);
FuzzyRuleAntecedent *IfHbveryfastAndTempcoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryfastAndTempcoldAndGsrdry->joinWithAND(HbveryfastAndTempcold, dry);

FuzzyRule *fuzzyRule31 = new FuzzyRule(31, IfHbveryfastAndTempcoldAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule31);

      // Building FuzzyRule 32

HbveryfastAndTempverycold->joinWithAND(veryfast, verycold);
FuzzyRuleAntecedent *IfHbveryfastAndTempverycoldAndGsrdry = new FuzzyRuleAntecedent();
IfHbveryfastAndTempverycoldAndGsrdry->joinWithAND(HbveryfastAndTempverycold, dry);

FuzzyRule *fuzzyRule32 = new FuzzyRule(32, IfHbveryfastAndTempverycoldAndGsrdry, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule32);

// Building FuzzyRule 33

HbveryslowAndTempveryhot->joinWithAND(veryslow, veryhot);
FuzzyRuleAntecedent *IfHbveryslowAndTempveryhotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTempveryhotAndGsrmoist->joinWithAND(HbveryslowAndTempveryhot, moist);

FuzzyRule *fuzzyRule33 = new FuzzyRule(33, IfHbveryslowAndTempveryhotAndGsrmoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule33);

// Building FuzzyRule 34

HbveryslowAndTemphot->joinWithAND(veryslow, hot);
FuzzyRuleAntecedent *IfHbveryslowAndTemphotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTemphotAndGsrmoist->joinWithAND(HbveryslowAndTemphot, moist);

FuzzyRule *fuzzyRule34 = new FuzzyRule(34, IfHbveryslowAndTemphotAndGsrmoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule34);

// Building FuzzyRule 35

HbveryslowAndTempcold->joinWithAND(veryslow, cold);
FuzzyRuleAntecedent *IfHbveryslowAndTempcoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTempcoldAndGsrmoist->joinWithAND(HbveryslowAndTempcold, moist);

FuzzyRule *fuzzyRule35 = new FuzzyRule(35, IfHbveryslowAndTempcoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule35);

// Building FuzzyRule 36

HbveryslowAndTempverycold->joinWithAND(veryslow, verycold);
FuzzyRuleAntecedent *IfHbveryslowAndTempverycoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTempverycoldAndGsrmoist->joinWithAND(HbveryslowAndTempverycold, moist);

FuzzyRule *fuzzyRule36 = new FuzzyRule(36, IfHbveryslowAndTempverycoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule36);

// Building FuzzyRule 37

HbslowAndTempveryhot->joinWithAND(slow, veryhot);
FuzzyRuleAntecedent *IfHbslowAndTempveryhotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbslowAndTempveryhotAndGsrmoist->joinWithAND(HbslowAndTempveryhot, moist);

FuzzyRule *fuzzyRule37 = new FuzzyRule(37, IfHbslowAndTempveryhotAndGsrmoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule37);

// Building FuzzyRule 38

HbslowAndTemphot->joinWithAND(slow, hot);
FuzzyRuleAntecedent *IfHbslowAndTemphotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbslowAndTemphotAndGsrmoist->joinWithAND(HbslowAndTemphot, moist);

FuzzyRule *fuzzyRule38 = new FuzzyRule(38, IfHbslowAndTemphotAndGsrmoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule38);

// Building FuzzyRule 39

HbslowAndTempcold->joinWithAND(slow, cold);
FuzzyRuleAntecedent *IfHbslowAndTempcoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbslowAndTempcoldAndGsrmoist->joinWithAND(HbslowAndTempcold, moist);

FuzzyRule *fuzzyRule39 = new FuzzyRule(39, IfHbslowAndTempcoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule39);

// Building FuzzyRule 40

HbslowAndTempverycold->joinWithAND(slow, verycold);
FuzzyRuleAntecedent *IfHbslowAndTempverycoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbslowAndTempverycoldAndGsrmoist->joinWithAND(HbslowAndTempverycold, moist);

FuzzyRule *fuzzyRule40 = new FuzzyRule(40, IfHbslowAndTempverycoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule40);

// Building FuzzyRule 41

HbfastAndTempveryhot->joinWithAND(fast, veryhot);
FuzzyRuleAntecedent *IfHbfastAndTempveryhotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbfastAndTempveryhotAndGsrmoist->joinWithAND(HbfastAndTempveryhot, moist);

FuzzyRule *fuzzyRule41 = new FuzzyRule(41, IfHbfastAndTempveryhotAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule41);

// Building FuzzyRule 42

HbfastAndTemphot->joinWithAND(fast, hot);
FuzzyRuleAntecedent *IfHbfastAndTemphotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbfastAndTemphotAndGsrmoist->joinWithAND(HbfastAndTemphot, moist);

FuzzyRule *fuzzyRule42 = new FuzzyRule(42, IfHbfastAndTemphotAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule42);

// Building FuzzyRule 43

HbfastAndTempcold->joinWithAND(fast, cold);
FuzzyRuleAntecedent *IfHbfastAndTempcoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbfastAndTempcoldAndGsrmoist->joinWithAND(HbfastAndTempcold, moist);

FuzzyRule *fuzzyRule43 = new FuzzyRule(43, IfHbfastAndTempcoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule43);

// Building FuzzyRule 44

HbfastAndTempverycold->joinWithAND(fast, verycold);
FuzzyRuleAntecedent *IfHbfastAndTempverycoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbfastAndTempverycoldAndGsrmoist->joinWithAND(HbfastAndTempverycold, moist);

FuzzyRule *fuzzyRule44 = new FuzzyRule(44, IfHbfastAndTempverycoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule44);

// Building FuzzyRule 45

HbveryfastAndTempveryhot->joinWithAND(veryfast, veryhot);
FuzzyRuleAntecedent *IfHbveryfastAndTempveryhotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTempveryhotAndGsrmoist->joinWithAND(HbveryfastAndTempveryhot, moist);

FuzzyRule *fuzzyRule45 = new FuzzyRule(45, IfHbveryfastAndTempveryhotAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule45);

  // Building FuzzyRule 46

HbveryfastAndTemphot->joinWithAND(veryfast, hot);
FuzzyRuleAntecedent *IfHbveryfastAndTemphotAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTemphotAndGsrmoist->joinWithAND(HbveryfastAndTemphot, moist);

FuzzyRule *fuzzyRule46 = new FuzzyRule(46, IfHbveryfastAndTemphotAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule46);

    // Building FuzzyRule 47

HbveryfastAndTempcold->joinWithAND(veryfast, cold);
FuzzyRuleAntecedent *IfHbveryfastAndTempcoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTempcoldAndGsrmoist->joinWithAND(HbveryfastAndTempcold, moist);

FuzzyRule *fuzzyRule47 = new FuzzyRule(47, IfHbveryfastAndTempcoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule47);

      // Building FuzzyRule 48

HbveryfastAndTempverycold->joinWithAND(veryfast, verycold);
FuzzyRuleAntecedent *IfHbveryfastAndTempverycoldAndGsrmoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTempverycoldAndGsrmoist->joinWithAND(HbveryfastAndTempverycold, moist);

FuzzyRule *fuzzyRule48 = new FuzzyRule(48, IfHbveryfastAndTempverycoldAndGsrmoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule48);

// Building FuzzyRule 49

HbveryslowAndTempveryhot->joinWithAND(veryslow, veryhot);
FuzzyRuleAntecedent *IfHbveryslowAndTempveryhotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTempveryhotAndGsrverymoist->joinWithAND(HbveryslowAndTempveryhot, verymoist);

FuzzyRule *fuzzyRule49 = new FuzzyRule(49, IfHbveryslowAndTempveryhotAndGsrverymoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule49);

// Building FuzzyRule 50

HbveryslowAndTemphot->joinWithAND(veryslow, hot);
FuzzyRuleAntecedent *IfHbveryslowAndTemphotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTemphotAndGsrverymoist->joinWithAND(HbveryslowAndTemphot, verymoist);

FuzzyRule *fuzzyRule50 = new FuzzyRule(50, IfHbveryslowAndTemphotAndGsrverymoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule50);

// Building FuzzyRule 51

HbveryslowAndTempcold->joinWithAND(veryslow, cold);
FuzzyRuleAntecedent *IfHbveryslowAndTempcoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTempcoldAndGsrverymoist->joinWithAND(HbveryslowAndTempcold, verymoist);

FuzzyRule *fuzzyRule51 = new FuzzyRule(51, IfHbveryslowAndTempcoldAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule51);

// Building FuzzyRule 52

HbveryslowAndTempverycold->joinWithAND(veryslow, verycold);
FuzzyRuleAntecedent *IfHbveryslowAndTempverycoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryslowAndTempverycoldAndGsrverymoist->joinWithAND(HbveryslowAndTempverycold, verymoist);

FuzzyRule *fuzzyRule52 = new FuzzyRule(52, IfHbveryslowAndTempverycoldAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule52);

// Building FuzzyRule 53

HbslowAndTempveryhot->joinWithAND(slow, veryhot);
FuzzyRuleAntecedent *IfHbslowAndTempveryhotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbslowAndTempveryhotAndGsrverymoist->joinWithAND(HbslowAndTempveryhot, verymoist);

FuzzyRule *fuzzyRule53 = new FuzzyRule(53, IfHbslowAndTempveryhotAndGsrverymoist, thenConditiontenang);
fuzzy->addFuzzyRule(fuzzyRule53);

// Building FuzzyRule 54

HbslowAndTemphot->joinWithAND(slow, hot);
FuzzyRuleAntecedent *IfHbslowAndTemphotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbslowAndTemphotAndGsrverymoist->joinWithAND(HbslowAndTemphot, verymoist);

FuzzyRule *fuzzyRule54 = new FuzzyRule(54, IfHbslowAndTemphotAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule54);

// Building FuzzyRule 55

HbslowAndTempcold->joinWithAND(slow, cold);
FuzzyRuleAntecedent *IfHbslowAndTempcoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbslowAndTempcoldAndGsrverymoist->joinWithAND(HbslowAndTempcold, verymoist);

FuzzyRule *fuzzyRule55 = new FuzzyRule(55, IfHbslowAndTempcoldAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule55);

// Building FuzzyRule 56

HbslowAndTempverycold->joinWithAND(slow, verycold);
FuzzyRuleAntecedent *IfHbslowAndTempverycoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbslowAndTempverycoldAndGsrverymoist->joinWithAND(HbslowAndTempverycold, verymoist);

FuzzyRule *fuzzyRule56 = new FuzzyRule(56, IfHbslowAndTempverycoldAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule56);

// Building FuzzyRule 57

HbfastAndTempveryhot->joinWithAND(fast, veryhot);
FuzzyRuleAntecedent *IfHbfastAndTempveryhotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbfastAndTempveryhotAndGsrverymoist->joinWithAND(HbfastAndTempveryhot, verymoist);

FuzzyRule *fuzzyRule57 = new FuzzyRule(57, IfHbfastAndTempveryhotAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule57);

// Building FuzzyRule 58

HbfastAndTemphot->joinWithAND(fast, hot);
FuzzyRuleAntecedent *IfHbfastAndTemphotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbfastAndTemphotAndGsrverymoist->joinWithAND(HbfastAndTemphot, verymoist);

FuzzyRule *fuzzyRule58 = new FuzzyRule(58, IfHbfastAndTemphotAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule58);

// Building FuzzyRule 59

HbfastAndTempcold->joinWithAND(fast, cold);
FuzzyRuleAntecedent *IfHbfastAndTempcoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbfastAndTempcoldAndGsrverymoist->joinWithAND(HbfastAndTempcold, verymoist);

FuzzyRule *fuzzyRule59 = new FuzzyRule(59, IfHbfastAndTempcoldAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule59);

// Building FuzzyRule 60

HbfastAndTempverycold->joinWithAND(fast, verycold);
FuzzyRuleAntecedent *IfHbfastAndTempverycoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbfastAndTempverycoldAndGsrverymoist->joinWithAND(HbfastAndTempverycold, verymoist);

FuzzyRuleConsequent *thenConditionstress = new FuzzyRuleConsequent();
thenConditionstress->addOutput(stress);

FuzzyRule *fuzzyRule60 = new FuzzyRule(60, IfHbfastAndTempverycoldAndGsrverymoist, thenConditionstress);
fuzzy->addFuzzyRule(fuzzyRule60);

// Building FuzzyRule 61

HbveryfastAndTempveryhot->joinWithAND(veryfast, veryhot);
FuzzyRuleAntecedent *IfHbveryfastAndTempveryhotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTempveryhotAndGsrverymoist->joinWithAND(HbveryfastAndTempveryhot, verymoist);

FuzzyRule *fuzzyRule61 = new FuzzyRule(61, IfHbveryfastAndTempveryhotAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule61);

  // Building FuzzyRule 62

HbveryfastAndTemphot->joinWithAND(veryfast, hot);
FuzzyRuleAntecedent *IfHbveryfastAndTemphotAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTemphotAndGsrverymoist->joinWithAND(HbveryfastAndTemphot, verymoist);

FuzzyRule *fuzzyRule62 = new FuzzyRule(62, IfHbveryfastAndTemphotAndGsrverymoist, thenConditioncemas);
fuzzy->addFuzzyRule(fuzzyRule62);

    // Building FuzzyRule 63

HbveryfastAndTempcold->joinWithAND(veryfast, cold);
FuzzyRuleAntecedent *IfHbveryfastAndTempcoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTempcoldAndGsrverymoist->joinWithAND(HbveryfastAndTempcold, verymoist);

FuzzyRule *fuzzyRule63 = new FuzzyRule(63, IfHbveryfastAndTempcoldAndGsrverymoist, thenConditionstress);
fuzzy->addFuzzyRule(fuzzyRule63);

      // Building FuzzyRule 64

HbveryfastAndTempverycold->joinWithAND(veryfast, verycold);
FuzzyRuleAntecedent *IfHbveryfastAndTempverycoldAndGsrverymoist = new FuzzyRuleAntecedent();
IfHbveryfastAndTempverycoldAndGsrverymoist->joinWithAND(HbveryfastAndTempverycold, verymoist);

FuzzyRule *fuzzyRule64 = new FuzzyRule(64, IfHbveryfastAndTempverycoldAndGsrverymoist, thenConditionstress);
fuzzy->addFuzzyRule(fuzzyRule64);
}
void loop()
{
// get random entrances
int input1 = random(60, 110);
int input2 = random(32, 37);
int input3 = random(1, 7);

Serial.println("\n\n\nEntrance: ");
Serial.print("\t\t\denyut jantung: ");
Serial.print(input1);
Serial.print(", suhu tubuh: ");
Serial.print(input2);
Serial.print(", and kelembaban: ");
Serial.println(input3);

fuzzy->setInput(1, input1);
fuzzy->setInput(2, input2);
fuzzy->setInput(3, input3);

fuzzy->fuzzify();

Serial.println("Input: ");
Serial.print("\tHb: veryslow-> ");
Serial.print(veryslow->getPertinence());
Serial.print("\tHb: slow-> ");
Serial.print(slow->getPertinence());
Serial.print("\tHb: fast-> ");
Serial.print(fast->getPertinence());
Serial.print("\tHb: veryfast-> ");
Serial.print(veryfast->getPertinence());

Serial.println("Input2: ");
Serial.print("\tTemp: veryhot-> ");
Serial.print(veryhot->getPertinence());
Serial.print("\tTemp: hot-> ");
Serial.print(hot->getPertinence());
Serial.print("\tTemp: cold-> ");
Serial.print(cold->getPertinence());
Serial.print("\tTemp: verycold-> ");
Serial.print(verycold->getPertinence());

Serial.println("Input3: ");
Serial.print("\tGsr: verydry-> ");
Serial.print(verydry->getPertinence());
Serial.print("\tGsr: dry-> ");
Serial.print(dry->getPertinence());
Serial.print("\tGsr: moist-> ");
Serial.print(moist->getPertinence());
Serial.print("\tGsr: verymoist-> ");
Serial.print(verymoist->getPertinence());

float output1 = fuzzy->defuzzify(1);

Serial.println("Output: ");
Serial.print("\tKondisi Relax-> ");
Serial.print(relax->getPertinence());
Serial.print(",Kondisi Tenang-> ");
Serial.print(tenang->getPertinence());
Serial.print(", Kondisi Cemas-> ");
Serial.println(cemas->getPertinence());
Serial.print(", Kondisi Stress-> ");
Serial.println(stress->getPertinence());

Serial.println (output1);

// wait 12 seconds
delay(12000);
}`

Two fuzzies

Is it just for one fuzzy? I mean, I want do twice defuzzification. I've tried to use 2 fuzzy it can compile perfectly but cant work in real, Im really need helpp.

I need two defuzzifications because. I build a line follower robot, and the speed is from PWM = BasePWM +/- PWM1. BasePWM is the result from defuzzification from keypad input. and PWM1 is result from defuuzzification from line tracking sensors.

And please give me examples of using two defuzzification at the same time , if this library could calculate 2 fuzzies at once. thankss

How to include NOT rules

As you know Fuzzy logic translates Linguistic rules into logical rules that can include AND, OR, NOT operators. Although eFLL has joinWithAND, joinSingle and joinWithOR, I can't seem to find a method for NOT. Taking the example sketches, how may I include the rule:

Distance is Near AND speed is NOT Fast

?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.