top of page

Fuzzy Logic Controlled Car

MATLAB, Unity C#

The Project​

The goal was to control a car moving towards a user controlled racing line on a straight road.

using a form of AI, Fuzzy Logic. A system was designed to take 2 inputs and provide an output.

 

The inputs are the Distance from the car to the line and the current horizontal Velocity, and the output is the amount the car should steer back towards the line.

 

​

FuzzyLogicCar.gif
2000px-Fuzzy_logic_temperature_en.svg_.p

Matlab Design

I designed a Fuzzy Associative Map (FAM) which defines the Ruleset for the system (shown here). Each output

(LL, L, Z, R or RR) is part of the defined Output Membership Function (shown here). ​

​

The Ruleset (shown here) defines 9 rules. It is used to compare each of the seperate sections in every Input Membership Function to provide a output amount for every rule, and a final output amount is determined using the chosen 'Defuzification' method. 

​

Basically, after comparing every rule with each other, the Centroid of the final shape is used as the output result.

Ruleset

Capture.PNG

What is Fuzzy Logic?

Fuzzy logic takes the idea of the traditional Boolean logic used in computers (true or false) and replaces it with multiple ranges that refer to ‘how much’ or ‘how little’ of a value we use.
 
For example, instead of describing temperature at either hot or cold, we instead tend to use a large range of values, such as freezing cold, slightly warm, very hot etc. 

FAM

3x3FAM.PNG

Output Membership Function

Output.png

The Application 

​

​For the application, I adapted the Matlab logic to work in C# in a Unity application. It uses the pre-defined rule set to compare the membership functions and calculate the total centroid of the output graph, using this as the crisp output data (defuzzification).

​

The user controls the racing line with the arrow keys and the system takes input from the cars distance to the line and the horizontal velocity. The car is moved by adding the output value (Steer Amount) to its current horizontal velocity.

 

The inputs can also be controlled by weighting values for alternative output results, such as smoother/more aggressive turning, or allowing the car to overshoot the line, seen in the GIF.

app.png
bottom of page