0% found this document useful (0 votes)
322 views

eFLL - A Fuzzy Library For Arduino and Embedded Systems

The document describes eFLL, a fuzzy logic library for Arduino and embedded systems. It explains that fuzzy logic uses linguistic variables to describe uncertainty in a way that is more similar to natural language than traditional Boolean logic. The eFLL library was developed in Brazil to provide a lightweight option for implementing fuzzy logic in embedded systems. It can be installed via the Arduino IDE library manager. The document provides an example of using eFLL to control the speed of a robot based on the distance to an obstacle.

Uploaded by

ayman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
322 views

eFLL - A Fuzzy Library For Arduino and Embedded Systems

The document describes eFLL, a fuzzy logic library for Arduino and embedded systems. It explains that fuzzy logic uses linguistic variables to describe uncertainty in a way that is more similar to natural language than traditional Boolean logic. The eFLL library was developed in Brazil to provide a lightweight option for implementing fuzzy logic in embedded systems. It can be installed via the Arduino IDE library manager. The document provides an example of using eFLL to control the speed of a robot based on the distance to an obstacle.

Uploaded by

ayman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

eFLL - A Fuzzy Library for Arduino and Embedded


Systems

Fuzzy Logic is an extension of traditional Boolean logic, using linguistic variables allows to express
logical values intermediate between FALSE and TRUE, describing with greater efficiency the
uncertainty principle in the real world.

Fuzzy Systems are practical applications that employ Fuzzy Logic in its decisions making on the basis
of linguistic variables and terms, the robotics and the electronic engineering has a large utility room.

Developed by Robotic Research Group (RRG) at the State University of Piauí (UESPI-Teresina)
the eFLL (Embedded Fuzzy Logic Library)

library is a versatile, lightweight and efficient option to work with Fuzzy Logic in embedded systems.

Please, report bugs and suggestions with comments or in the official code page on GitHub

Step 4: eFLL will appear in the list, to finish, just click in INSTALL, now you can include eFLL to
your sketchs

Old Way

Step 1: Go to the official project page on GitHub: eFLL

1 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Step 2: Make a clone of the project using Git or download it

Download on the button "Download as zip."

Step 3: Clone or unzip the files into Arduino libraries' folder:

Obs: Rename the folder from "eFLL-master" to "eFLL"

Ubuntu (/usr/share/arduino/libraries/) if installed via apt-get, if not, on Windows, Mac or Linux (where
you downloaded the Arduino IDE, the Library folder is inside)

Ok! The library is ready to be used.

How to import

If the installation of the library has been successfully held, to import the library is easy:

Step 1: Open your Arduino IDE, check out the tab on the top menu SKETCH →

LIBRARY → Import eFLL

Características

Written in C++/C, uses only standard C language library "stdlib.h", so eFLL is a library designed not
only to Arduino, but any Embedded System or not how have your commands written in C.

2 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

It has no explicit limitations on quantity of Fuzzy, Fuzzy Rules, Inputs or Outputs, these limited
processing power and storage of each microcontroller

The library uses the process:

(MAX-MIN) and (Minimum Mamdani) for inference and composition and (CENTER OF AREA)
to defuzzification in a continuous universe.

Tested with GTest for C, Google Inc.

Simple example:

Speed control of a robotic, entry: Frontal distance obstacle.

#include <Fuzzy.h>

// Instantiating a Fuzzy object

Fuzzy *fuzzy = new Fuzzy();

void setup()

// Set the Serial output

3 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Serial.begin(9600);

// Set a random seed

randomSeed(analogRead(0));

// Instantiating a FuzzyInput object

FuzzyInput *distance = new FuzzyInput(1);

// Instantiating a FuzzySet object

FuzzySet *small = new FuzzySet(0, 20, 20, 40);

// Including the FuzzySet into FuzzyInput

distance->addFuzzySet(small);

// Instantiating a FuzzySet object

FuzzySet *safe = new FuzzySet(30, 50, 50, 70);

// Including the FuzzySet into FuzzyInput

distance->addFuzzySet(safe);

// Instantiating a FuzzySet object

FuzzySet *big = new FuzzySet(60, 80, 80, 80);

