Fuzzy Logic Project

This was a simple project that demonstrates using a fuzzy logic system to determine how a platform should behave to keep a rolling ball on top of it. The fuzzy input captures the position of the ball on the platform and the system outputs an angle for the platform to rotate to.

Fuzzy Logic Process

Fuzzy Logic inference is a process that determines the membership of a value in a set wherein the value might have partial membership to that set. In the case of this project, the set "far-left" would include positions on the platform which are on the far left of it. The next set might be "middle-left" and would include values further right than the previous.

With this setup, a value might be on the left of the platform and considered 40% far left and 60% middle left. This input is then processed and outputs a function that highlights the portion of the rules that the input is covered by. This output can then be interpreted as a single value.

Fuzzy Inference System

The Fuzzy Inference system describes the process of input to output and it made up the bulk of the work on this project. I chose to use C# with Unity to take advantage of all the built-in graphical functionality.

This project involved a lot of delegate function use which is something that I had not used in the past very much at all. Each rule of the fuzzy set (shown above in various colors) uses a delegate to evaluate the function at a given X value. Once the firing levels are calculated, the output set needs to be constructed again with delegates to represent each of the pieces of the piecewise function. The most difficult part of this task was combining the 5 or more overlapping function pieces into a function that could be evaluated continuously across the entire range.

The general process for condensing the pieces given as output was to iterate over every piece and find an intersection between them. If there was an intersection present then the ranges of that piece could be adjusted to connect them at the intersection. If there was no intersection present then I can check to see if one piece encompasses the entirety of another. It is important to get the maximum area of this function so it can be "defuzzified" properly and get the correct output angle. The piece that represents a smaller output can be discarded.

After this process iterates until no pieces are discarded, the final fuzzy output is achieved and displayed in the second graph above (in white).