Shop OBEX P1 Docs P2 Docs Learn Events
Convert Fuzzy Library for Arduino to the Propeller — Parallax Forums

Convert Fuzzy Library for Arduino to the Propeller

Hello everyone.

This is a great library for Fuzzy Logic: <http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino.html&gt;

I want use it in propeller. Any sugestion?

Thanks!
AS
«13

Comments

  • MJBMJB Posts: 1,235
    AS wrote: »
    Hello everyone.

    This is a great library for Fuzzy Logic: <http://www.zerokol.com/2012/09/arduinofuzzy-fuzzy-library-for-arduino.html&gt;

    I want use it in propeller. Any sugestion?

    Thanks!
    AS
    how do you want to use it?
    SPIN ? PASM?
    C/C++ with GCC ... ??


  • I know you want to maybe rewrite the Arduino code, but you may be interested in ViewPort that includes Fuzzy Logic for the Propeller:

    http://onerobot.org/products/viewport/
  • ASAS Posts: 149
    edited 2016-01-18 00:49
    MJB wrote: »
    how do you want to use it?
    SPIN ? PASM?
    C/C++ with GCC ... ??


    I prefer have the Fuzzy library in SPIN!
    How is the easy way for use the Fuzzy library for arduino that already exist?
    C/C++ with GCC I think can be easier (but not easy for my knowledge) but I have no idea the difficulty level.

    thanks for the interest
    AS
  • ASAS Posts: 149
    Publison wrote: »
    I know you want to maybe rewrite the Arduino code, but you may be interested in ViewPort that includes Fuzzy Logic for the Propeller:

    http://onerobot.org/products/viewport/

    Thanks for the sugestion.
    AS
  • The logic compiles great, no errors or even warnings. Unfortunately, the "general_simple_sample" is too large even in CMM mode, even after I replaced the call to std::cout. In CMM mode, it overflows hub by 5 kB, and LMM by 10 kB. XMM modes work great though.

    Here's the output I got using xmmc on the Quickstart:
    Propeller Version 1 on /dev/ttyUSB0
    Patching __cfg_txpin with 0000001e
    Patching __cfg_baudrate with 0001c200
    Loading the serial helper to hub memory
    9808 bytes sent                  
    Verifying RAM ... OK
    Loading external memory driver 'eeprom_xmem.dat'
    884 bytes sent                  
    Loading program image to flash
    43324 bytes sent                  
    Loading .xmmkernel
    1984 bytes sent                  
    [ Entering terminal mode. Type ESC or Control-C to exit. ]
    Entrada: 0, Saida: 0.000000
    Entrada: 1, Saida: 10.000000
    Entrada: 2, Saida: 10.000001
    Entrada: 3, Saida: 9.999999
    Entrada: 4, Saida: 10.000000
    Entrada: 5, Saida: 10.000000
    Entrada: 6, Saida: 10.000002
    Entrada: 7, Saida: 9.999999
    Entrada: 8, Saida: 9.999999
    Entrada: 9, Saida: 10.000001
    Entrada: 10, Saida: 10.000000
    Entrada: 11, Saida: 10.000000
    Entrada: 12, Saida: 9.999999
    Entrada: 13, Saida: 10.000000
    Entrada: 14, Saida: 10.000001
    Entrada: 15, Saida: 10.000000
    Entrada: 16, Saida: 10.000000
    Entrada: 17, Saida: 9.999999
    Entrada: 18, Saida: 10.000000
    Entrada: 19, Saida: 10.000001
    Entrada: 20, Saida: 10.000000
    Entrada: 21, Saida: 10.000001
    Entrada: 22, Saida: 10.000000
    Entrada: 23, Saida: 9.999999
    Entrada: 24, Saida: 10.000000
    Entrada: 25, Saida: 10.000000
    Entrada: 26, Saida: 10.000001
    

    No idea what this means! :D But it works
  • So now that we know it compiles with PropGCC, how would you like to use it AS? I can either show you what I did so you can replicate it yourself, or I could simply provide you with the static libraries and header files so that you can link it to your own program via SimpleIDE.
  • ASAS Posts: 149
    Hi DavidZemon. Thanks a lot for your time.

    Fuzzy logic is a great solution to control systems/machines, in some situations better than PID, when we have nonlinear systems is better. I have some knowledge about FL but simulated and controled in LabView, at this moment I already can simulated in LabView and control with Arduino, but in my opinion when we think in machines/systems we need more cores and I think the Propeller is a better solution.

    I published a paper about this work (controled and simulated in LV) <http://www.mirlabs.net/nabic14/proceedings/html/paper25.xml&gt; (see the attach file) I can explain the example of that paper in other words.

    I want to replicate/learn what you have done with PropGCC and learn how you make that static libraries and header files for the SimpleIDE (if it isn´t very dificult. I hope you can help me.
    It overflows with the simple sample? It is not good, I put 2 functions like the advanced sample and the serial comunication in Leonardo Arduino.

    Any question about FL, just ask.
    Sorry for any mistake in my english.
  • Oh
    My
    Goodness.

    I am duuummbbb :D

    I was not compiling the library with any flags - not even optimization! I need to make an enhancement to PropWare so that it is easier to compile libraries, but long story short, even the "general_advanced_sample" compiles in LMM mode with propeller-load reporting 26.5 kB being sent to the prop (so probably 24-25 kB binary size).

    I'm writing up a full description of how I made this work. Look for it in a few minutes.
  • AS wrote: »
    I want to replicate/learn what you have done with PropGCC and learn how you make that static libraries and header files for the SimpleIDE (if it isn´t very dificult. I hope you can help me.

    As the author of PropWare, that was my goto choice for attempting to build eFFL. I forked the eFFL project and then added two files to it which are used with CMake - a Makefile generator build system. PropWare is build using CMake and is really easy to use.

    So, in the root directory of eFFL, I added a file named CMakeLists.txt, and placed the following content:
    cmake_minimum_required(VERSION 3.3)
    find_package(PropWare REQUIRED)
    
    project(eFFL)
    
    set(MODEL lmm)
    set_compile_flags()
    
    add_library(eFFL
        Fuzzy
        FuzzyComposition
        FuzzyInput
        FuzzyIO
        FuzzyOutput
        FuzzyRule
        FuzzyRuleAntecedent
        FuzzyRuleConsequent
        FuzzySet)
    
    add_subdirectory(examples)
    

    Line 1 determines which version of CMake is required. PropWare has a very strict requirement on CMake 3.3 at the moment. The second line imports everything necessary to build projects for the Parallax Propeller using PropWare's build system. Next is the "project" function, which simply declares that we have ourselves a project named "eFFL". Following that we set the memory model. Read all about memory models here. the "set_compile_flags()" function is supposed to be an internal part of PropWare, and I ask that you please ignore this line for the moment. When I finish making the enhancement to PropWare (it will be a PropWare 2.1 release), you will no longer need that line.

    We then create the library. The first line, with "eFFL" in it, declares the name of the library. Following that is the name of every source file - you can include the file extension if you wish, but it is not necessary.

    At this point, you have everything you need to compile the static library. Simply execute the following on the command line, starting from the project root:
    mkdir bin
    cd bin
    cmake ..
    make
    

    And you'll find libeFFL.a in <project root>/bin/libeFFL.a.

    The final line, add_subdirectory(...), simply says "look in the examples directory for some more configuration". The file examples/CMakeLists.txt just has a couple lines that describe how to build executables. The create_executable function takes a couple arguments, very similar to "add_library". The first argument is the name of the executable, and all remaining arguments are source files (with or without file extensions). The "target_link_libraries" function allows you to link libraries with executables - so you can see the first argument to that function is the name of the executable, and all remaining arguments are the libraries you want linked.

    You can see my full commit here. I made very basic changes to the example source code to replace references to std::cout with PropWare's pwOut, which is similar but smaller.
  • ASAS Posts: 149
    OMG this is a great work.

    Really thanks. I will try everything you explain and I will have doubts for sure.

  • AS wrote: »
    OMG this is a great work.

    Really thanks. I will try everything you explain and I will have doubts for sure.

    I left a lot of blanks there, so do please feel free to ask any questions. I suppose there's one really big and important step I should have mentioned already: you'll need PropWare installed :)
    http://david.zemon.name/PropWare/Download.xhtml
    Note that the first option on that download page, "SimpleIDE" won't work for you because it only includes the PropWare libraries and headers - not the build system.
  • ASAS Posts: 149
    edited 2016-01-20 00:16
    DavidZemon,
    - I Installed PropWare for Windows.
    - In the root directory of eFFL, I added a file named MakeLists.txt, and placed the content you wrote.

    When you say: "At this point, you have everything you need to compile the static library. Simply execute the following on the command line, starting from the project root:"
    I need execute CMake?
    When I execute CMake or CTest or CPack it open and close so fast that I can´t read nothing :snooty: . It´s normal? What I´m doing wrong?

    Thanks
  • AS wrote: »
    DavidZemon,
    - I Installed PropWare for Windows.
    - In the root directory of eFFL, I added a file named MakeLists.txt, and placed the content you wrote.

    You forgot the "C" at the front. CMakeLists.txt
    Also, remove the final line - the one that reads "add_subdirectory(examples)". We'll get the static library compiling and then try the examples.
    AS wrote: »
    When you say: "At this point, you have everything you need to compile the static library. Simply execute the following on the command line, starting from the project root:"
    I need execute CMake?
    When I execute CMake or CTest or CPack it open and close so fast that I can´t read nothing :snooty: . It´s normal? What I´m doing wrong?

    Thanks

    CMake, CTest, and CPack are all interactive command-line tools that require certain arguments to execute correctly.

    Keep in mind two things as I walk you through the instructions for this: 1) I am more than happy to bundle up the static libraries and headers for you at any time, and 2) I am more than happy to continue answering your questions as long as you like.

    Now, on to answering your question.

    GNU Make
    You'll need GNU Make (make.exe) installed on your machine. There are lots of different ways to do this. One of the easiest is to download and install this file.
    Once installed, add the folder containing "make.exe" to your PATH variable. If you are using a 64-bit machine that is Windows Vista or newer, then the path is most likely "C:\Program Files (x86)\GnuWin32\bin"

    Preparing the command line
    Open the terminal by typing "cmd" into the start menu and selecting the option titled "Command Prompt".
    You should get a screen that says something like:
    Microsoft Windows [Version 10.0.10586]
    (c) 2015 Microsoft Corporation. All rights reserved.
    
    C:\Users\David>
    
    Type "where cmake" and press enter. If you don't see something along the lines of "C:\PropWare\PWCMake\bin\cmake.exe" then you forgot to add CMake's bin directory to your PATH. See Step 3 of "Microsoft Windows" on PropWare's download page.

    Note that each time you modify the PATH variable, you'll need to close and re-open the command prompt.

    A message such as "INFO: Could not find files for the given pattern(s)." means that you did not set the PATH variable correctly.

    Once "where cmake" returns the path to the CMake executable, try "where make". This should return the path to make.exe.

    Running CMake
    Let's assume you downloaded eFFL to a directory named "C:\Users\AS\eFFL", and therefore you have a file named "C:\Users\AS\eFFL\CMakeLists.txt". In the command prompt, type the following commands. This will create a new directory to store CMake generated files, object files, and the static library and then build everything.
    cd C:\Users\AS\eFFL
    mkdir bin
    cd bin
    cmake -G "Unix Makefiles" ..
    make
    

    If all goes well, you should now be able to see libeFFL.a in your file browser.

    Okay! I think that should do it. Let me know if anything doesn't go smoothly, and we'll get it fixed!
  • ASAS Posts: 149
    edited 2016-01-20 20:06
    OK! I think I´m in the right path! :)

    But when I write:
    cmake -G "Unix Makefiles" ..
    

    It gets bloked. (see the file attached)

    I will wait you tell me the next step...
    Thanks a lot!
  • AS wrote: »
    I´m editing this comment because It´s everything OK! at the moment, I want delete the comment but I can´t :)

    I don't see an attached file :(
  • ASAS Posts: 149
    :) I was editing!


    I attached now.
  • Well.... there's no error in that screenshot. Hard to help with that one :P
  • ASAS Posts: 149
    The comment I made before editing, I have errors because I forgot add the folder containing "make.exe" to my PATH variable.

    Now when I write:
    cmake -G "Unix Makefiles" ..
    

    It gets bloked. :(



  • Do you mean it is frozen? How long have you waited? CMake and Make aren't the fastest on Windows, but they shouldn't take more than a minute to run on such a small project, even on a really old computer. If they're truly frozen - not running at all, I'm afraid I don't know why it could be. Is task manager showing CPU usage? How old is the computer?
  • ASAS Posts: 149
    I tried everything.. :P

    My computer has about 8 years, CPU usage is not more than 40%.

    I send attached where it blocks, it make some files and directories.

    It should creat the file libeFFL.a in the bin directory? If you send me this file I can continue the process from here? :D

    (I think the reason is that my computer have a lot of junk?!)

    thanks
  • This is just awful :( I'm sorry CMake isn't working for you. Here's all the static libraries and headers in a zip for you. The instructions for importing that into SimpleIDE are nearly identical to PropWare (the ZIP is organized in the same way) so just use the instructions from my downloads page for "SimpleIDE (Any Operating System)".

    As for your system... 8 years is pretty old... but it shouldn't be so old that CMake freezes on you. Let's try putting cmake into trace mode. Instead of
    cmake -G "Unix Makefiles" ..
    

    let's try
    cmake --trace -G "Unix Makefiles" ..
    

    And see where that gets you.
  • ASAS Posts: 149
    If I understand well the ZIP file have the work all done to use eFLL, I only need follow the instructions for "SimpleIDE (Any operating system)" to make it work.

    Putting cmake into trace mode is to see where it freezes?
    cmake --trace -G "Unix Makefiles" ..
    

    I sending the file attached.

    Thanks a lot
  • ASAS Posts: 149
    After the 8 step in the instructions for "SimpleIDE (Any operating system)". What should I do?
  • DavidZemonDavidZemon Posts: 2,973
    edited 2016-01-21 03:05
    AS wrote: »
    After the 8 step in the instructions for "SimpleIDE (Any operating system)". What should I do?

    At that point, you can write your code and link against the project. Try executing this code from your project in SimpleIDE. It's the general_simple_sample file, using PropWare's serial communication. You'll need to add both PropWare and eFFL to your project. In other words, you'll need to run through the "SimpleIDE (Any Operating System)" instructions twice: once for PropWare, once for eFFL.
    #include <PropWare/printer/printer.h>
    #include <PropWare/c++allocate.h>
    #include "FuzzyRule.h"
    #include "FuzzyComposition.h"
    #include "Fuzzy.h"
    #include "FuzzyRuleConsequent.h"
    #include "FuzzyOutput.h"
    #include "FuzzyInput.h"
    #include "FuzzyIO.h"
    #include "FuzzySet.h"
    #include "FuzzyRuleAntecedent.h"
    
    int main(int argc, char *argv[]) {
    	// Instanciando um objeto da biblioteca
    	Fuzzy* fuzzy = new Fuzzy();
    
    	// 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
    
    	fuzzy->addFuzzyInput(distance); // Adicionando o FuzzyInput no objeto Fuzzy
    
    	// Criando o FuzzyOutput velocidade
    	FuzzyOutput* velocity = new FuzzyOutput(1);
    	// Criando os FuzzySet que compoem o FuzzyOutput velocidade
    	FuzzySet* slow = new FuzzySet(0, 10, 10, 20); // Velocidade lenta
    	velocity->addFuzzySet(slow); // Adicionando o FuzzySet slow em velocity
    	FuzzySet* average = new FuzzySet(10, 20, 30, 40); // Velocidade normal
    	velocity->addFuzzySet(average); // Adicionando o FuzzySet average em velocity
    	FuzzySet* fast = new FuzzySet(30, 40, 40, 50); // Velocidade alta
    	velocity->addFuzzySet(fast); // Adicionando o FuzzySet fast em velocity
    
    	fuzzy->addFuzzyOutput(velocity); // Adicionando o FuzzyOutput no objeto Fuzzy
    
    	//-------------------- Montando as regras Fuzzy
    	// FuzzyRule "SE distancia = pequena ENTAO velocidade = lenta"
    	FuzzyRuleAntecedent* ifDistanceSmall = new FuzzyRuleAntecedent(); // Instanciando um Antecedente para a expresso
    	ifDistanceSmall->joinSingle(small); // Adicionando o FuzzySet correspondente ao objeto Antecedente
    	FuzzyRuleConsequent* thenVelocitySlow = new FuzzyRuleConsequent(); // Instancinado um Consequente para a expressao
    	thenVelocitySlow->addOutput(slow);// Adicionando o FuzzySet correspondente ao objeto Consequente
    	// Instanciando um objeto FuzzyRule
    	FuzzyRule* fuzzyRule01 = new FuzzyRule(1, ifDistanceSmall, thenVelocitySlow); // Passando o Antecedente e o Consequente da expressao
    	fuzzy->addFuzzyRule(fuzzyRule01); // Adicionando o FuzzyRule ao objeto Fuzzy
    
    	// FuzzyRule "SE distancia = segura ENTAO velocidade = normal"
    	FuzzyRuleAntecedent* ifDistanceSafe = new FuzzyRuleAntecedent(); // Instanciando um Antecedente para a expresso
    	ifDistanceSafe->joinSingle(safe); // Adicionando o FuzzySet correspondente ao objeto Antecedente
    	FuzzyRuleConsequent* thenVelocityAverage = new FuzzyRuleConsequent(); // Instancinado um Consequente para a expressao
    	thenVelocityAverage->addOutput(average);// Adicionando o FuzzySet correspondente ao objeto Consequente
    	// Instanciando um objeto FuzzyRule
    	FuzzyRule* fuzzyRule02 = new FuzzyRule(2, ifDistanceSafe, thenVelocityAverage); // Passando o Antecedente e o Consequente da expressao
    	fuzzy->addFuzzyRule(fuzzyRule02); // Adicionando o FuzzyRule ao objeto Fuzzy
    
    	// FuzzyRule "SE distancia = grande ENTAO velocidade = alta"
    	FuzzyRuleAntecedent* ifDistanceBig = new FuzzyRuleAntecedent(); // Instanciando um Antecedente para a expresso
    	ifDistanceBig->joinSingle(big); // Adicionando o FuzzySet correspondente ao objeto Antecedente
    	FuzzyRuleConsequent* thenVelocityFast = new FuzzyRuleConsequent(); // Instancinado um Consequente para a expressao
    	thenVelocityFast->addOutput(fast);// Adicionando o FuzzySet correspondente ao objeto Consequente
    	// Instanciando um objeto FuzzyRule
    	FuzzyRule* fuzzyRule03 = new FuzzyRule(3, ifDistanceBig, thenVelocityFast); // Passando o Antecedente e o Consequente da expressao
    	fuzzy->addFuzzyRule(fuzzyRule03); // Adicionando o FuzzyRule ao objeto Fuzzy
    
    	for(int dist = 0; dist < 100; dist++){
    		fuzzy->setInput(1, dist);
    
    		fuzzy->fuzzify();
    
    		float output = fuzzy->defuzzify(1);
    		pwOut << "Entrada: " << dist << ", Saida: " << output << '\n';
    	}
    	return 0;
    }
    
  • By the way, I thought it would be helpful to show how you can use PropWare's libraries to convert a basic Arduino application to the Propeller. Here's the diff for arduino_simple_example in eFFL

    https://github.com/DavidZemon/eFLL/commit/12d25c777b73d1fdf1b5934df7631c5cbf1945b2

    Of course, you can also use libpropelleruino. It hasn't seen activity in a long while, but I suspect it still works all the same: https://code.google.com/p/lib-propelleruino/
  • ASAS Posts: 149
    Hi DavidZemon,

    I think I had done everything right, but I got this error (see the file attached).
    DavidZemon wrote: »
    Of course, you can also use libpropelleruino. It hasn't seen activity in a long while, but I suspect it still works all the same: https://code.google.com/p/lib-propelleruino/

    Where I can download it? (I don´t see any link to download)
    You have any sugestion where I can learn something about that?

    Thank you
  • AS wrote: »
    Hi DavidZemon,

    I think I had done everything right, but I got this error (see the file attached).

    Common problem :) Simply rename your program from *.c to *.cpp. The compiler won't recognize it as a C++ program until you change the file extension to "cpp".
    AS wrote: »
    DavidZemon wrote: »
    Of course, you can also use libpropelleruino. It hasn't seen activity in a long while, but I suspect it still works all the same: https://code.google.com/p/lib-propelleruino/

    Where I can download it? (I don´t see any link to download)
    You have any sugestion where I can learn something about that?

    Thank you

    It may be available as source only. I'm afraid I really don't know too much about that library, other than it aims to be Arduino-compatible. No idea how far along it is, or how close to "compatible" it got. Here's the git clone command: https://code.google.com/p/lib-propelleruino/source/checkout
  • ASAS Posts: 149
    I lost some detail :P

    SimpleIDE freezes at 88% when building.

    what I´m doing:
    1. Open SimpleIDE
    2. New Project: general_simple_sample.cpp
    3. Copy paste the code
    4. make everything you say in "SimpleIDE (Any Operating System)"
    Add the path for Include and Library to the eFLL and PropWare-Generic

    What you think it can be?
  • What version of simpleide?
  • ASAS Posts: 149
    SimpleIDE Version 1.0.2 (RC2)
Sign In or Register to comment.