4 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// Including the FuzzySet into FuzzyInput

distance->addFuzzySet(big);

// Including the FuzzyInput into Fuzzy

fuzzy->addFuzzyInput(distance);

// Instantiating a FuzzyOutput objects

FuzzyOutput *speed = new FuzzyOutput(1);

// Instantiating a FuzzySet object

FuzzySet *slow = new FuzzySet(0, 10, 10, 20);

// Including the FuzzySet into FuzzyOutput

speed->addFuzzySet(slow);

// Instantiating a FuzzySet object

FuzzySet *average = new FuzzySet(10, 20, 30, 40);

// Including the FuzzySet into FuzzyOutput

speed->addFuzzySet(average);

// Instantiating a FuzzySet object

5 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

FuzzySet *fast = new FuzzySet(30, 40, 40, 50);

// Including the FuzzySet into FuzzyOutput

speed->addFuzzySet(fast);

// Including the FuzzyOutput into Fuzzy

fuzzy->addFuzzyOutput(speed);

// Building FuzzyRule "IF distance = small THEN speed = slow"

// Instantiating a FuzzyRuleAntecedent objects

FuzzyRuleAntecedent *ifDistanceSmall = new FuzzyRuleAntecedent();

// Creating a FuzzyRuleAntecedent with just a single FuzzySet

ifDistanceSmall->joinSingle(small);

// Instantiating a FuzzyRuleConsequent objects

FuzzyRuleConsequent *thenSpeedSlow = new FuzzyRuleConsequent();

// Including a FuzzySet to this FuzzyRuleConsequent

thenSpeedSlow->addOutput(slow);

// Instantiating a FuzzyRule objects

6 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

FuzzyRule *fuzzyRule01 = new FuzzyRule(1, ifDistanceSmall, thenSpeedSlow);

// Including the FuzzyRule into Fuzzy

fuzzy->addFuzzyRule(fuzzyRule01);

// Building FuzzyRule "IF distance = safe THEN speed = average"

// Instantiating a FuzzyRuleAntecedent objects

FuzzyRuleAntecedent *ifDistanceSafe = new FuzzyRuleAntecedent();

// Creating a FuzzyRuleAntecedent with just a single FuzzySet

ifDistanceSafe->joinSingle(safe);

// Instantiating a FuzzyRuleConsequent objects

FuzzyRuleConsequent *thenSpeedAverage = new FuzzyRuleConsequent();

// Including a FuzzySet to this FuzzyRuleConsequent

thenSpeedAverage->addOutput(average);

// Instantiating a FuzzyRule objects

FuzzyRule *fuzzyRule02 = new FuzzyRule(2, ifDistanceSafe, thenSpeedAverage);

// Including the FuzzyRule into Fuzzy

7 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

fuzzy->addFuzzyRule(fuzzyRule02);

// Building FuzzyRule "IF distance = big THEN speed = high"

// Instantiating a FuzzyRuleAntecedent objects

FuzzyRuleAntecedent *ifDistanceBig = new FuzzyRuleAntecedent();

// Creating a FuzzyRuleAntecedent with just a single FuzzySet

ifDistanceBig->joinSingle(big);

// Instantiating a FuzzyRuleConsequent objects

FuzzyRuleConsequent *thenSpeedFast = new FuzzyRuleConsequent();

// Including a FuzzySet to this FuzzyRuleConsequent

thenSpeedFast->addOutput(fast);

// Instantiating a FuzzyRule objects

FuzzyRule *fuzzyRule03 = new FuzzyRule(3, ifDistanceBig, thenSpeedFast);

// Including the FuzzyRule into Fuzzy

fuzzy->addFuzzyRule(fuzzyRule03);

8 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

void loop()

// Getting a random value

int input = random(0, 80);

// Printing something

Serial.println("\n\n\nEntrance: ");

Serial.print("\t\t\tDistance: ");

Serial.println(input);

// Set the random value as an input

fuzzy->setInput(1, input);

// Running the Fuzzification

fuzzy->fuzzify();

// Running the Defuzzification

float output = fuzzy->defuzzify(1);

// Printing something

9 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Serial.println("Result: ");

Serial.print("\t\t\tSpeed: ");

Serial.println(output);

