alvesoaj / eFLL

eFLL (Embedded Fuzzy Logic Library) is a standard library for Embedded Systems
MIT License
211 stars 91 forks source link

Fuzzy output limit ? #21

Closed larrymvududu closed 3 years ago

larrymvududu commented 4 years ago

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

// 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); }`

alvesoaj commented 4 years ago

Hey, there is no limitation for the library itself. The limitation is probably the hardware, please try to use an Adruino Mega for example and tell me if the issue continues.