zerokol.com
Vamos que vamos, ao infinito e alm!
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
How to install
Step 2: Make a clone of the project using Git or download it Donwload on the button "Download as zip."
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)
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 SKETCKS LIBRARY Import eFLL
Caractersticas
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.
It has no explicit limitations on quantity of Fuzzy, Fuzzy Rules, Inputs or Outputs, these limited processing power and
storage of each microcontroller
1 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
MAX-MIN) and (Minimum Mamdani) for inference and composition and (CENTER OF AREA) to defuzzification in a
continuous universe.
Simple example:
1 #include <FuzzyRule.h>
2 #include <FuzzyComposition.h>
3 #include <Fuzzy.h>
4 #include <FuzzyRuleConsequent.h>
5 #include <FuzzyOutput.h>
6 #include <FuzzyInput.h>
7 #include <FuzzyIO.h>
8 #include <FuzzySet.h>
9 #include <FuzzyRuleAntecedent.h>
10
11 // Step 1 - Instantiating an object library
12 Fuzzy* fuzzy = new Fuzzy();
13
14 void setup(){
15 Serial.begin(9600);
16
17 // Step 2 - Creating a FuzzyInput distance
18 FuzzyInput* distance = new FuzzyInput(1);// With its ID in param
19
20 // Creating the FuzzySet to compond FuzzyInput distance
21 FuzzySet* small = new FuzzySet(0, 20, 20, 40); // Small distance
22 distance->addFuzzySet(small); // Add FuzzySet small to distance
23 FuzzySet* safe = new FuzzySet(30, 50, 50, 70); // Safe distance
24 distance->addFuzzySet(safe); // Add FuzzySet safe to distance
25 FuzzySet* big = new FuzzySet(60, 80, 80, 80); // Big distance
26 distance->addFuzzySet(big); // Add FuzzySet big to distance
27
28 fuzzy->addFuzzyInput(distance); // Add FuzzyInput to Fuzzy object
29
30 // Passo 3 - Creating FuzzyOutput velocity
31 FuzzyOutput* velocity = new FuzzyOutput(1);// With its ID in param
32
33 // Creating FuzzySet to compond FuzzyOutput velocity
34 FuzzySet* slow = new FuzzySet(0, 10, 10, 20); // Slow velocity
35 velocity->addFuzzySet(slow); // Add FuzzySet slow to velocity
36 FuzzySet* average = new FuzzySet(10, 20, 30, 40); // Average velocity
37 velocity->addFuzzySet(average); // Add FuzzySet average to velocity
38 FuzzySet* fast = new FuzzySet(30, 40, 40, 50); // Fast velocity
39 velocity->addFuzzySet(fast); // Add FuzzySet fast to velocity
40
41 fuzzy->addFuzzyOutput(velocity); // Add FuzzyOutput to Fuzzy object
42
43 //Passo 4 - Assembly the Fuzzy rules
44 // FuzzyRule "IF distance = samll THEN velocity = slow"
45 FuzzyRuleAntecedent* ifDistanceSmall = new FuzzyRuleAntecedent(); // Instantiating an Antecedent to expression
46 ifDistanceSmall->joinSingle(small); // Adding corresponding FuzzySet to Antecedent object
47 FuzzyRuleConsequent* thenVelocitySlow = new FuzzyRuleConsequent(); // Instantiating a Consequent to expression
48 thenVelocitySlow->addOutput(slow);// Adding corresponding FuzzySet to Consequent object
49 // Instantiating a FuzzyRule object
50 FuzzyRule* fuzzyRule01 = new FuzzyRule(1, ifDistanceSmall, thenVelocitySlow); // Passing the Antecedent and the
51
52 fuzzy->addFuzzyRule(fuzzyRule01); // Adding FuzzyRule to Fuzzy object
53
54 // FuzzyRule "IF distance = safe THEN velocity = normal"
55 FuzzyRuleAntecedent* ifDistanceSafe = new FuzzyRuleAntecedent(); // Instantiating an Antecedent to expression
56 ifDistanceSafe->joinSingle(safe); // Adding corresponding FuzzySet to Antecedent object
57 FuzzyRuleConsequent* thenVelocityAverage = new FuzzyRuleConsequent(); // Instantiating a Consequent to expressi
58 thenVelocityAverage->addOutput(average); // Adding corresponding FuzzySet to Consequent object
59 // Instantiating a FuzzyRule object
60 FuzzyRule* fuzzyRule02 = new FuzzyRule(2, ifDistanceSafe, thenVelocityAverage); // Passing the Antecedent and t
61
62 fuzzy->addFuzzyRule(fuzzyRule02); // Adding FuzzyRule to Fuzzy object
63
64 // FuzzyRule "IF distance = big THEN velocity = fast"
65 FuzzyRuleAntecedent* ifDistanceBig = new FuzzyRuleAntecedent(); // Instantiating an Antecedent to expression
66 ifDistanceBig->joinSingle(big); // Adding corresponding FuzzySet to Antecedent object
67 FuzzyRuleConsequent* thenVelocityFast = new FuzzyRuleConsequent(); // Instantiating a Consequent to expression
68 thenVelocityFast->addOutput(fast);// Adding corresponding FuzzySet to Consequent object
69 // Instantiating a FuzzyRule object
70 FuzzyRule* fuzzyRule03 = new FuzzyRule(3, ifDistanceBig, thenVelocityFast); // Passing the Antecedent and the C
71
72 fuzzy->addFuzzyRule(fuzzyRule03); // Adding FuzzyRule to Fuzzy object
73 }
74
75 void loop(){
76 float dist = getDistanceFromSonar();
77
78 // Step 5 - Report inputs value, passing its ID and value
79 fuzzy->setInput(1, dist);
80 // Step 6 - Exe the fuzzification
81 fuzzy->fuzzify();
82 // Step 7 - Exe the desfuzzyficao for each output, passing its ID
83 float output = fuzzy->defuzzify(1);
84
85 setRobotSpeed(output);
86
87 delay(100);
88 }
Brief documentation
Fuzzy object - This object includes all the Fuzzy System, through it, you can manipulate the Fuzzy Sets, Linguistic
Rules, inputs and outputs.
2 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
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 thar 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
examples:
FuzzyRule object - This object is used to mount the base rule of Fuzzy object, which contains one or more of this object
nstantiated 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:
3 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
The method joinSingle(FuzzySet* fuzzySet) is used to build simple expressions IF/THEN. To compose more complex
expressions there are other special methods.
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:
examples:
"IF (velocity = hight AND distance = small) OR fuel = low THEN velocity = small AND consumption = short"
// 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:
// 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 (velocity = hight AND distance = small) OR fuel = low THEN velocity = small AND consumption = short"
thenSpeedSmallAndFeedSmall->addOutput(tine);
For the object FuzzyRuleConsequent entire expression is mounted using the method addOutput(FuzzySet* fuzzySet);
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.
4 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
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:
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();
And finally:
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:
Or whether a particular rule was fired, use the method bool isFiredRule(int ruleId); of Fuzzy object.
Advanced example:
1 #include <FuzzyRule.h>
2 #include <FuzzyComposition.h>
3 #include <Fuzzy.h>
4 #include <FuzzyRuleConsequent.h>
5 #include <FuzzyOutput.h>
6 #include <FuzzyInput.h>
7 #include <FuzzyIO.h>
8 #include <FuzzySet.h>
9 #include <FuzzyRuleAntecedent.h>
10
11 // Instantiating an object of library
12 Fuzzy* fuzzy = new Fuzzy();
13
14 FuzzySet* close = new FuzzySet(0, 20, 20, 40);
15 FuzzySet* safe = new FuzzySet(30, 50, 50, 70);
16 FuzzySet* distante = new FuzzySet(60, 80, 100, 100);
17
18 FuzzySet* stoped = new FuzzySet(0, 0, 0, 0);
19 FuzzySet* slow = new FuzzySet(1, 10, 10, 20);
20 FuzzySet* normal = new FuzzySet(15, 30, 30, 50);
21 FuzzySet* quick = new FuzzySet(45, 60, 70, 70);
22
23 FuzzySet* cold = new FuzzySet(-30, -30, -20, -10);
24 FuzzySet* good = new FuzzySet(-15, 0, 0, 15);
25 FuzzySet* hot = new FuzzySet(10, 20, 30, 30);
26
27 void setup(){
28 Serial.begin(9600);
29
30 // FuzzyInput
31 FuzzyInput* distance = new FuzzyInput(1);
32 distance->addFuzzySet(close);
33 distance->addFuzzySet(safe);
34 distance->addFuzzySet(distante);
35
36 fuzzy->addFuzzyInput(distance);
37
38 // FuzzyInput
39 FuzzyInput* inputSpeed = new FuzzyInput(2);
40 inputSpeed->addFuzzySet(stoped);
41 inputSpeed->addFuzzySet(slow);
42 inputSpeed->addFuzzySet(normal);
43 inputSpeed->addFuzzySet(quick);
44
45 fuzzy->addFuzzyInput(inputSpeed);
46
47 // FuzzyInput
48 FuzzyInput* temperature = new FuzzyInput(3);
49 temperature->addFuzzySet(cold);
50 temperature->addFuzzySet(good);
51 temperature->addFuzzySet(hot);
52
53 fuzzy->addFuzzyInput(temperature);
54
55 // FuzzyOutput
56 FuzzyOutput* risk = new FuzzyOutput(1);
57
58 FuzzySet* minimum = new FuzzySet(0, 20, 20, 40);
59 risk->addFuzzySet(minimum);
5 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
6 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
Biblioteca eFLL licenciada sob uma Licena Creative Commons Atribuio-SemDerivados 3.0 No Adaptada.
Baseado no trabalho em http://github.com/zerokol/eFLL.
Persses alm do escopo dessa licena podem estar disponvel em http://zerokol.com.
Linkwithin
24 comentrios:
Arbie disse...
AJ O. Alves
Thanks for the team who want to share this library for arduino. what a great job's.. :) by the way i want to ask
about the variabel get from ADC (example input LM35 & output relay) where do i place
analogRead('variabel') as a fuzzy input and digitalWrite(13,HIGH/LOW) as a fuzzy output i'm still confuse it..
i want to apologize cause bad english (i'm from indonesia),I really appreciate your help and send me some
tutorial
bimo.ardi.h@gmail.com
thanks before.. :)
19 de novembro de 2012 00:25
AJ O. Alves disse...
Thanks Arbie!
Pat disse...
Thank you very much for providing this great library to the Adruino community!
I'm currently using it in a "robotic fireman toy truck" project to drive the speed and direction of the truck.
I'm just beginning the implementation but thanks to your doc and samples it's going fine.
Patrice
http://breizhmakers.over-blog.com/
25 de novembro de 2012 15:20
Arbie disse...
Hi AJ...
i've got trouble at result of defuzzyfy when i have 2 or more fuzzyrule using same fuzzyrule consequent but
different fuzzyantecedent...
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
28 de novembro de 2012 04:25
AJ O. Alves disse...
Thanks one more time Arbie!!!
7 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
AlanK disse...
Thank you so much for providing this fantastic library as an open source. I can finally finish something I
started looking at many years ago but never quite got around to finishing!
16 de dezembro de 2012 18:08
Christophe disse...
Very interesting indeed. I dont have a lot of experience with libraries, but Id like to share two ideas :
- is it possible to have a boolean output with defuzzyfication ? Most outputs are boolean. I know you can
arrange that with some slow PWM, but there should be a better way
- is it possible to reuse fuzzysets ? In the example I see the same set defined more than once.
- using some #defines could allow to make the usage a bit lighter. IMHO it would allow to reduce
verbosity/hide the OO construction/links. For example
Unknown disse...
can the system read negative value? i try to feed the system with negative input, but the output is wrong, any
solution. thanks
23 de fevereiro de 2013 23:38
AJ O. Alves disse...
Christophe, thanks so much for your notes!
24 de fevereiro de 2013 10:21
AJ O. Alves disse...
Hey Unknow, it is possible! One of my tests is using only negative numbers in FuzzySets and Inputs, and
always i get a good result.
Please, can you explain better what you are trying to do, how are you building your FuzzySets. Take a good
look in "Advanced Example" in this post, i use a negative FuzzySet called "cold" and after i pass a negative
value in the third input.
24 de fevereiro de 2013 10:27
Unknown disse...
Unknown disse...
Unknown disse...
unknow here, the library works, i'm sory about that
7 de maro de 2013 18:50
AJ O. Alves disse...
Ok Sam, thanks to use our library. any doubt, aj.alves@zerokol.com
7 de maro de 2013 21:24
sreeram disse...
i've got trouble at result of defuzzyfy when i have 2 or more fuzzyrule using same fuzzyrule consequent but
different fuzzyantecedent...
why..??
example i' have 2 input
1.temperature have 4 variable
2.humidity have 4 Variable
17 de abril de 2013 01:23
AJ O. Alves disse...
Sreeram, shuld you send me a email (aj.alves@zerokol.com) with the source code?
17 de abril de 2013 08:26
LectorCompulsivo disse...
Just for those who have the same problem: The library cannot be imported to Arduino unless that the folder
name will be changed from eFLL-master to eFLLmaster.
8 de 9 02-08-2016 21:34
zerokol.com: eFLL - A Fuzzy Library for Arduino and Embeded Systems http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino...
Annimo disse...
Hi, i have same problem like Sreeram, i have 2 inputs, and one output.
"when i have 2 or more fuzzyrule using same fuzzyrule consequent but different fuzzyantecedent"
sreeram disse...
I had change the library name eFLL-master to eFLL and still it doesn't works.
21 de maio de 2013 02:03
i've got trouble at result of defuzzyfy when i have 2 or more fuzzyrule using same fuzzyrule consequent but
different fuzzyantecedent...
why..??
example i' have 3 input from gyro sensor
1.X-axis have 4 variable
2.Y-axis have 4 Variable
3.Z-axis have 4 Variable
and 1 output
1.move have 6 variable
Unknown disse...
how i know which desfuzzy method im using ?
And by the way fuzzy->setInput(1, dist); how i know the correct value for Dist ?
26 de outubro de 2015 14:35
John S disse...
Hi, I'm working in a system to control a dc/dc converter, and I have two inputs, 1 output and 16 rules. I
designed the controller in Matlab and tested on arduino. The problem is that the same controller has different
values for the output when tested in Matlab and Arduino. When one rule is fired, can I know their value at the
output membership?, the thing is that I have 4 active rules and the output in Matlab is the average of the
memberships, but in Arduino seems to be the maximum of memberships. I was wondering what does
minimum-mandani mean at the output?
Thanks
28 de maro de 2016 11:50
amruta disse...
Thank you so much for the library
13 de abril de 2016 08:26
Postar um comentrio
9 de 9 02-08-2016 21:34