// wait 12 seconds

delay(12000);

Brief documentation

Fuzzy object - This object includes all the Fuzzy System, through it, you can manipulate the Fuzzy
Sets, Linguistic Rules, inputs and outputs.

FuzzyInput object - This object groups all entries Fuzzy Sets that belongs to the same domain.

FuzzyOutput object - This object is similar to FuzzyInput, is used to group all output Fuzzy Sets
that belongs to the same domain.

FuzzySet object - This is one of the main objects of Fuzzy Library, with each set is possible to model
the system in question. Currently the library supports triangular membership functions, trapezoidal and
singleton, which are assembled based on points A, B, C and D, they are passed by parameter in its
constructor FuzzySet(float a, float b, float c, float d) examples:

Triangular pertinence function:

10 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

FuzzySet* fs = FuzzySet(10, 20, 20, 30);

FuzzySet* fs = FuzzySet(10, 33, 33, 33);

FuzzySet* fs = FuzzySet(5, 5, 5, 30);

11 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Trapezoidal pertinence function:

FuzzySet* fs = FuzzySet(10, 20, 30, 40);

FuzzySet* fs = FuzzySet(0, 0, 10, 20);

Any value below 10 will have pertinence = 1

12 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

FuzzySet* fs = FuzzySet(20, 30, 40, 40);

Any value above 30 will have pertinence = 1

Singleton pertinence function:

FuzzySet* fs = FuzzySet(20, 20, 20, 20);

FuzzyRule object - This object is used to mount the base rule of Fuzzy object, which contains one or
more of this object. Instantiated with FuzzyRule fr = new FuzzyRule (ID, antecedent, consequent)

FuzzyRuleAntecedent object - This object is used to compound the object FuzzyRule, responsible for
assembling the antecedent of the conditional expression of a FuzzyRule, examples:

13 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

"IF distance = small THEN velocity = slow"

FuzzyRuleAntecedent* ifDistanceSmall = new FuzzyRuleAntecedent(); ifDistanceSmall->joinSingle(small);

The method joinSingle(FuzzySet* fuzzySet) is used to build simple expressions IF/THEN. To compose
more complex expressions there are other special methods.

"IF temperature = hot AND pressure = hight THEN rick = big"

FuzzyRuleAntecedent* ifTemperatureHotAndPressureHight = new FuzzyRuleAntecedent();


ifTemperatureHotAndPressureHight->joinWithAND(hot, hight);

"IF temperature = hot OR pressure = hight THEN rick = big"

FuzzyRuleAntecedent* ifTemperatureHotAndPressureHight = new FuzzyRuleAntecedent();


ifTemperatureHotAndPressureHight->joinWithOR(hot, hight);

The methods joinWithAND(FuzzySet* fuzzySet1, FuzzySet* fuzzySet2) and joinWithOR(FuzzySet*


fuzzySet1, FuzzySet* fuzzySet2) can make logical compositions between Fuzzy Sets. These methods
also have more advanced variations that allow further enhance the expression, they are:

bool joinWithAND(FuzzySet* fuzzySet, FuzzyRuleAntecedent* fuzzyRuleAntecedent);


bool joinWithAND(FuzzyRuleAntecedent* fuzzyRuleAntecedent, FuzzySet* fuzzySet);

14 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

bool joinWithOR(FuzzySet* fuzzySet, FuzzyRuleAntecedent* fuzzyRuleAntecedent);


