Fuzzy Logic Controller for an Automatic Braking System

This is a step-by-step tutorial on how to create a Fuzzy logic Controller for an Automatic Braking System using MATLAB(R2015a).  Below is a typical automotive braking system and we shall discuss how the system can be automated based on a set of input parameters.

Image result for Automatic Braking System

Source: www.carparts.com

The problem at hand has been adopted from Artificial Intelligence Illuminated – by Ben Coppin (1st Edition, Jones & Bartlett) – p.516-522.

Image result for ai illuminated ben coppin

Before we look at the problem, we need to understand the four key steps in creating a Fuzzy Logic System (FLS):

  1. Define inputs and outputs
  2. Create a membership function
  3. Create rules
  4. Simulate the fuzzy logic system / Fuzzy Inference System (FIS)

To get clarity on the above steps, we have to analyze the problem at hand. The problem given in the text book may look trivial but the actual scenario might be quite complicated and may comprise of thousands of rules.

Rules 1

 

As per the above problem, there are three inputs:

  1. Pressure on the brake pedal (brake pressure)
  2. Car speed
  3. Wheel speed

And one output:

  1. Brake (which has two decision parameters- Apply Brake or Release Brake)

To apply these rules, using Mamdani inference, the first step is to fuzzify the crisp input values. To do this, we need first to define the fuzzy sets for the various linguistic variables we are using. For this simple example, we will assume that brake pressure is measured from 0 (no pressure) to 100 (brake fully applied).

We will define brake pressure as having three linguistic values: high (H), medium (M), and low (L), which we will define as follows:

                                             H = {(50, 0), (100, 1)}
                                            M = {(30, 0), (50, 1), (70, 0)}
                                            L = {(0, 1), (50, 0)}

Even though the author has considered the the membership function for the input parameter “brake_pressure” as triangular, I would opt for gaussian membership function (which suits the input requirement here)

You can create FIS using MATLAB or sciLab. Both have built-in fuzzy logic toolkits for this. I’m using MATLAB.

Step 1 : Open Matlab and type fuzzy on the command line to invoke the  FLT as shown:

fuzzy

This will open the fuzzy logic designer console as follows:

FL Designer.JPG

Step 2 : Click on the “inputs” section (in yellow) to add inputs. Note that an input is already defined here, we need to add two more for our problem. For this goto–>edit–>add variable–>input

inputoutput.JPG

Step 3: Double click on “BrakePressure” and click on the red-curve. Rename it from “mf1” to “low” and change the Type from ” trimf to gaussmf” as shown below. Similarly, do it for medium and high as well by clicking over the curves:

brkprss.JPG

Step 4: Now let’s fuzzify the car speed input. This can be trapezoidal and triangular since we have a speedometer that can objectively tell the speed (eg. 55.5 mph). Double click on the rectangle that has CarSpeed variable. We will define the car speed as also having three linguistic values: slow, medium, and fast.We will define the membership functions for these values for a universe of discourse of values from 0 to 100:
                                                          S = {(0, 1), (60, 0)}
                                                         M = {(20, 0), (50, 1), (80, 0)}
                                                         F = {(40, 0), (100, 1)}
If the wheel speed is in fact 55, then this gives us membership values as follows:
                                                           M[slow(55)] = 0.083
                                                           M[medium(55)]= 0.833
                                                           M[fast(55)] = 0.25

**M[] for “membership of”

carspeed.JPG

Step 5 : Set the wheel speed on the same parameters as car speed and based on three linguistic variables: Slow, Medium and Fast.

Slow

wheel speeed 1.JPG

medium

wheel speed 2.JPG

fast

fast.JPG

Step 6 : Now that we have defined the inputs, let’s define the output- that is break (Apply_break and Release Break). Both are trapmfs:

brake.JPG

Source: AI Illuminated, Ben Coppin, p.520

 

brake2.JPG

By default, the system uses “Mamdani” model. Here the defuzzification is centroid methoddefuzz.JPG

The formula for centroid method is:

formula

How the fuzzy values for the antecedents of the rules are applied to the consequents is being shown below:

clipping.JPG

Source: AI Illuminated, Ben Coppin, p.521

Step 7 : Remember the rules? Yeah… now since we defined the fuzzy variables and their membership attributes, we need to create the rule base by feeding it into the system. For this go to –> edit –>rules to get the Rules Editor. You can add-edit-delete rules as shown below. Once done, click ‘close’ to return to the fuzzy logic designer.

rulesrama.JPG

Step 8 : You can save it to the hard disk by exporting it as shown below:

save.JPG

You can export it to your workspace as well so that it’s instance is available throughout the session and you can invoke it whenever you want. To do this goto –> file–>export to the workspace:

click “OK”

sys.JPG

conso.JPG

Step 9 : Now your FIS (Fuzzy Inference System) for the automatic Breaking System is ready.

Click on your Fuzzy Logic Designer window-  view–>rules to see all the rules sets as shown below:

rulesets.JPG

You can drag the red line (|) to left (<–) or right (–>) and see how the crisp output varies for various inputs as below:elow :

vary.JPG

Step 10 : Plotting the surface. If you are using sciLab, you need to use a function called “plotsurf()” to plot the surface of the plane created by the FIS you have just created, but MATLAB makes things easier. You just have to click –> view –>surface to view the surface as shown below:

Surfaceplot.JPG

You can rotate it by dragging the surface :

drag.JPG

You can aslo view the output in terms of just one parameter by varying the selection criteria :

single.JPG

The above plot shows how the output (brake) varies with respect to Car_Speed. You can try it out for other input parameters like Wheel_Speed and Brake_Pressure.

References:

  1. Artificial Intelligence Illuminated, Ben Coppin, First Edition, Jones and Bartlett.
  2. Artificial Intelligence – A Guide to Intelligence Systems, Michael Negnevitsky, 3rd Edition
  3. http://www.mathworks.com

If you have any queries, you can e-mail me at : srinath.krishnamoorthy@villacollege.edu.mv

About me :

I m Srinath Krishnamoorthy. I m an MTech in Computer Science and Engineering from MA College of Engineering, Kothamangalam, and BTech in Information Technology from Government Engineering College, Palakkad. I m teaching Artificial Intelligence for the University of West of England (BSc Computer Science) in Male`, Maldives. My area of interests is AI, Data Analytics, Computational Intelligence and Theory of Computation.

Srinath Krishnamoorthy (1)
Srinath Krishnamoorthy

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: