Arduino FIST: Fuzzy Inference System Translation

First, let me introduce you to FROBO (Fuzzy Robot).  He’s small and he’s got an Arduino for a brain.  He uses three parallax ping sensors to sense the world around him.  FROBO uses two DC motors with a gearbox to achieve differential drive and wears a speed-flag for safety from other robots (you wouldn’t want a big robot to step on him would you?).

Perhaps the most interesting thing about FROBO is that he only took about eight hours to complete from start to finish including programming.  In fact, creating FROBO’s run-time program took less time than locating the short that was making the drive motors act strangely.

Arduino FIST (Fuzzy Inference System Translation) allowed for rapid prototyping of FROBO’s behaviors.  In short, Arduino FIST takes a .FIS (fuzzy inference system) file created by MATLAB, or by hand, and turns it into C code that is useable on the Arduino, or just about any other micro-controller system as long as it has some support for floating point math.  It’s probably time to give you a quick refresh on fuzzy systems.

Fuzzy systems allow you to take natural language concepts like “too close” and use them in a rule-set for controlling systems.  For example:  If Left-Wall is Too Close Then Left Wheel is Fast and Right Wheel is Slow.  That rule is used by a fuzzy system to keep the robot from hitting an object to it’s left.  Fuzzy systems use geometric representations of concepts like “Too Close” that are pretty intuitive once you’ve had a chance to play with them.  The important thing to know about FIST is that it takes care of all the hard “mathy” parts of implementing your fuzzy system and allows you to focus on rule creation.

THIS GUY explains the whole fuzzy thing with a great accent.

FROBO relates the information it gathers from its three sensors to outputs on its motors through a set of rules.  Very minimal Arduino code has to be written.  In fact, to get FROBO to run, the pins had to be defined, a call to the Fuzzy system had to be created, and the output to the motors using AnalogWrite (PWM) had to be written – and that’s it!  The entire behavior of the robot was defined through geometric doodles and simple rules in MATLAB.

For those of you that don’t have MATLAB, it is possible to write the .FIS format by hand, and we’ll provide a page defining how to do that.

If there’s enough interest ($5,000 or more in donations) we will also write a visual interface program that produces .FIS files in a way similar to that of MATLAB.

You can access Arduino FIST on our website here: http://www.makeproto.com/projects/fuzzy/matlab_arduino_FIST/index.php

To use it:

1. Design a cool robot (or control system).

2. Write a fuzzy system using MATLAB or by hand defining the behaviors of said robot.

3. Dump the .FIS file onto our website at the link provided above.

4. Two output files will be produced, a .h file and a C file.  Copy the contents of the C file and dump it into your Arduino IDE.  Put the .h file in the same folder as your Arduino sketch.

5. To access the system, create an array of inputs and an array of outputs.

6. Call the system function with a pointer to the inputs and a pointer to the outputs.  (the function will have the same name as your .FIS file).

6. Use the outputs of the FIS to control whatever it is you need to control.

NOTE: Arduino FIST is not guaranteed for any purpose whatsoever.  Please do not design your new life support system using Arduino FIST.

That’s all there is to it folks!  Have fun.

15 Comments

  1. Sam
    Sam October 29, 2012 at 4:30 AM . Reply

    Hi! It’s really great that you made this.
    I’ve created the Fuzzy part in Matlab, and i really don’t understand on the step 5 and 6 above. Could you please explain and perhaps provide some example on the Arduino coding using the Arduino FIST? It would be really helpful for us newbie.

  2. Jason Lewis
    Jason Lewis November 26, 2012 at 9:03 AM . Reply

    There seems to be a bug in the centroid function. tx and tx should be summed using a “+=”. The correction is shown below…
    tx += (x[i] + x[i+1]) * t;
    ty += (y[i] + y[i+1]) * t;

    1. KodeNinja
      KodeNinja November 26, 2012 at 10:14 AM . Reply

      Noted. It’ll be fixed in the update.

  3. MATRIX
    MATRIX November 27, 2012 at 1:04 PM . Reply

    I Think there is still some error in addition to above correction in
    centroid function…please update the right code.

  4. MATRIX
    MATRIX November 28, 2012 at 3:47 AM . Reply

    dear Kodeninja,
    your centroid function is working perfectly if output membership function is triagular….but if its a trapezoid then it is giving the wrong output…plz help me to get the right function valid for all type of membership function…..(by the way ur rest of the code is appreciable working perfect…NICE JOB)

  5. ALDANAHER
    ALDANAHER December 5, 2012 at 10:50 AM . Reply

    Excellent contribution BUT NOT AS I HAVE RUN THE CODE TO IN Arduino DO NOT UNDERSTAND HOW steps 4 to 6 ME CAN you please help me with a broader explanation THEME

  6. Dipti
    Dipti December 31, 2012 at 2:18 AM . Reply

    Thank you for making this tool. Its really helpful but I didn’t understand the meaning of point no 5 and 6. Can you please elaborate them a little .

  7. Dipti
    Dipti January 9, 2013 at 2:32 AM . Reply

    dear admin,
    This application is very helpful. Thank you for making this. I am through with the step nos 1-4 but I am really confused about step no 5 n 6. Can u please help me to get through them so that I can move forward with my project. It will be a great help to me. Thank you.

  8. Jorge Cardenas
    Jorge Cardenas February 4, 2013 at 1:35 PM . Reply

    Dear KodeNinja,

    I can’t seem to figure out where does the program get lost when I am using an input with a negative value. My input ranges [-5 5] but while reading the code I can’t see where is the problem. Hope you can give me an advice.

    Thank you.

  9. Adevil
    Adevil March 16, 2013 at 10:38 PM . Reply

    Hope you are in the best of your health and spirits.
    there seems to be a problem I am encountering in the Aggregate3 function where ‘_mmfloat3 mf’ is undefined. Some assistance would really be appreciated.

  10. damon
    damon April 18, 2013 at 6:11 PM . Reply

    Can you post the code you created for your robot as an example? I’m trying to implement a fuzzy controller using your system and cant seem to grasp how you intend to input and output values. Is the .c file supposed to be edited further to operate as a library for the arduino?

  11. Eko
    Eko June 18, 2013 at 5:15 PM . Reply

    The interface seems to be down.
    It keeps telling me that only Mamdani type is supported, even if the file is a Mamdani. I’ve got MAtlab 2008, I’m using the tipper example file.
    I’ve also tried to put all membership function to trimf, it doesn’t work either.
    Thank you

  12. maria
    maria July 10, 2013 at 12:16 AM . Reply

    while running the program error occurs as mf cannot be used as function and also mf_float3 has not been declared.what does this indicate?
    pls cud u help me out

  13. Robert
    Robert October 18, 2013 at 6:20 AM . Reply

    Really appreciate your taking the effort to create this system and availing it to us. Which Arduino did you use?

  14. xuling
    xuling November 28, 2013 at 6:00 AM . Reply

    float* values

    float* what`s means?im newbie

Post Comment