bool joinWithOR(FuzzyRuleAntecedent* fuzzyRuleAntecedent, FuzzySet* fuzzySet);
bool joinWithAND(FuzzyRuleAntecedent* fuzzyRuleAntecedent1, FuzzyRuleAntecedent* fuzzyRuleAntecedent2
bool joinWithOR(FuzzyRuleAntecedent* fuzzyRuleAntecedent1, FuzzyRuleAntecedent* fuzzyRuleAntecedent2

examples:

"IF (velocity = hight AND distance = small) OR fuel = low THEN velocity = small AND consumption
= short"

FuzzyRuleAntecedent* speedHightAndDistanceSmall = new FuzzyRuleAntecedent();


speedHightAndDistanceSmall->joinWithAND(hight, small);

FuzzyRuleAntecedent* fuelLow = new FuzzyRuleAntecedent();


fuelLow->joinSingle(low);

// Este objeto FuzzyRuleAntecedente é que será usada para compor o objeto FuzzyRule
FuzzyRuleAntecedent* ifSpeedHightAndDistanceSmallOrFuelLow = new FuzzyRuleAntecedent();
ifSpeedHightAndDistanceSmallOrFuelLow->joinWithOR(speedHightAndDistanceSmall, fuelLow);

Using these methods, any expression can be mounted, FuzzyRuleAntecedent can be used to compose
another object FuzzyRuleAntecedent, in many different ways.
OBS:. in the previous example, the final antecedent was composed of speedHightAndDistanceSmall
and fuelLow objects, but the latter could be replaced without loss by the FuzzySet object low, since it is
a simple expression, without any conditional operator:

FuzzyRuleAntecedent* speedHightAndDistanceSmall = new FuzzyRuleAntecedent();

15 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

speedHightAndDistanceSmall->joinWithAND(hight, small);

// Este objeto FuzzyRuleAntecedente é que será usada para compor o objeto FuzzyRule
FuzzyRuleAntecedent* ifSpeedHightAndDistanceSmallOrFuelLow = new FuzzyRuleAntecedent();
ifSpeedHightAndDistanceSmallOrFuelLow->joinWithOR(speedHightAndDistanceSmall, low);

FuzzyRuleConsequente object - This object is used to render the object FuzzyRule, responsible for
assembling the output expression of a FuzzyRule, examples:

"IF disctance = small THEN velocity = slow"

FuzzyRuleConsequent* thenSpeedSlow = new FuzzyRuleConsequent();


thenSpeedSlow->addOutput(slow);

What would result in an FuzzyRule object like:

FuzzyRule* fuzzyRule = new FuzzyRule(2, ifDistanceSmall, thenSpeedSlow);

"IF (velocity = hight AND distance = small) OR fuel = low THEN velocity = small AND consumption
= short"

FuzzyRuleConsequent* thenSpeedSmallAndFeedTine = new FuzzyRuleConsequent(); thenSpeedSmallAndFeedSmall

thenSpeedSmallAndFeedSmall->addOutput(tine);

16 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

For the object FuzzyRuleConsequent entire expression is mounted using the method
addOutput(FuzzySet* fuzzySet);

What would result in an FuzzyRule object like:

FuzzyRule* fuzzyRule = new FuzzyRule(2, ifSpeedHightAndDistanceSmallOrFuelLow, thenSpeedSmallAndFeedTine

After assembling an FuzzyRule object, use the method addFuzzyRule(FuzzyRule* fuzzyRule); to add
it to Fuzzy object base rule, repeat the same process for all the rules.

Tip

These are all eFLL library objects that are used in the process. The next step, generally interactive is
handled by three methods of the Fuzzy Class first:

bool setInput(int id, float value);

It is used to pass the

Crispe input value to the system note that the first parameter is the FuzzyInput object' ID which
parameter value is intended.

bool fuzzify();

It is used to start the fuzzification process, composition and inference.

And finally:

17 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

float defuzzify(int id);

It is used to finalize the fuzzification

process, notice that the param ID belongs to FuzzyOutput object which you want to get the
defuzzification value.

Hint: Sometimes is necessary to know the pertinence with which some or each fuzzy set was activated.
To do this, use the method float getPertinence(); of FuzzySet Class, eg:

FuzzySet* hot = new FuzzySet(30, 50, 50, 70);


...
... // After fuzzification with ->fuzzyfy();
...
float pertinenceOfHot = hot->getPertinence();

Or whether a particular rule was fired, use the method bool isFiredRule(int ruleId); of Fuzzy object.

FuzzyRule* fuzzyRule = new FuzzyRule(2, ifDistanceSmall, thenSpeedSlow);


...
... // After fuzzification with ->fuzzyfy();
...
bool wasTheRulleFired = fuzzy->isFiredRule(2);

Advanced example:

#include <Fuzzy.h>

18 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// 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

FuzzySet *near = new FuzzySet(0, 20, 20, 40);

FuzzySet *safe = new FuzzySet(30, 50, 50, 70);

FuzzySet *distant = new FuzzySet(60, 80, 100, 100);

// FuzzyInput

FuzzySet *stopedInput = new FuzzySet(0, 0, 0, 0);

FuzzySet *slowInput = new FuzzySet(1, 10, 10, 20);

FuzzySet *normalInput = new FuzzySet(15, 30, 30, 50);

FuzzySet *quickInput = new FuzzySet(45, 60, 70, 70);

19 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// FuzzyInput

FuzzySet *cold = new FuzzySet(-30, -30, -20, -10);

FuzzySet *good = new FuzzySet(-15, 0, 0, 15);

FuzzySet *hot = new FuzzySet(10, 20, 30, 30);

// FuzzyOutput

FuzzySet *minimum = new FuzzySet(0, 20, 20, 40);

FuzzySet *average = new FuzzySet(30, 50, 50, 70);

FuzzySet *maximum = new FuzzySet(60, 80, 80, 100);

// FuzzyOutput

FuzzySet *stopedOutput = new FuzzySet(0, 0, 0, 0);

FuzzySet *slowOutput = new FuzzySet(1, 10, 10, 20);

FuzzySet *normalOutput = new FuzzySet(15, 30, 30, 50);

FuzzySet *quickOutput = new FuzzySet(45, 60, 70, 70);

20 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

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 *distance = new FuzzyInput(1);

distance->addFuzzySet(near);

distance->addFuzzySet(safe);

distance->addFuzzySet(distant);

fuzzy->addFuzzyInput(distance);

21 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// FuzzyInput

FuzzyInput *speedInput = new FuzzyInput(2);

speedInput->addFuzzySet(stopedInput);

speedInput->addFuzzySet(slowInput);

speedInput->addFuzzySet(normalInput);

speedInput->addFuzzySet(quickInput);

fuzzy->addFuzzyInput(speedInput);

// FuzzyInput

FuzzyInput *temperature = new FuzzyInput(3);

temperature->addFuzzySet(cold);

temperature->addFuzzySet(good);

temperature->addFuzzySet(hot);

fuzzy->addFuzzyInput(temperature);

22 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// FuzzyOutput

FuzzyOutput *risk = new FuzzyOutput(1);

risk->addFuzzySet(minimum);

risk->addFuzzySet(average);

risk->addFuzzySet(maximum);

fuzzy->addFuzzyOutput(risk);

// FuzzyOutput

FuzzyOutput *speedOutput = new FuzzyOutput(2);

speedOutput->addFuzzySet(stopedOutput);

speedOutput->addFuzzySet(slowOutput);

speedOutput->addFuzzySet(normalOutput);

speedOutput->addFuzzySet(quickOutput);

fuzzy->addFuzzyOutput(speedOutput);

23 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// Building FuzzyRule

FuzzyRuleAntecedent *distanceNearAndSpeedQuick = new FuzzyRuleAntecedent();

distanceNearAndSpeedQuick->joinWithAND(near, quickInput);

FuzzyRuleAntecedent *temperatureCold = new FuzzyRuleAntecedent();

temperatureCold->joinSingle(cold);

FuzzyRuleAntecedent *ifDistanceNearAndSpeedQuickOrTemperatureCold = new


FuzzyRuleAntecedent();

ifDistanceNearAndSpeedQuickOrTemperatureCold->joinWithOR(distanceNearAndSpeedQuick,
temperatureCold);

FuzzyRuleConsequent *thenRisMaximumAndSpeedSlow = new FuzzyRuleConsequent();

thenRisMaximumAndSpeedSlow->addOutput(maximum);

thenRisMaximumAndSpeedSlow->addOutput(slowOutput);

FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifDistanceNearAndSpeedQuickOrTemperatureCold,


thenRisMaximumAndSpeedSlow);

fuzzy->addFuzzyRule(fuzzyRule1);

24 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

// Building FuzzyRule

FuzzyRuleAntecedent *distanceSafeAndSpeedNormal = new FuzzyRuleAntecedent();

distanceSafeAndSpeedNormal->joinWithAND(safe, normalInput);

FuzzyRuleAntecedent *ifDistanceSafeAndSpeedNormalOrTemperatureGood = new


FuzzyRuleAntecedent();

ifDistanceSafeAndSpeedNormalOrTemperatureGood->joinWithOR(distanceSafeAndSpeedNormal,
good);

FuzzyRuleConsequent *thenRiskAverageAndSpeedNormal = new FuzzyRuleConsequent();

thenRiskAverageAndSpeedNormal->addOutput(average);

thenRiskAverageAndSpeedNormal->addOutput(normalOutput);

FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifDistanceSafeAndSpeedNormalOrTemperatureGood,


thenRiskAverageAndSpeedNormal);

fuzzy->addFuzzyRule(fuzzyRule2);

// Building FuzzyRule

FuzzyRuleAntecedent *distanceDistantAndSpeedSlow = new FuzzyRuleAntecedent();

25 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

distanceDistantAndSpeedSlow->joinWithAND(distant, slowInput);

FuzzyRuleAntecedent *ifDistanceDistantAndSpeedSlowOrTemperatureHot = new


FuzzyRuleAntecedent();

ifDistanceDistantAndSpeedSlowOrTemperatureHot->joinWithOR(distanceDistantAndSpeedSlow,
hot);

FuzzyRuleConsequent *thenRiskMinimumSpeedQuick = new FuzzyRuleConsequent();

thenRiskMinimumSpeedQuick->addOutput(minimum);

thenRiskMinimumSpeedQuick->addOutput(quickOutput);

FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifDistanceDistantAndSpeedSlowOrTemperatureHot,


thenRiskMinimumSpeedQuick);

fuzzy->addFuzzyRule(fuzzyRule3);

void loop()

// get random entrances

26 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

int input1 = random(0, 100);

int input2 = random(0, 70);

int input3 = random(-30, 30);

Serial.println("\n\n\nEntrance: ");

Serial.print("\t\t\tDistance: ");

Serial.print(input1);

Serial.print(", Speed: ");

Serial.print(input2);

Serial.print(", and Temperature: ");

Serial.println(input3);

fuzzy->setInput(1, input1);

fuzzy->setInput(2, input2);

fuzzy->setInput(3, input3);

fuzzy->fuzzify();

27 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Serial.println("Input: ");

Serial.print("\tDistance: Near-> ");

Serial.print(near->getPertinence());

Serial.print(", Safe-> ");

Serial.print(safe->getPertinence());

Serial.print(", Distant-> ");

Serial.println(distant->getPertinence());

Serial.print("\tSpeed: Stoped-> ");

Serial.print(stopedInput->getPertinence());

Serial.print(", Slow-> ");

Serial.print(slowInput->getPertinence());

Serial.print(", Normal-> ");

Serial.print(normalInput->getPertinence());

Serial.print(", Quick-> ");

28 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Serial.println(quickInput->getPertinence());

Serial.print("\tTemperature: Cold-> ");

