Fuzzy Logic Control

By | December 25, 2015

Fuzzy Logic Control

Some people describe fuzzy logic in mystical terms, as if it’s a magical way of making a computer think like a human. It’s not. It’s a simple way of mapping an input to an output. There’s nothing fuzzy about it.

Let’s look at an example. Say you’re making an auto-throttle for an autonomous go-kart.

Go-kart performance

The throttle can go from 1 up to 9. The kart goes for a test drive to see how fast it goes at each throttle setting.

Plotting the results, the result is the blue line on the graph.

For a given speed, how could the required throttle setting be calculated? Let’s try calculating the linear function for this problem. The top speed is 5 and there’s 8 throttle settings, so gain is 5/8 = 1.6. The first throttle setting is 1, so the bias must be 1. The linear function is y=x*1.6+1

To prove, let selected speed = 0
throttle = 0*1.6+1 = 1
Now let selected speed = 5
throttle = 5*1.6+1 = 9

Great, that all agrees with the graph. Let’s try selected speed = 1.5m/s

Linear approximation fail

throttle = 1.5*1.6+1 = 3.4

Hang on, a throttle setting of 3.4 does not give a speed of 1.5m/s. Not even close! Looking at the graph, the throttle setting for 1.5m/s should be around 4.6.

Clearly linear control cannot be used here. What’s required is a better way of mapping the speed input to a throttle output.

This is where fuzzy logic becomes really useful. Using fuzzy logic, it’s possible to closely approximate non-linear functions. Using real measurements as guidance, fuzzy logic can calculate (almost) exactly the best throttle setting for a given speed.

This video actually explains the workings of fuzzy logic quite well.

Terminology Review

Crisp input – A number. It’s just a flaming real number that will be mapped onto the output. Using the go-kart control example, it’s the selected speed.

Crisp output – It’s just a number! This one is the output. It’s the throttle setting.

Fuzzy set – One of those triangular shapes from the video. Each set has a minimum point, a peak and a maximum point that determine it’s range. It also has a weight – or a value. Fuzzy logic requires at least one, but usually 3 or more sets.

DOM – Degree of membership. The DOM ranges from 0 to 1. It represents how close the crisp input is to the peak of the triangle. If the input is outside the triangle, the DOM is 0. The closer the input is to the peak of the triangle, the closer the DOM will be to 1.

Output component – The output component of a set is the DOM multiplied by the weight of the set. The output components are added together to produce the crisp output.

Example Using ETK

Graphing the output file gives this image

fuzzy_graph

The X axis is speed (x10). The Y axis is throttle.

Now, with this new Fuzzy logic generated graph, selecting a speed of 1.5 gives a throttle of 4.65. Awesome!

Leave a Reply

Your email address will not be published. Required fields are marked *