Fuzzy Logic and Genetic Algorithms
Fuzzy Logic – Speed Control for DC Motor
Mohamed Abdul Malik. J, 2018103043
Nidya. M, 2018103046
Srikanth. G. R, 2018103603
Introduction to fuzzy logic:
There are generally two types of logic which can be implemented, that is, crisp logic
and fuzzy logic. Crisp logic deals with boolean values of membership, such as 0 and
1, meaning values in a crisp set can only be 0 or 1. Fuzzy logic assumes membership
values between 0 and 1, meaning in a fuzzy set, we can use decimal or fraction values
that are in the 0 to 1 range, such as 0.2, 0.6, 0.8 etc. Such values can be associated
with phrases such as "high", "low", "hot", "cold", "less", "more", etc. These terms are
known as linguistic variables, which can take a range of fuzzy values. Functions
which are used to assign these variables are called membership functions, and we will
be using three of them in this particular implementation.
We will see how we can apply these fuzzy logic techniques to our use case, i.e.
controlling the speed for a DC motor.
Application – DC Motor:
First, we need to understand what exactly a DC motor does. It is a device that
converts electrical energy to mechanical energy. Simplifying, it can take an input
voltage and convert that to a particular speed by which it runs. It is used in various
areas, such as printers, fuel pumps and electrical vehicles. Generally a DC motor's
speed is controlled manually, or by using an automated control device.
First off, we need to know the factors affecting the speed in a DC motor. We know
the basic EMF equation for a DC motor:
Rearranging so that speed (N) ends up on the RHS, we get:
N = 60A E / PZØ
As we know k = PZ/60A, which is constant, we get:
N = E / kØ
Here, we can see that the speed of the DC motor (N) is directly proportional to the
emf (E) and inversely proportional to the flux of the DC motor (Ø).
Therefore, we can take the emf and flux as our antecedents, and the speed as our
consequent, and design rules for the proportional/inversely proportional constraints.
Implementation:
First, we import the python libraries needed:
Next, we define our antecedents and consequents:
An antecedent is a single variable, with a range, on which we can apply rules via the
'OR' operator(maximum), and consequents take these antecedents and apply the
implication operator(minimum) which can be AND operator, or a product(x) operator.
The antecedents fuzzify the input before applying any operations, i.e. they convert the
given range to a range of numbers between 0 and 1.
Antecedents and consequents, with their membership functions:
Here, our antecedents are emf and flux, with ranges (0, 91) and (0, 10) respectively.
The consequent is naturally speed, as that is the variable we wish to control. We will
now define the membership functions for our antecedents and consequents.
The parameters for the membership function are as follows:
EMF(Antecedent):
Degree Parameter a Parameter b Parameter c Parameter d
lowest 0 6 12 18
lower 12 18 24 30
low 24 30 36 42
medium 36 42 48 54
high 48 54 60 66
higher 60 66 72 78
highest 72 78 84 90
Here, we define the trapezoidal membership function for our antecedent 'emf', and
define seven ranges as well, ranging from 'lowest' to 'highest'. The trapezoidal
membership function is used as 'trapmf' which is the function defined in the python
library.
The trapezoidal membership functions looks like this:
The function y= trapmf(x,params) returns fuzzy membership values
computed using the following trapezoidal membership function:
f(x;a,b,c,d)=max(min(x−ab−a,1,d−xd−c),0)
Membership function parameters, specified as the vector [a,b,c,d]. Parameters b and c
define the shoulders of the membership function, and a and d define its feet.
The shape of the membership function depends on the relative values of b and c.
Therefore, When c is greater than b, the resulting membership function is trapezoidal.
Next, we will see the membership functions implemented for flux, the second
antecedent. We can define it in the range (0, 10), and with three linguistic variables,
namely less, moderate and more.
The membership parameters are as follows:
Flux(Antecedent):
Degree Parameter a Sigma
less 0 5
moderate 5 5
more 10 5
For flux, we are inclined to use the gaussian membership function. The graph of this
membership function looks like this:
The function y = gaussmf(x,params) returns fuzzy membership values
computed using the following Gaussian membership function:
f(x;σ,c)=e^(−(x−c)^2/2σ^2)
To specify the standard deviation, σ, and mean, c, for the Gaussian function, we can
use params. Membership values are computed for each input value in x. Moreover,
a Gaussian membership function always has a maximum value of 1.
We have finished defining the membership functions for the antecedents. Now, we
will define them for the consequent, the speed.
We have defined the consequent, speed, with three linguistic variables, namely low,
medium and high, with a range of (0, 9) with 0 being the least and 9 being the
highest.
The membership parameters are as follows:
Speed(Consequent):
Degree Parameter a Parameter b Parameter c
low 0 1 3
medium 2 4 6
high 5 7 9
This is derived from the fact that we have set 0 as the minimum for both emf and
flux, and 90 as the maximum for emf and 10 as the maximum for flux. Since speed is
proportional to emf/flux, we can take the upper limit as 90/10 = 9 and the lower limit
as 0.
For the consequent we are using the triangular membership function. This is what it
looks like:
The triangular membership function is essentially a modification of the gaussian
membership function, with the following modification:
When b is equal to c, the resulting membership function is equivalent to a triangular
membership function with parameters [a,b,d].
Therefore it has a vector of three elements instead of the four for gaussian.
Now that we have defined the membership functions for the antecedents and
consequent, we need to define rules that the antecedents should follow in order to
obtain a particular state or linguistic variable in the consequent.
Rules:
Typically, in crisp logic, we can have rules with the premise x is A, however it can
only be true or false. With fuzzy logic, we can define a degree of truth for the premise
x is A, thus using linguistic variables to modify the premise. For example, we can say
x is 'mostly' A, in fuzzy logic. So, here, we can define a relationship between the
antecedents and the consequents by using rules.
We will first define the rules for obtaining a 'low' speed of the DC motor. We can see
the obvious combinations such as setting a very small ('lowest') emf, and an increased
('more') flux can result in a very low speed. Some more combinations which give a
slightly lesser speed, such as 'lower' emf and 'moderate' flux can be added as well.
Now that we have set the rule for 'low' speed, we can move to the second linguistic
variable of the consequent, 'moderate' speed. The most obvious combination would
be 'medium' emf and 'moderate' flux, as it clearly results in 'medium' speed. Other
combinations which deal in extremes, such as 'highest' emf and 'more' flux, as well as
'lowest' emf and 'less' flux can be added.
Finally, we can now define the rules for obtaining 'high' speed of the DC motor.
Naturally, the obvious combination would be 'highest' emf and 'less' flux, given the
relationship of the two with speed. Some other combinations such as 'higher' emf and
'less' flux can be added as well.
Now, we will define the variables to initialize the speed control system using the
above rules, and an output variable to see our graphs.
We have defined our variables for the control system and the output. Now, we will
see our output graphs for the antecedents:
EMF: (Trapezoidal Membership)
Flux: (Gaussian Membership)
We will now check the output graphs for the consequent, speed, with different inputs,
in order to get the three degrees of speed, namely, 'high' speed, 'medium' speed, and
'low' speed.
DC Motor Speed: (Triangular Membership)
'Low' Speed:
With inputs of:
emf = 10, flux = 8, we get:
'Medium' Speed:
With inputs of:
emf = 47, flux = 5, we get:
'High' Speed:
With inputs of:
emf = 87, flux = 2, we get:
Thus, we have covered the three cases, namely 'low', 'medium' and 'high' speed for
different values of emf and flux. The above triangular membership functions show
degree of membership of each of the three linguistic states of speed, with different
inputs.
In conclusion, we have successfully implemented a fuzzy logic controller for the
speed of a DC motor, by using emf and flux as inputs, and with the help of fuzzy
logic principles. The use of speed controls in DC motors have been around for quite a
while, being implemented in various use cases such as conveyors and turntables
where adjustable speed and constant or low-speed torque is required.