Serial.print(cold->getPertinence());

Serial.print(", Good-> ");

Serial.print(good->getPertinence());

Serial.print(", Hot-> ");

Serial.println(hot->getPertinence());

float output1 = fuzzy->defuzzify(1);

float output2 = fuzzy->defuzzify(2);

Serial.println("Output: ");

Serial.print("\tRisk: Minimum-> ");

Serial.print(minimum->getPertinence());

Serial.print(", Average-> ");

Serial.print(average->getPertinence());

29 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Serial.print(", Maximum-> ");

Serial.println(maximum->getPertinence());

Serial.print("\tSpeed: Stoped-> ");

Serial.print(stopedOutput->getPertinence());

Serial.print(", Slow-> ");

Serial.print(slowOutput->getPertinence());

Serial.print(", Normal-> ");

Serial.print(normalOutput->getPertinence());

Serial.print(", Quick-> ");

Serial.println(quickOutput->getPertinence());

Serial.println("Result: ");

Serial.print("\t\t\tRisk: ");

Serial.print(output1);

Serial.print(", and Speed: ");

30 of 31 5/19/21, 1:39 AM
eFLL - A Fuzzy Library for Arduino and Embedded Systems https://blog.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...

Serial.println(output2);

// wait 12 seconds

delay(12000);

31 of 31 5/19/21, 1:39 AM

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy