SlideShare a Scribd company logo
1 of 36
ECE478
FINAL REPORT
Applying Fuzzy Logic
to Control a Submarine
CLASS 12ES
GROUP MEMBERS:
Đinh Tuấn Anh
Nguyễn Thanh Sang
Đoàn Công Danh
Tạ Đình Sang
Table of Contents
I. Fuzzy logic and fuzzy controller.............................................................................................3
1. Fuzzy Logic...........................................................................................................................3
2. Working-Process..................................................................................................................4
3. Fuzzy Logic Algorithm.........................................................................................................5
I. Fuzzy Logic Algorithm ofControlling a Submarine...............................................................6
1. Linguistic Variables .............................................................................................................6
2. Membership functions.........................................................................................................7
a. Popular Membership Functions:.........................................................................................7
b. Membership Functions in Cotrolling a Submarine ..............................................................8
3. Fuzzy Rules.........................................................................................................................10
4. Convert the output data to non-fuzzy values (defuzzification) ......................................13
1. main function........................................................................................................................15
2.double triangular....................................................................................................................16
3.Assigning rules and returns the angles two blades rotate..........................................................18
4. max-min method...................................................................................................................30
5. Result..................................................................................................................................32
6. Conclusion..........................................................................................................................36
Figures
Figure 1: A Fuzzy Logic System (FLS)................................................................................................4
Figure 2:Examples of Popular Membership Functions.......................................................................7
Figure 3: Triangular Membership Function.......................................................................................9
Figure 4: Depth Membership Function..............................................................................................9
Figure 5: Left-Right Obstacle Membership Function..........................................................................9
Figure 6: Velocity Membership Function.........................................................................................10
Figure 7.Blade1-Blade2 Membership Function................................................................................10
Figure 8: Weighted Average Method .....................................................Error! Bookmark not defined.
I. Fuzzy logic and fuzzy controller
1. Fuzzy Logic
Fuzzy logic is an approach to computing based on "degrees of truth" rather than
the usual "true or false" (1 or 0) Boolean logic on which the modern computer is
based.
The idea of fuzzy logic was first advanced by Dr. Lotfi Zadeh of the University of
California at Berkeley in the 1960s. Dr. Zadeh was working on the problem of
computer understanding of natural language. Natural language (like most other
activities in life and indeed the universe) is not easily translated into the absolute
terms of 0 and 1. (Whether everything is ultimately describable in binary terms is a
philosophical question worth pursuing, but in practice much data we might want to
feed a computer is in some state in between and so, frequently, are the results of
computing.) It may help to see fuzzy logic as the way reasoning really works and
binary or Boolean logic is simply a special case of it.
Fuzzy logic includes 0 and 1 as extreme cases of truth (or "the state of matters" or
"fact") but also includes the various states of truth in between so that, for example,
the result of a comparison between two things could be not "tall" or "short" but ".38
of tallness."
Fuzzy logic seems closer to the way our brains work. We aggregate data and form
a number of partial truths which we aggregate further into higher truths which in
turn, when certain thresholds are exceeded, cause certain further results such as
motor reaction. A similar kind of process is used in neural networks, expert
systems and other artificial intelligence applications. Fuzzy logic is essential to the
development of human-like capabilities for AI, sometimes referred to as artificial
general intelligence: the representation of generalized human cognitive abilities in
software so that, faced with an unfamiliar task, the AI system could find a solution.
2. Working-Process
Figure 1: A Fuzzy Logic System (FLS)
Firstly, a crisp set of input data are gathered and converted to a fuzzy set using
fuzzy linguistic variables, fuzzy linguistic terms and membership functions. This
step is known as fuzzification. Afterwards, an inference is made based on a set of
rules. Lastly, the resulting fuzzy output is mapped to a crisp output using the
membership functions, in the defuzzification step.
Fuzzy sets
A fuzzy set is represented by a membership function defined on the universe of
discourse. The universe of discourse is the space where the fuzzy variables are
defined. The membership function gives the grade, or degree, of membership within
the set, of any element of the universe of discourse. The membership function maps
the elements of the universe onto numerical values in the interval [0, 1]. A
membership function value of zero implies that the corresponding element is
definitely not an element of the fuzzy set, while a value of unity means that the
element fully belongs to the set. A grade of membership in between corresponds to
the fuzzy membership to set. In crisp set theory, if someone is taller than 1.8 meters,
we can state that such person belongs to the “set of tall people”. However, such
sharp change from 1.7999 meters of a “short person” to 1.8001 meters of a “tall
person” is against the common sense.
Fuzzifcation
Fuzzification is the process of decomposing a system input and/or output into
one or more fuzzy sets. Many types of curves can be used, but triangular or
trapezoidal shaped membership functions are the most common because they are
easier to represent in embedded controllers. Fig 1 shows a system of fuzzy sets for
an input with trapezoidal and triangular membership functions. Each fuzzy set
spans a region of input (or output) value graphed with the membership. Any
particular input is interpreted from this fuzzy set and a degree of membership is
interpreted. The membership functions should overlap to allow smooth mapping of
the system. The process of fuzzification allows the system inputs and outputs to be
expressed in linguistic terms so that rules can be applied in a simple manner to
express a complex system.
Defuzzification
After fuzzy reasoning we have a linguistic output variable which needs to be
translated into a crisp value. The objective is to derive a single crisp numeric value
that best represents the inferred fuzzy values of the linguistic output variable.
Defuzzification is such inverse transformation which maps the output from the
fuzzy domain back into the crisp domain. Some defuzzification methods tend to
produce an integral output considering all the elements of the resulting fuzzy set
with the corresponding weights. Other methods take into account just the elements
corresponding to the maximum points of the resulting membership functions.
3. Fuzzy Logic Algorithm
1. Define the linguistic variables and terms (initialization)
2. Construct the membership functions (initialization)
3. Construct the rule base (initialization)
4. Convert crisp input data to fuzzy values using the membership functions
(fuzzification)
5. Evaluate the rules in the rule base (inference)
6. Combine the results of each rule (inference)
7. Convert the output data to non-fuzzy values (defuzzification)
I. Fuzzy Logic Algorithm of Controlling a Submarine
1. Linguistic Variables
Linguistic variables are the input or output variables of the system whose values
are words or sentences from a natural language, instead of numerical values. A
linguistic variable is generally decomposed into a set of linguistic terms.
 Fuzzy sets for depth:
Depth = {Low, Medium, High}
 Fuzzy sets for left obstacles:
Left_Obstacles = {Close, Near, Far}
 Fuzzy sets for right obstacles:
Right_Obstacles = {Close, Near, Far}
 Fuzzy sets for velocity:
Velocity = {Slow, Medium, Fast}
 Fuzzy sets for blade 1:
Blade1 = {Lowlow, Low, Zero, High, Highhigh};
 Fuzzy sets for blade 2:
Blade2 = {Lowlow, Low, Zero, High, Highhigh};
2. Membershipfunctions
Membership functions are used in the fuzzification and defuzzification steps of a
FLS, to map the non-fuzzy input values to fuzzy linguistic terms and vice versa. A
membership function is used to quantify a linguistic term.
a. Popular Membership Functions:
Figure 2:Examples of Popular Membership Functions
The simplest membership functions are formed using straight lines. Of these, the
simplest is the triangular membership function, and it has the function name trimf.
This function is nothing more than a collection of three points forming a triangle.
The trapezoidal membership function, trapmf, has a flat top and really is just a
truncated triangle curve. These straight line membership functions have the
advantage of simplicity.
Two membership functions are built on the Gaussian distribution curve: a simple
Gaussian curve and a two-sided composite of two different Gaussian curves. The
two functions aregaussmf and gauss2mf.
The generalized bell membership function is specified by three parameters and
has the function name gbellmf. The bell membership function has one more
parameter than the Gaussian membership function, so it can approach a non-fuzzy
set if the free parameter is tuned. Because of their smoothness and concise notation,
Gaussian and bell membership functions are popular methods for specifying fuzzy
sets. Both of these curves have the advantage of being smooth and nonzero at all
points.
Although the Gaussian membership functions and bell membership functions
achieve smoothness, they are unable to specify asymmetric membership functions,
which are important in certain applications. Next, you define
the sigmoidal membership function, which is either open left or right. Asymmetric
and closed (i.e. not open to the left or right) membership functions can be
synthesized using two sigmoidal functions, so in addition to the basic sigmf, you also
have the difference between two sigmoidal functions, dsigmf, and the product of two
sigmoidal functions psigmf.
Polynomial based curves account for several of the membership functions in the
toolbox. Three related membership functions are the Z, S, and Pi curves, all named
because of their shape. The function zmf is the asymmetrical polynomial curve open
to the left, smf is the mirror-image function that opens to the right, and pimf is zero
on both extremes with a rise in the middle.
There is a very wide selection to choose from when you're selecting a
membership function. You can also create your own membership functions with the
toolbox. However, if a list based on expanded membership functions seems too
complicated, just remember that you could probably get along very well with just
one or two types of membership functions, for example the triangle and trapezoid
functions. The selection is wide for those who want to explore the possibilities, but
expansive membership functions are not necessary for good fuzzy inference
systems. Finally, remember that more details are available on all these functions in
the reference section.
b. Membership Functionsin Cotrollinga Submarine
𝜇 𝐴
( 𝑥) =
{
0 𝑖𝑓 𝑥 ≤ 𝑎
𝑥−𝑎
𝑏−𝑎
𝑖𝑓 𝑎 < 𝑥 ≤ 𝑏
𝑐−𝑥
𝑐−𝑏
𝑖𝑓 𝑏 < 𝑥 < 𝑐
0 𝑖𝑓 𝑥 ≥ 𝑐
Figure 4: Depth Membership Function
Figure 5: Left-Right Obstacle Membership Function
Figure 3: Triangular Membership Function
Figure 6: Velocity Membership Function
Figure 7.Blade1-Blade2 Membership Function
3. Fuzzy Rules
In a FLS, a rule base is constructed to control the output variable. A fuzzy rule is a
simple IF-THEN rule with a condition and a conclusion.
Let:
 L1: depth is low
 L2: left obstacle is close
 L3: right obstacle is close
 L4: velocity is slow
 M1: depth is medium
 M2: left obstacle is near
 M3: right obstacle is near
 M4: velocity is medium
 H1: depth is high
 H2: left obstacle is far
 H3: right obstacle is far
 H4: velocity is fast
 Z/Z or Z/L … stands for blade1/blade2.
Then, we have the rule table below.
Table 1. Rule Table of Fuzzy Logic
L1 L2 L1 M2 L1 H2 M1 L2 M1 M2 M1 H2 H1 L2 H1 M2 H1 H2
L3 L4 Z/Z L/H L/H Z/Z L/H L/H Z/Z L/L L/L
L3 M4 Z/Z L/H LL/H Z/Z L/H LL/H Z/Z L/L LL/L
L3 H4 Z/Z LL/H LL/H Z/Z LL/H LL/H Z/Z LL/L LL/L
M3 L4 H/H Z/H L/HH H/H Z/H L/H H/L Z/L L/LL
M3 M4 H/H Z/H L/HH H/H Z/H L/HH H/L Z/L L/LL
M3 H4 HH/H Z/HH L/HH HH/H Z/H L/HH HH/L H/LL L/LL
H3 L4 HH/H Z/HH Z/HH HH/H H/HH Z/HH HH/L HH/LL Z/LL
H3 M4 HH/H Z/HH Z/HH HH/H HH/H Z/HH HH/L H/L Z/LL
H3 H4 HH/H Z/HH Z/HH HH/H H/H Z/HH HH/L H/L Z/LL
According to table 1, we have 81 rules for two output blade1 and blade2
(1) if (Depth(Low) and Left_Obstacle(Far) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Zero and Blade2 is Zero
(2) if (Depth(Low) and Left_Obstacle(Near) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Low and Blade2 is High
(3) if (Depth(Low) and Left_Obstacle(Close) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Low and Blade2 is High
(4) if (Depth(Medium) and Left_Obstacle(Far) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Zero and Blade2 is Zero
(5) if (Depth(Medium) and Left_Obstacle(Near) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Low and Blade2 is High
(6) if (Depth(Medium) and Left_Obstacle(Close) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Low and Blade2 is High
(7) if (Depth(High) and Left_Obstacle(Far) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Zero and Blade2 is Zero
(8) if (Depth(High) and Left_Obstacle(Near) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Low and Blade2 is Low
(9) if (Depth(High) and Left_Obstacle(Close) and Right_Obstacle(Far) and
Velocity(Slow)) then Blade1 is Low and Blade2 is Low
…
In the C codes we discuss in next section, we will have full of Rules.
4. Convert the output data to non-fuzzy values (defuzzification)
After the inference step, the overall result is a fuzzy value. This result should be
defuzzified to obtain a final crisp output. This is the purpose of the defuzzifier
component of a FLS. Defuzzification is performed according to the membership
function of the output variable.
In this project, we choose Weighted Average Method because this method is valid
for symmetrical output membership functions.
The follwing codes based on C programming language run on CodeBlocks
platform.
#include <stdio.h>
#include <stdlib.h>
void assignRule_Blade (double L1, double L2, double L3, double L4,
double M1, double M2, double M3, double M4, double H1, double H2,
double H3, double H4, double blade1, double blade2);
double triangular (double low, double mid, double high, double x);
void Depth (double x, double a[]);
void Left_Obstacles (double x, double a[]);
void Right_Obstacles (double x, double a[]);
void Velocity (double x, double a[]);
double min4 (double x, double y, double m, double n);
/* The C sub-functions:
 void assignRule_Blade returns values of two blades (1 and 2)
 double triangular returns the probability of number x in the triangle.
 void Depth builds Depth membership function based on triangular function.
 void Left_Obstacles builds Left_Obstacles membership function based on
triangular function.
 void Right_Obstacles builds Right_Obstacles membership function based on
triangular function.
 void Velocity builds Velocity membership function based on triangular
function.
 double min4 returns the minimum value of four given numbers.
*/
1. main function
int main()
{
double D[3], Le[3], Ri[3], V[3];
double L1, L2, L3, L4, M1, M2, M3, M4, H1, H2, H3, H4;
Depth(52.4,D);
Left_Obstacles (3.91,Le);
Right_Obstacles(3.91,Ri);
Velocity(10.2,V);
L1 = D[0];
M1 = D[1];
H1 = D[2];
L2 = Le[2];
M2 = Le[1];
H2 = Le[0];
L3 = Ri[2];
M3 = Ri[1];
H3 = Ri[0];
L4 = V[0];
M4 = V[1];
H4 = V[2];
double out_blade1, out_blade2;
assignRule_Blade(L1, L2, L3, L4, M1, M2, M3, M4, H1, H2, H3, H4,
out_blade1, out_blade2);
return 0;
}
The way sub-functions implement
2.double triangular
double triangular (double low, double mid, double high, double x)
{
double u;
if (x<= low) u = 0;
else if (x > low && x <= mid ) u = (x-low)/(mid-low);
else if (x > mid && x <high) u = (high-x)/(high-mid);
else if (x >= high) u = 0;
return u;
}
void Depth (double x, double a[])
{
a[0] = triangular (0, 20, 40, x);
a[1] = triangular (20, 50, 80, x);
a[2] = triangular (60, 80, 100, x);
}
void Left_Obstacles (double x, double a[])
{
a[0] = triangular (0, 2, 4, x);
a[1] = triangular (3, 5, 7, x);
a[2] = triangular (6, 8, 10, x);
}
void Right_Obstacles (double x, double a[])
{
a[0] = triangular (0, 2, 4, x);
a[1] = triangular (3, 5, 7, x);
a[2] = triangular (6, 8, 10, x);
}
void Velocity (double x, double a[])
{
a[0] = triangular (0, 4, 8, x);
a[1] = triangular (5, 10, 15, x);
a[2] = triangular (12, 16, 20, x);
}
double min4 (double x, double y, double m, double n)
{
return (((x<y)? x:y) < ((m<n)? m:n)) ? ((x<y)? x:y) : ((m<n)? m:n)
;
}
3.Assigning rules and returns the angles two blades rotate
void assignRule_Blade(double L1, double L2, double L3, double L4,
double M1, double M2, double M3, double M4, double H1, double H2,
double H3, double H4, double blade1, double blade2)
{
Double
ll1[25],ll2[25],l1[25],l2[25],z1[25],z2[25],h1[25],h2[25],hh1[25],hh2[
25];
int idx;
for(idx=0;idx<25;idx++)
{
ll1[idx]=0;
ll2[idx]=0;
l1[idx]=0;
l2[idx]=0;
z1[idx]=0;
z2[idx]=0;
h1[idx]=0;
h2[idx]=0;
hh1[idx]=0;
hh2[idx]=0;
}
if (L1 && L2 && L3)
{
z1[0] = min4(L1, L2, L3, 1);
z2[0] = min4(L1, L2, L3, 1);
}
if (L1 && L2 && M3 && L4)
{
h1[0] = min4(L1,L2, M3, L4);
h2[0] = min4(L1,L2, M3, L4);
}
if (L1 && L2 && M3 && M4)
{
h1[1] = min4(L1,L2, M3, M4);
h2[1] = min4(L1,L2, M3, M4);
}
if (L1 && L2 && M3 && H4)
{
hh1[0] = min4(L1,L2,M3,H4);
h2[2] = min4(L1,L2,M3,H4);
}
if (L1 && L2 && H3 && L4)
{
hh1[1] = min4(L1,L2,H3,L4);
h2[3] = min4(L1,L2,H3,L4);
}
if (L1 && L2 && H3 && M4)
{
hh1[2] = min4(L1,L2,H3,M4);
h2[4] = min4(L1,L2,H3,M4);
}
if (L1 && L2 && H3 && H4)
{
hh1[3] = min4(L1,L2,H3,H4);
h2[5] = min4(L1,L2,H3,H4);
}
if (L1 && M2 && L3 && L4)
{
l1[0] = min4(L1,M2,L3,L4);
h2[6] = min4(L1,M2,L3,L4);
}
if (L1 && M2 && L3 && M4)
{
l1[1] = min4(L1,M2,L3,M4);
h2[7] = min4(L1,M2,L3,L4);
}
if (L1 && M2 && L3 && H4)
{
ll1[0] = min4(L1,M2,L3,H4);
h2[8] = min4(L1,M2,L3,H4);
}
if (L1 && M2 && M3 && L4)
{
z1[1] = min4(L1,M2,M3,L4);
h2[9] = min4(L1,M2,M3,L4);
}
if (L1 && M2 && M3 && M4)
{
z1[2] = min4(L1,M2,M3,M4);
h2[10] = min4(L1,M2,M3,M4);
}
if (L1 && M2 && M3 && H4)
{
z1[3] = min4(L1,M2,M3,H4);
hh2[0] = min4(L1,M2,M3,M4);
}
if (L1 && M2 && H3 && L4)
{
h1[2] = min4(L1,M2,H3,L4);
hh2[1] = min4(L1,M2,H3,L4);
}
if (L1 && M2 && H3 && M4)
{
hh1[3] = min4(L1,M2,H3,M4);
hh2[2] = min4(L1,M2,H3,L4);
}
if (L1 && M2 && H3 && H4)
{
h1[3] = min4(L1,M2,H3,H4);
h2[11] = min4(L1,M2,H3,H4);
}
if (L1 && H2 && L3 && L4)
{
l1[2] = min4(L1,H2,L3,L4);
h2[12] = min4(L1,H2,L3,L4);
}
if (L1 && H2 && L3 && M4)
{
ll1[1] = min4(L1,H2,L3,M4);
h2[13] = min4(L1,H2,L3,M4);
}
if (L1 && H2 && L3 && H4)
{
l1[3] = min4(L1,H2,L3,H4);
h2[14] = min4(L1,H2,L3,L4);
}
if (L1 && H2 && M3 && L4)
{
l1[4] = min4(L1,H2,M3,L4);
hh2[3] = min4(L1,H2,M3,L4);
}
if (L1 && H2 && M3 && M4)
{
l1[5] = min4(L1,H2,M3,M4);
hh2[4] = min4(L1,H2,M3,M4);
}
if (L1 && H2 && M3 && H4)
{
l1[6] = min4(L1,H2,M3,H4);
hh2[5] = min4(L1,H2,M3,H4);
}
if (L1 && H2 && H3 && L4)
{
z1[4] = min4(L1,H2,H3,L4);
hh2[6] = min4(L1,H2,H3,L4);
}
if (L1 && H2 && H3 && M4)
{
z1[5] = min4(L1,H2,H3,M4);
hh2[7] = min4(L1,H2,H3,M4);
}
if (L1 && H2 && H3 && H4)
{
z1[6] = min4(L1,H2,H3,H4);
hh2[8] = min4(L1,H2,H3,H4);
}
if (M1 && L2 && L3)
{
z1[7] = min4(M1, L2, L3, 1);
z2[1] = min4(M1, L2, L3, 1);
}
if (M1 && L2 && M3 && L4)
{
h1[4] = min4(M1, L2, L3, L4);
h2[15] = min4(M1, L2, L3, L4);
}
if (M1 && L2 && M3 && M4)
{
h1[5] = min4(M1, L2, L3, M4);
h2[16] = min4(M1, L2, L3, M4);
}
if (M1 && L2 && M3 && H4)
{
hh1[4] = min4(M1,L2,M3,H4);
hh2[9] = min4(M1,L2,M3,H4);
}
if (M1 && L2 && H3 )
{
hh1[5] = min4(M1,L2,H3,1);
hh2[10] = min4(M1,L2,H3,1);
}
if (M1 && M2 && L3 && L4)
{
l1[7] = min4(M1,M2,L3,L4);
h2[17] = min4(M1,M2,L3,L4);
}
if (M1 && M2 && L3 && M4)
{
l1[8] = min4(M1,M2,L3,M4);
h2[18] = min4(M1,M2,L3,M4);
}
if (M1 && M2 && L3 && H4)
{
ll1[2] = min4(M1,M2,L3,H4);
h2[19] = min4(M1,M2,L3,H4);
}
if (M1 && M2 && M3 )
{
z1[8] = min4(M1,M2,M3,1);
h2[20] = min4(M1,M2,M3,1);
}
if (M1 && M2 && H3 && L4)
{
h1[6] = min4(M1,M2,H3,L4);
hh2[11] = min4(M1,M2,H3,L4);
}
if (M1 && M2 && H3 && M4)
{
hh1[6] = min4(M1,M2,H3,M4);
hh2[12] = min4(M1,M2,H3,M4);
}
if (M1 && M2 && H3 && H4)
{
h1[7] = min4(M1,M2,H3,H4);
h2[21] = min4(M1,M2,H3,H4);
}
if (M1 && H2 && L3 && L4)
{
l1[9] = min4(M1,H2,L3,L4);
h2[22] = min4(M1,H2,L3,L4);
}
if (M1 && H2 && L3 && M4)
{
ll1[3] = min4(M1,H2,L3,M4);
h2[23] = min4(M1,H2,L3,M4);
}
if (M1 && H2 && L3 && H4)
{
ll1[4] = min4(M1,H2,L3,H4);
h2[24] = min4(M1,H2,L3,H4);
}
if (M1 && H2 && M3)
{
l1[10] = min4(M1,H2,M3,1);
hh2[13] = min4(M1,H2,M3,1);
}
if (M1 && H2 && H3)
{
z1[9] = min4(M1,H2,H3,1);
hh2[14] = min4(M1,H2,H3,1);
}
if (H1 && L2 && L3)
{
z1[10] = min4(H1,L2,L3,1);
z2[2] = min4(H1,L2,L3,1);
}
if (H1 && L2 && M3 && L4)
{
h1[8] = min4(H1,L2,M3,L4);
l2[0] = min4(H1,L2,M3,L4);
}
if (H1 && L2 && M3 && M4)
{
h1[9] = min4(H1,L2,M3,M4);
l2[1] = min4(H1,L2,M3,M4);
}
if (H1 && L2 && M3 && H4)
{
hh1[7] = min4(H1,L2,M3,H4);
l2[2] = min4(H1,L2,M3,H4);
}
if (H1 && L2 && H3 )
{
hh1[8] = min4(H1,L2,H3,1);
l2[3] = min4(H1,L2,H3,1);
}
if (H1 && M2 && L3 && L4)
{
l1[11] = min4(H1,M2,L3,L4);
l2[4] = min4(H1,M2,L3,L4);
}
if (H1 && M2 && L3 && M4)
{
l1[12] = min4(H1,M2,L3,M4);
l2[5] = min4(H1,M2,L3,M4);
}
if (H1 && M2 && L3 && H4)
{
ll1[5] = min4(H1,M2,L3,H4);
l2[6] = min4(H1,M2,L3,H4);
}
if (H1 && M2 && M3)
{
z1[11] = min4(H1,M2,M3,1);
l2[7] = min4(H1,M2,M3,1);
}
if (H1 && M2 && H3 && L4)
{
h1[10] = min4(H1,M2,H3,L4);
ll2[3] = min4(H1,M2,H3,L4);
}
if (H1 && M2 && H3 && M4)
{
hh1[9] = min4(H1,M2,H3,M4);
ll2[2] = min4(H1,M2,H3,M4);
}
if (H1 && M2 && H3 && H4)
{
h1[11] = min4(H1,M2,H3,H4);
l2[8] = min4(H1,M2,H3,H4);
}
if (H1 && H2 && L3 && L4)
{
l1[13] = min4(H1,H2,L3,L4);
l2[9] = min4(H1,H2,L3,L4);
}
if (H1 && H2 && L3 && M4)
{
ll1[6] = min4(H1,H2,L3,M4);
l2[10] = min4(H1,H2,L3,M4);
}
if (H1 && H2 && L3 && H4)
{
ll1[7] = min4(H1,H2,L3,H4);
l2[11] = min4(H1,H2,L3,H4);
}
if (H1 && H2 && M3)
{
l1[14] = min4(H1,H2,M3,1);
ll2[1] = min4(H1,H2,M3,1);
}
if (H1 && H2 && H3)
{
z1[12] = min4(H1,H2,H3,1);
ll2[0] = min4(H1,H2,H3,1);
}
4. max-min method
double ll1max =
ll1[0],ll2max=ll2[0],l1max=l1[0],l2max=l2[0],z1max=z1[0],z2max=z2[0],h
1max=h1[0],h2max=h2[0],hh1max=hh1[0],hh2max=hh2[0];
for(idx=1;idx<25;idx++)
{
if(ll1max<ll1[idx]) ll1max=ll1[idx];
if(ll2max<ll2[idx]) ll2max=ll2[idx];
if(l1max<l1[idx]) l1max=l1[idx];
if(l2max<l2[idx]) l2max=l2[idx];
if(z1max<z1[idx]) z1max=z1[idx];
if(z2max<z2[idx]) z2max=z2[idx];
if(h1max<h1[idx]) h1max=h1[idx];
if(h2max<h2[idx]) h2max=h2[idx];
if(hh1max<hh1[idx]) hh1max=hh1[idx];
if(hh2max<hh2[idx]) hh2max=hh2[idx];
}
printf("ll1 = %f l1 = %f z1=%f h1 = %f hh1 = %fn",
ll1max,l1max,z1max,h1max,hh1max);
printf("ll2 = %f l2 = %f z2=%f h2 = %f hh2 = %fn",
ll2max,l2max,z2max,h2max,hh2max);
// weighted average equation to find out the angles two blades rotate.
blade1 = (ll1max*15 + l1max*52 + z1max*92 + h1max*130 + hh1max*165
)/(ll1max+l1max+z1max+h1max+hh1max);
blade2 = (ll2max*15 + l2max*50 + z2max*90 + h2max*130 + hh2max*165
)/(ll2max+l2max+z2max+h2max+hh2max);
printf("blade1 = %f nblade2 = %f ", blade1,blade2);
}
5. Result
The following figures show the results of simulating fuzzy logic on Matlab (above)
and implementing C programming on CodeBlocks (below).
After testing many times, we get other results recorded in table 2
Table2. Theinputparametersandresults comparison
Depth
Left
Obstacle
Right
Obstacle
Velocity
Matlab’s
results
Blade1/Blade2
CodeBlock’s
results
Blade1/Blade2
75 5 5 75 90/62 92/64.55
80 6 9 18 13/53 15/50
10 6 9 18 17/129 15/130
29.89 8.97 5.3 6.17 129/133 130/130
25.62 3.42 5.32 17.17 68/150 68.8/151.264
15.8452 8.472 2.32 7.127 159/135 162/130
90 9.472 9.32 9.127 90/90 92/90
7 9 9.32 9.13 90/90 92/90
35 4.6 9.5 9.7 53/127 52/130
6. Conclusion
There are some little differences between Matlab and CodeBlocks. This comes
from the difference of processing input and defuzzification method.
If time permits, we think we can improve the C codes to enhance the quality of
results efficiently.

More Related Content

What's hot

Optimization using soft computing
Optimization using soft computingOptimization using soft computing
Optimization using soft computingPurnima Pandit
 
Fuzzy Logic ppt
Fuzzy Logic pptFuzzy Logic ppt
Fuzzy Logic pptRitu Bafna
 
Fuzzy Logic Ppt
Fuzzy Logic PptFuzzy Logic Ppt
Fuzzy Logic Pptrafi
 
On fuzzy concepts in engineering ppt. ncce
On fuzzy concepts in engineering ppt. ncceOn fuzzy concepts in engineering ppt. ncce
On fuzzy concepts in engineering ppt. ncceSurender Singh
 
Fuzzy Sets Introduction With Example
Fuzzy Sets Introduction With ExampleFuzzy Sets Introduction With Example
Fuzzy Sets Introduction With Exampleraisnasir
 
Fuzzy Logic in the Real World
Fuzzy Logic in the Real WorldFuzzy Logic in the Real World
Fuzzy Logic in the Real WorldBCSLeicester
 
Fuzzy logic and its applications
Fuzzy logic and its applicationsFuzzy logic and its applications
Fuzzy logic and its applicationsTarek Kalaji
 
Fuzzy Logic Seminar with Implementation
Fuzzy Logic Seminar with ImplementationFuzzy Logic Seminar with Implementation
Fuzzy Logic Seminar with ImplementationBhaumik Parmar
 
Fuzzy modelling using sciFLT
Fuzzy modelling using sciFLTFuzzy modelling using sciFLT
Fuzzy modelling using sciFLTUmang Shukla
 
33412283 solving-fuzzy-logic-problems-with-matlab
33412283 solving-fuzzy-logic-problems-with-matlab33412283 solving-fuzzy-logic-problems-with-matlab
33412283 solving-fuzzy-logic-problems-with-matlabsai kumar
 
Fuzzy logic Notes AI CSE 8th Sem
Fuzzy logic Notes AI CSE 8th SemFuzzy logic Notes AI CSE 8th Sem
Fuzzy logic Notes AI CSE 8th SemDigiGurukul
 
Report on robotic control
Report on robotic controlReport on robotic control
Report on robotic controlAnil Maurya
 
Linguistic variable
Linguistic variable Linguistic variable
Linguistic variable Math-Circle
 

What's hot (20)

Optimization using soft computing
Optimization using soft computingOptimization using soft computing
Optimization using soft computing
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
Fuzzy logic ppt
Fuzzy logic pptFuzzy logic ppt
Fuzzy logic ppt
 
Fuzzy Logic ppt
Fuzzy Logic pptFuzzy Logic ppt
Fuzzy Logic ppt
 
Fuzzy Logic
Fuzzy LogicFuzzy Logic
Fuzzy Logic
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
Fuzzy Logic Ppt
Fuzzy Logic PptFuzzy Logic Ppt
Fuzzy Logic Ppt
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
On fuzzy concepts in engineering ppt. ncce
On fuzzy concepts in engineering ppt. ncceOn fuzzy concepts in engineering ppt. ncce
On fuzzy concepts in engineering ppt. ncce
 
Fuzzy Sets Introduction With Example
Fuzzy Sets Introduction With ExampleFuzzy Sets Introduction With Example
Fuzzy Sets Introduction With Example
 
Fuzzy Logic in the Real World
Fuzzy Logic in the Real WorldFuzzy Logic in the Real World
Fuzzy Logic in the Real World
 
Fuzzy logic and its applications
Fuzzy logic and its applicationsFuzzy logic and its applications
Fuzzy logic and its applications
 
Fuzzy Logic Seminar with Implementation
Fuzzy Logic Seminar with ImplementationFuzzy Logic Seminar with Implementation
Fuzzy Logic Seminar with Implementation
 
Fuzzy modelling using sciFLT
Fuzzy modelling using sciFLTFuzzy modelling using sciFLT
Fuzzy modelling using sciFLT
 
33412283 solving-fuzzy-logic-problems-with-matlab
33412283 solving-fuzzy-logic-problems-with-matlab33412283 solving-fuzzy-logic-problems-with-matlab
33412283 solving-fuzzy-logic-problems-with-matlab
 
Fuzzy logic Notes AI CSE 8th Sem
Fuzzy logic Notes AI CSE 8th SemFuzzy logic Notes AI CSE 8th Sem
Fuzzy logic Notes AI CSE 8th Sem
 
Fuzzy logic mis
Fuzzy logic misFuzzy logic mis
Fuzzy logic mis
 
Report on robotic control
Report on robotic controlReport on robotic control
Report on robotic control
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
Linguistic variable
Linguistic variable Linguistic variable
Linguistic variable
 

Similar to Ece478 12es_final_report

An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...
An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...
An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...ijsc
 
IRJET - Application of Fuzzy Logic: A Review
IRJET - Application of Fuzzy Logic: A ReviewIRJET - Application of Fuzzy Logic: A Review
IRJET - Application of Fuzzy Logic: A ReviewIRJET Journal
 
Fuzzy Logic Controller.pptx
Fuzzy Logic Controller.pptxFuzzy Logic Controller.pptx
Fuzzy Logic Controller.pptxMahuaPal6
 
Presentation on fuzzy logic and fuzzy systems
Presentation on fuzzy logic and fuzzy systemsPresentation on fuzzy logic and fuzzy systems
Presentation on fuzzy logic and fuzzy systemsShreyaSahu20
 
FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...
FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...
FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...ijfls
 
Fuzzy logic systems
Fuzzy logic systemsFuzzy logic systems
Fuzzy logic systemsPham Tung
 
Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...
Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...
Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...ijfls
 

Similar to Ece478 12es_final_report (20)

An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...
An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...
An Optimum Time Quantum Using Linguistic Synthesis for Round Robin Cpu Schedu...
 
IRJET - Application of Fuzzy Logic: A Review
IRJET - Application of Fuzzy Logic: A ReviewIRJET - Application of Fuzzy Logic: A Review
IRJET - Application of Fuzzy Logic: A Review
 
Fuzzy expert system
Fuzzy expert systemFuzzy expert system
Fuzzy expert system
 
109 me0422
109 me0422109 me0422
109 me0422
 
Swaroop.m.r
Swaroop.m.rSwaroop.m.r
Swaroop.m.r
 
Swaroop.m.r
Swaroop.m.rSwaroop.m.r
Swaroop.m.r
 
Fuzzy Logic Controller.pptx
Fuzzy Logic Controller.pptxFuzzy Logic Controller.pptx
Fuzzy Logic Controller.pptx
 
Fuzzy Logic.pptx
Fuzzy Logic.pptxFuzzy Logic.pptx
Fuzzy Logic.pptx
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
Fuzzy logic1
Fuzzy logic1Fuzzy logic1
Fuzzy logic1
 
Fuzzy inference systems
Fuzzy inference systemsFuzzy inference systems
Fuzzy inference systems
 
Presentation on fuzzy logic and fuzzy systems
Presentation on fuzzy logic and fuzzy systemsPresentation on fuzzy logic and fuzzy systems
Presentation on fuzzy logic and fuzzy systems
 
Fb35884889
Fb35884889Fb35884889
Fb35884889
 
Nueral fuzzy system.pptx
Nueral fuzzy system.pptxNueral fuzzy system.pptx
Nueral fuzzy system.pptx
 
FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...
FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...
FUZZY CONTROL OF A SERVOMECHANISM: PRACTICAL APPROACH USING MAMDANI AND TAKAG...
 
Fuzzy logic systems
Fuzzy logic systemsFuzzy logic systems
Fuzzy logic systems
 
Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...
Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...
Fuzzy Control of a Servomechanism: Practical Approach using Mamdani and Takag...
 
Ejsr 86 3
Ejsr 86 3Ejsr 86 3
Ejsr 86 3
 
International Journal of Engineering Inventions (IJEI)
International Journal of Engineering Inventions (IJEI)International Journal of Engineering Inventions (IJEI)
International Journal of Engineering Inventions (IJEI)
 
Fuzzy logic member functions
Fuzzy logic member functionsFuzzy logic member functions
Fuzzy logic member functions
 

Recently uploaded

Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Servicejennyeacort
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back17lcow074
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一F La
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Architecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfArchitecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfSumit Lathwal
 
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130Suhani Kapoor
 
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdfvaibhavkanaujia
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024CristobalHeraud
 
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一Fi sss
 
Call Girls Meghani Nagar 7397865700 Independent Call Girls
Call Girls Meghani Nagar 7397865700  Independent Call GirlsCall Girls Meghani Nagar 7397865700  Independent Call Girls
Call Girls Meghani Nagar 7397865700 Independent Call Girlsssuser7cb4ff
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Rndexperts
 
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证nhjeo1gg
 
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一lvtagr7
 
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCRCall In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCRdollysharma2066
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Narsimha murthy
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Nightssuser7cb4ff
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpmainac1
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts ServiceCall Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
Call Girls In Safdarjung Enclave 24/7✡️9711147426✡️ Escorts Service
 
shot list for my tv series two steps back
shot list for my tv series two steps backshot list for my tv series two steps back
shot list for my tv series two steps back
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
 
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Okhla Delhi 💯Call Us 🔝8264348440🔝
 
Architecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfArchitecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdf
 
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
VIP Call Girls Service Bhagyanagar Hyderabad Call +91-8250192130
 
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Harsh Vihar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdf
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
 
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
(办理学位证)埃迪斯科文大学毕业证成绩单原版一比一
 
Call Girls Meghani Nagar 7397865700 Independent Call Girls
Call Girls Meghani Nagar 7397865700  Independent Call GirlsCall Girls Meghani Nagar 7397865700  Independent Call Girls
Call Girls Meghani Nagar 7397865700 Independent Call Girls
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025
 
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
 
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
 
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCRCall In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
Call In girls Bhikaji Cama Place 🔝 ⇛8377877756 FULL Enjoy Delhi NCR
 
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...Revit Understanding Reference Planes and Reference lines in Revit for Family ...
Revit Understanding Reference Planes and Reference lines in Revit for Family ...
 
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full NightCall Girls Aslali 7397865700 Ridhima Hire Me Full Night
Call Girls Aslali 7397865700 Ridhima Hire Me Full Night
 
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk GurgaonCheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Iffco Chowk Gurgaon
 
Kindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUpKindergarten Assessment Questions Via LessonUp
Kindergarten Assessment Questions Via LessonUp
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
 

Ece478 12es_final_report

  • 1. ECE478 FINAL REPORT Applying Fuzzy Logic to Control a Submarine CLASS 12ES GROUP MEMBERS: Đinh Tuấn Anh Nguyễn Thanh Sang Đoàn Công Danh Tạ Đình Sang
  • 2. Table of Contents I. Fuzzy logic and fuzzy controller.............................................................................................3 1. Fuzzy Logic...........................................................................................................................3 2. Working-Process..................................................................................................................4 3. Fuzzy Logic Algorithm.........................................................................................................5 I. Fuzzy Logic Algorithm ofControlling a Submarine...............................................................6 1. Linguistic Variables .............................................................................................................6 2. Membership functions.........................................................................................................7 a. Popular Membership Functions:.........................................................................................7 b. Membership Functions in Cotrolling a Submarine ..............................................................8 3. Fuzzy Rules.........................................................................................................................10 4. Convert the output data to non-fuzzy values (defuzzification) ......................................13 1. main function........................................................................................................................15 2.double triangular....................................................................................................................16 3.Assigning rules and returns the angles two blades rotate..........................................................18 4. max-min method...................................................................................................................30 5. Result..................................................................................................................................32 6. Conclusion..........................................................................................................................36 Figures Figure 1: A Fuzzy Logic System (FLS)................................................................................................4 Figure 2:Examples of Popular Membership Functions.......................................................................7 Figure 3: Triangular Membership Function.......................................................................................9 Figure 4: Depth Membership Function..............................................................................................9 Figure 5: Left-Right Obstacle Membership Function..........................................................................9 Figure 6: Velocity Membership Function.........................................................................................10 Figure 7.Blade1-Blade2 Membership Function................................................................................10 Figure 8: Weighted Average Method .....................................................Error! Bookmark not defined.
  • 3. I. Fuzzy logic and fuzzy controller 1. Fuzzy Logic Fuzzy logic is an approach to computing based on "degrees of truth" rather than the usual "true or false" (1 or 0) Boolean logic on which the modern computer is based. The idea of fuzzy logic was first advanced by Dr. Lotfi Zadeh of the University of California at Berkeley in the 1960s. Dr. Zadeh was working on the problem of computer understanding of natural language. Natural language (like most other activities in life and indeed the universe) is not easily translated into the absolute terms of 0 and 1. (Whether everything is ultimately describable in binary terms is a philosophical question worth pursuing, but in practice much data we might want to feed a computer is in some state in between and so, frequently, are the results of computing.) It may help to see fuzzy logic as the way reasoning really works and binary or Boolean logic is simply a special case of it. Fuzzy logic includes 0 and 1 as extreme cases of truth (or "the state of matters" or "fact") but also includes the various states of truth in between so that, for example, the result of a comparison between two things could be not "tall" or "short" but ".38 of tallness." Fuzzy logic seems closer to the way our brains work. We aggregate data and form a number of partial truths which we aggregate further into higher truths which in turn, when certain thresholds are exceeded, cause certain further results such as motor reaction. A similar kind of process is used in neural networks, expert systems and other artificial intelligence applications. Fuzzy logic is essential to the development of human-like capabilities for AI, sometimes referred to as artificial general intelligence: the representation of generalized human cognitive abilities in software so that, faced with an unfamiliar task, the AI system could find a solution.
  • 4. 2. Working-Process Figure 1: A Fuzzy Logic System (FLS) Firstly, a crisp set of input data are gathered and converted to a fuzzy set using fuzzy linguistic variables, fuzzy linguistic terms and membership functions. This step is known as fuzzification. Afterwards, an inference is made based on a set of rules. Lastly, the resulting fuzzy output is mapped to a crisp output using the membership functions, in the defuzzification step. Fuzzy sets A fuzzy set is represented by a membership function defined on the universe of discourse. The universe of discourse is the space where the fuzzy variables are defined. The membership function gives the grade, or degree, of membership within the set, of any element of the universe of discourse. The membership function maps the elements of the universe onto numerical values in the interval [0, 1]. A membership function value of zero implies that the corresponding element is definitely not an element of the fuzzy set, while a value of unity means that the element fully belongs to the set. A grade of membership in between corresponds to the fuzzy membership to set. In crisp set theory, if someone is taller than 1.8 meters, we can state that such person belongs to the “set of tall people”. However, such
  • 5. sharp change from 1.7999 meters of a “short person” to 1.8001 meters of a “tall person” is against the common sense. Fuzzifcation Fuzzification is the process of decomposing a system input and/or output into one or more fuzzy sets. Many types of curves can be used, but triangular or trapezoidal shaped membership functions are the most common because they are easier to represent in embedded controllers. Fig 1 shows a system of fuzzy sets for an input with trapezoidal and triangular membership functions. Each fuzzy set spans a region of input (or output) value graphed with the membership. Any particular input is interpreted from this fuzzy set and a degree of membership is interpreted. The membership functions should overlap to allow smooth mapping of the system. The process of fuzzification allows the system inputs and outputs to be expressed in linguistic terms so that rules can be applied in a simple manner to express a complex system. Defuzzification After fuzzy reasoning we have a linguistic output variable which needs to be translated into a crisp value. The objective is to derive a single crisp numeric value that best represents the inferred fuzzy values of the linguistic output variable. Defuzzification is such inverse transformation which maps the output from the fuzzy domain back into the crisp domain. Some defuzzification methods tend to produce an integral output considering all the elements of the resulting fuzzy set with the corresponding weights. Other methods take into account just the elements corresponding to the maximum points of the resulting membership functions. 3. Fuzzy Logic Algorithm 1. Define the linguistic variables and terms (initialization) 2. Construct the membership functions (initialization) 3. Construct the rule base (initialization) 4. Convert crisp input data to fuzzy values using the membership functions (fuzzification) 5. Evaluate the rules in the rule base (inference)
  • 6. 6. Combine the results of each rule (inference) 7. Convert the output data to non-fuzzy values (defuzzification) I. Fuzzy Logic Algorithm of Controlling a Submarine 1. Linguistic Variables Linguistic variables are the input or output variables of the system whose values are words or sentences from a natural language, instead of numerical values. A linguistic variable is generally decomposed into a set of linguistic terms.  Fuzzy sets for depth: Depth = {Low, Medium, High}  Fuzzy sets for left obstacles: Left_Obstacles = {Close, Near, Far}  Fuzzy sets for right obstacles: Right_Obstacles = {Close, Near, Far}  Fuzzy sets for velocity: Velocity = {Slow, Medium, Fast}  Fuzzy sets for blade 1: Blade1 = {Lowlow, Low, Zero, High, Highhigh};  Fuzzy sets for blade 2: Blade2 = {Lowlow, Low, Zero, High, Highhigh};
  • 7. 2. Membershipfunctions Membership functions are used in the fuzzification and defuzzification steps of a FLS, to map the non-fuzzy input values to fuzzy linguistic terms and vice versa. A membership function is used to quantify a linguistic term. a. Popular Membership Functions: Figure 2:Examples of Popular Membership Functions The simplest membership functions are formed using straight lines. Of these, the simplest is the triangular membership function, and it has the function name trimf. This function is nothing more than a collection of three points forming a triangle. The trapezoidal membership function, trapmf, has a flat top and really is just a truncated triangle curve. These straight line membership functions have the advantage of simplicity. Two membership functions are built on the Gaussian distribution curve: a simple Gaussian curve and a two-sided composite of two different Gaussian curves. The two functions aregaussmf and gauss2mf. The generalized bell membership function is specified by three parameters and has the function name gbellmf. The bell membership function has one more
  • 8. parameter than the Gaussian membership function, so it can approach a non-fuzzy set if the free parameter is tuned. Because of their smoothness and concise notation, Gaussian and bell membership functions are popular methods for specifying fuzzy sets. Both of these curves have the advantage of being smooth and nonzero at all points. Although the Gaussian membership functions and bell membership functions achieve smoothness, they are unable to specify asymmetric membership functions, which are important in certain applications. Next, you define the sigmoidal membership function, which is either open left or right. Asymmetric and closed (i.e. not open to the left or right) membership functions can be synthesized using two sigmoidal functions, so in addition to the basic sigmf, you also have the difference between two sigmoidal functions, dsigmf, and the product of two sigmoidal functions psigmf. Polynomial based curves account for several of the membership functions in the toolbox. Three related membership functions are the Z, S, and Pi curves, all named because of their shape. The function zmf is the asymmetrical polynomial curve open to the left, smf is the mirror-image function that opens to the right, and pimf is zero on both extremes with a rise in the middle. There is a very wide selection to choose from when you're selecting a membership function. You can also create your own membership functions with the toolbox. However, if a list based on expanded membership functions seems too complicated, just remember that you could probably get along very well with just one or two types of membership functions, for example the triangle and trapezoid functions. The selection is wide for those who want to explore the possibilities, but expansive membership functions are not necessary for good fuzzy inference systems. Finally, remember that more details are available on all these functions in the reference section. b. Membership Functionsin Cotrollinga Submarine
  • 9. 𝜇 𝐴 ( 𝑥) = { 0 𝑖𝑓 𝑥 ≤ 𝑎 𝑥−𝑎 𝑏−𝑎 𝑖𝑓 𝑎 < 𝑥 ≤ 𝑏 𝑐−𝑥 𝑐−𝑏 𝑖𝑓 𝑏 < 𝑥 < 𝑐 0 𝑖𝑓 𝑥 ≥ 𝑐 Figure 4: Depth Membership Function Figure 5: Left-Right Obstacle Membership Function Figure 3: Triangular Membership Function
  • 10. Figure 6: Velocity Membership Function Figure 7.Blade1-Blade2 Membership Function 3. Fuzzy Rules In a FLS, a rule base is constructed to control the output variable. A fuzzy rule is a simple IF-THEN rule with a condition and a conclusion. Let:  L1: depth is low  L2: left obstacle is close  L3: right obstacle is close  L4: velocity is slow
  • 11.  M1: depth is medium  M2: left obstacle is near  M3: right obstacle is near  M4: velocity is medium  H1: depth is high  H2: left obstacle is far  H3: right obstacle is far  H4: velocity is fast  Z/Z or Z/L … stands for blade1/blade2. Then, we have the rule table below. Table 1. Rule Table of Fuzzy Logic L1 L2 L1 M2 L1 H2 M1 L2 M1 M2 M1 H2 H1 L2 H1 M2 H1 H2 L3 L4 Z/Z L/H L/H Z/Z L/H L/H Z/Z L/L L/L L3 M4 Z/Z L/H LL/H Z/Z L/H LL/H Z/Z L/L LL/L L3 H4 Z/Z LL/H LL/H Z/Z LL/H LL/H Z/Z LL/L LL/L M3 L4 H/H Z/H L/HH H/H Z/H L/H H/L Z/L L/LL M3 M4 H/H Z/H L/HH H/H Z/H L/HH H/L Z/L L/LL M3 H4 HH/H Z/HH L/HH HH/H Z/H L/HH HH/L H/LL L/LL H3 L4 HH/H Z/HH Z/HH HH/H H/HH Z/HH HH/L HH/LL Z/LL
  • 12. H3 M4 HH/H Z/HH Z/HH HH/H HH/H Z/HH HH/L H/L Z/LL H3 H4 HH/H Z/HH Z/HH HH/H H/H Z/HH HH/L H/L Z/LL According to table 1, we have 81 rules for two output blade1 and blade2 (1) if (Depth(Low) and Left_Obstacle(Far) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Zero and Blade2 is Zero (2) if (Depth(Low) and Left_Obstacle(Near) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Low and Blade2 is High (3) if (Depth(Low) and Left_Obstacle(Close) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Low and Blade2 is High (4) if (Depth(Medium) and Left_Obstacle(Far) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Zero and Blade2 is Zero (5) if (Depth(Medium) and Left_Obstacle(Near) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Low and Blade2 is High (6) if (Depth(Medium) and Left_Obstacle(Close) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Low and Blade2 is High (7) if (Depth(High) and Left_Obstacle(Far) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Zero and Blade2 is Zero
  • 13. (8) if (Depth(High) and Left_Obstacle(Near) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Low and Blade2 is Low (9) if (Depth(High) and Left_Obstacle(Close) and Right_Obstacle(Far) and Velocity(Slow)) then Blade1 is Low and Blade2 is Low … In the C codes we discuss in next section, we will have full of Rules. 4. Convert the output data to non-fuzzy values (defuzzification) After the inference step, the overall result is a fuzzy value. This result should be defuzzified to obtain a final crisp output. This is the purpose of the defuzzifier component of a FLS. Defuzzification is performed according to the membership function of the output variable. In this project, we choose Weighted Average Method because this method is valid for symmetrical output membership functions.
  • 14. The follwing codes based on C programming language run on CodeBlocks platform. #include <stdio.h> #include <stdlib.h> void assignRule_Blade (double L1, double L2, double L3, double L4, double M1, double M2, double M3, double M4, double H1, double H2, double H3, double H4, double blade1, double blade2); double triangular (double low, double mid, double high, double x); void Depth (double x, double a[]); void Left_Obstacles (double x, double a[]); void Right_Obstacles (double x, double a[]); void Velocity (double x, double a[]); double min4 (double x, double y, double m, double n); /* The C sub-functions:  void assignRule_Blade returns values of two blades (1 and 2)  double triangular returns the probability of number x in the triangle.
  • 15.  void Depth builds Depth membership function based on triangular function.  void Left_Obstacles builds Left_Obstacles membership function based on triangular function.  void Right_Obstacles builds Right_Obstacles membership function based on triangular function.  void Velocity builds Velocity membership function based on triangular function.  double min4 returns the minimum value of four given numbers. */ 1. main function int main() { double D[3], Le[3], Ri[3], V[3]; double L1, L2, L3, L4, M1, M2, M3, M4, H1, H2, H3, H4; Depth(52.4,D); Left_Obstacles (3.91,Le); Right_Obstacles(3.91,Ri); Velocity(10.2,V); L1 = D[0]; M1 = D[1]; H1 = D[2]; L2 = Le[2]; M2 = Le[1];
  • 16. H2 = Le[0]; L3 = Ri[2]; M3 = Ri[1]; H3 = Ri[0]; L4 = V[0]; M4 = V[1]; H4 = V[2]; double out_blade1, out_blade2; assignRule_Blade(L1, L2, L3, L4, M1, M2, M3, M4, H1, H2, H3, H4, out_blade1, out_blade2); return 0; } The way sub-functions implement 2.double triangular double triangular (double low, double mid, double high, double x) { double u;
  • 17. if (x<= low) u = 0; else if (x > low && x <= mid ) u = (x-low)/(mid-low); else if (x > mid && x <high) u = (high-x)/(high-mid); else if (x >= high) u = 0; return u; } void Depth (double x, double a[]) { a[0] = triangular (0, 20, 40, x); a[1] = triangular (20, 50, 80, x); a[2] = triangular (60, 80, 100, x); } void Left_Obstacles (double x, double a[]) { a[0] = triangular (0, 2, 4, x); a[1] = triangular (3, 5, 7, x); a[2] = triangular (6, 8, 10, x); } void Right_Obstacles (double x, double a[]) { a[0] = triangular (0, 2, 4, x); a[1] = triangular (3, 5, 7, x); a[2] = triangular (6, 8, 10, x);
  • 18. } void Velocity (double x, double a[]) { a[0] = triangular (0, 4, 8, x); a[1] = triangular (5, 10, 15, x); a[2] = triangular (12, 16, 20, x); } double min4 (double x, double y, double m, double n) { return (((x<y)? x:y) < ((m<n)? m:n)) ? ((x<y)? x:y) : ((m<n)? m:n) ; } 3.Assigning rules and returns the angles two blades rotate void assignRule_Blade(double L1, double L2, double L3, double L4, double M1, double M2, double M3, double M4, double H1, double H2, double H3, double H4, double blade1, double blade2) {
  • 20. h2[0] = min4(L1,L2, M3, L4); } if (L1 && L2 && M3 && M4) { h1[1] = min4(L1,L2, M3, M4); h2[1] = min4(L1,L2, M3, M4); } if (L1 && L2 && M3 && H4) { hh1[0] = min4(L1,L2,M3,H4); h2[2] = min4(L1,L2,M3,H4); } if (L1 && L2 && H3 && L4) { hh1[1] = min4(L1,L2,H3,L4); h2[3] = min4(L1,L2,H3,L4); } if (L1 && L2 && H3 && M4) { hh1[2] = min4(L1,L2,H3,M4); h2[4] = min4(L1,L2,H3,M4); } if (L1 && L2 && H3 && H4) { hh1[3] = min4(L1,L2,H3,H4); h2[5] = min4(L1,L2,H3,H4); }
  • 21. if (L1 && M2 && L3 && L4) { l1[0] = min4(L1,M2,L3,L4); h2[6] = min4(L1,M2,L3,L4); } if (L1 && M2 && L3 && M4) { l1[1] = min4(L1,M2,L3,M4); h2[7] = min4(L1,M2,L3,L4); } if (L1 && M2 && L3 && H4) { ll1[0] = min4(L1,M2,L3,H4); h2[8] = min4(L1,M2,L3,H4); } if (L1 && M2 && M3 && L4) { z1[1] = min4(L1,M2,M3,L4); h2[9] = min4(L1,M2,M3,L4); } if (L1 && M2 && M3 && M4) { z1[2] = min4(L1,M2,M3,M4); h2[10] = min4(L1,M2,M3,M4); } if (L1 && M2 && M3 && H4) {
  • 22. z1[3] = min4(L1,M2,M3,H4); hh2[0] = min4(L1,M2,M3,M4); } if (L1 && M2 && H3 && L4) { h1[2] = min4(L1,M2,H3,L4); hh2[1] = min4(L1,M2,H3,L4); } if (L1 && M2 && H3 && M4) { hh1[3] = min4(L1,M2,H3,M4); hh2[2] = min4(L1,M2,H3,L4); } if (L1 && M2 && H3 && H4) { h1[3] = min4(L1,M2,H3,H4); h2[11] = min4(L1,M2,H3,H4); } if (L1 && H2 && L3 && L4) { l1[2] = min4(L1,H2,L3,L4); h2[12] = min4(L1,H2,L3,L4); } if (L1 && H2 && L3 && M4) { ll1[1] = min4(L1,H2,L3,M4); h2[13] = min4(L1,H2,L3,M4);
  • 23. } if (L1 && H2 && L3 && H4) { l1[3] = min4(L1,H2,L3,H4); h2[14] = min4(L1,H2,L3,L4); } if (L1 && H2 && M3 && L4) { l1[4] = min4(L1,H2,M3,L4); hh2[3] = min4(L1,H2,M3,L4); } if (L1 && H2 && M3 && M4) { l1[5] = min4(L1,H2,M3,M4); hh2[4] = min4(L1,H2,M3,M4); } if (L1 && H2 && M3 && H4) { l1[6] = min4(L1,H2,M3,H4); hh2[5] = min4(L1,H2,M3,H4); } if (L1 && H2 && H3 && L4) { z1[4] = min4(L1,H2,H3,L4); hh2[6] = min4(L1,H2,H3,L4); } if (L1 && H2 && H3 && M4)
  • 24. { z1[5] = min4(L1,H2,H3,M4); hh2[7] = min4(L1,H2,H3,M4); } if (L1 && H2 && H3 && H4) { z1[6] = min4(L1,H2,H3,H4); hh2[8] = min4(L1,H2,H3,H4); } if (M1 && L2 && L3) { z1[7] = min4(M1, L2, L3, 1); z2[1] = min4(M1, L2, L3, 1); } if (M1 && L2 && M3 && L4) { h1[4] = min4(M1, L2, L3, L4); h2[15] = min4(M1, L2, L3, L4); } if (M1 && L2 && M3 && M4) { h1[5] = min4(M1, L2, L3, M4); h2[16] = min4(M1, L2, L3, M4); } if (M1 && L2 && M3 && H4) {
  • 25. hh1[4] = min4(M1,L2,M3,H4); hh2[9] = min4(M1,L2,M3,H4); } if (M1 && L2 && H3 ) { hh1[5] = min4(M1,L2,H3,1); hh2[10] = min4(M1,L2,H3,1); } if (M1 && M2 && L3 && L4) { l1[7] = min4(M1,M2,L3,L4); h2[17] = min4(M1,M2,L3,L4); } if (M1 && M2 && L3 && M4) { l1[8] = min4(M1,M2,L3,M4); h2[18] = min4(M1,M2,L3,M4); } if (M1 && M2 && L3 && H4) { ll1[2] = min4(M1,M2,L3,H4); h2[19] = min4(M1,M2,L3,H4); } if (M1 && M2 && M3 ) { z1[8] = min4(M1,M2,M3,1); h2[20] = min4(M1,M2,M3,1);
  • 26. } if (M1 && M2 && H3 && L4) { h1[6] = min4(M1,M2,H3,L4); hh2[11] = min4(M1,M2,H3,L4); } if (M1 && M2 && H3 && M4) { hh1[6] = min4(M1,M2,H3,M4); hh2[12] = min4(M1,M2,H3,M4); } if (M1 && M2 && H3 && H4) { h1[7] = min4(M1,M2,H3,H4); h2[21] = min4(M1,M2,H3,H4); } if (M1 && H2 && L3 && L4) { l1[9] = min4(M1,H2,L3,L4); h2[22] = min4(M1,H2,L3,L4); } if (M1 && H2 && L3 && M4) { ll1[3] = min4(M1,H2,L3,M4); h2[23] = min4(M1,H2,L3,M4); } if (M1 && H2 && L3 && H4)
  • 27. { ll1[4] = min4(M1,H2,L3,H4); h2[24] = min4(M1,H2,L3,H4); } if (M1 && H2 && M3) { l1[10] = min4(M1,H2,M3,1); hh2[13] = min4(M1,H2,M3,1); } if (M1 && H2 && H3) { z1[9] = min4(M1,H2,H3,1); hh2[14] = min4(M1,H2,H3,1); } if (H1 && L2 && L3) { z1[10] = min4(H1,L2,L3,1); z2[2] = min4(H1,L2,L3,1); } if (H1 && L2 && M3 && L4) { h1[8] = min4(H1,L2,M3,L4); l2[0] = min4(H1,L2,M3,L4); } if (H1 && L2 && M3 && M4) {
  • 28. h1[9] = min4(H1,L2,M3,M4); l2[1] = min4(H1,L2,M3,M4); } if (H1 && L2 && M3 && H4) { hh1[7] = min4(H1,L2,M3,H4); l2[2] = min4(H1,L2,M3,H4); } if (H1 && L2 && H3 ) { hh1[8] = min4(H1,L2,H3,1); l2[3] = min4(H1,L2,H3,1); } if (H1 && M2 && L3 && L4) { l1[11] = min4(H1,M2,L3,L4); l2[4] = min4(H1,M2,L3,L4); } if (H1 && M2 && L3 && M4) { l1[12] = min4(H1,M2,L3,M4); l2[5] = min4(H1,M2,L3,M4); } if (H1 && M2 && L3 && H4) { ll1[5] = min4(H1,M2,L3,H4); l2[6] = min4(H1,M2,L3,H4);
  • 29. } if (H1 && M2 && M3) { z1[11] = min4(H1,M2,M3,1); l2[7] = min4(H1,M2,M3,1); } if (H1 && M2 && H3 && L4) { h1[10] = min4(H1,M2,H3,L4); ll2[3] = min4(H1,M2,H3,L4); } if (H1 && M2 && H3 && M4) { hh1[9] = min4(H1,M2,H3,M4); ll2[2] = min4(H1,M2,H3,M4); } if (H1 && M2 && H3 && H4) { h1[11] = min4(H1,M2,H3,H4); l2[8] = min4(H1,M2,H3,H4); } if (H1 && H2 && L3 && L4) { l1[13] = min4(H1,H2,L3,L4); l2[9] = min4(H1,H2,L3,L4); } if (H1 && H2 && L3 && M4)
  • 30. { ll1[6] = min4(H1,H2,L3,M4); l2[10] = min4(H1,H2,L3,M4); } if (H1 && H2 && L3 && H4) { ll1[7] = min4(H1,H2,L3,H4); l2[11] = min4(H1,H2,L3,H4); } if (H1 && H2 && M3) { l1[14] = min4(H1,H2,M3,1); ll2[1] = min4(H1,H2,M3,1); } if (H1 && H2 && H3) { z1[12] = min4(H1,H2,H3,1); ll2[0] = min4(H1,H2,H3,1); } 4. max-min method double ll1max = ll1[0],ll2max=ll2[0],l1max=l1[0],l2max=l2[0],z1max=z1[0],z2max=z2[0],h 1max=h1[0],h2max=h2[0],hh1max=hh1[0],hh2max=hh2[0]; for(idx=1;idx<25;idx++)
  • 31. { if(ll1max<ll1[idx]) ll1max=ll1[idx]; if(ll2max<ll2[idx]) ll2max=ll2[idx]; if(l1max<l1[idx]) l1max=l1[idx]; if(l2max<l2[idx]) l2max=l2[idx]; if(z1max<z1[idx]) z1max=z1[idx]; if(z2max<z2[idx]) z2max=z2[idx]; if(h1max<h1[idx]) h1max=h1[idx]; if(h2max<h2[idx]) h2max=h2[idx]; if(hh1max<hh1[idx]) hh1max=hh1[idx]; if(hh2max<hh2[idx]) hh2max=hh2[idx]; } printf("ll1 = %f l1 = %f z1=%f h1 = %f hh1 = %fn", ll1max,l1max,z1max,h1max,hh1max); printf("ll2 = %f l2 = %f z2=%f h2 = %f hh2 = %fn", ll2max,l2max,z2max,h2max,hh2max); // weighted average equation to find out the angles two blades rotate. blade1 = (ll1max*15 + l1max*52 + z1max*92 + h1max*130 + hh1max*165 )/(ll1max+l1max+z1max+h1max+hh1max); blade2 = (ll2max*15 + l2max*50 + z2max*90 + h2max*130 + hh2max*165 )/(ll2max+l2max+z2max+h2max+hh2max); printf("blade1 = %f nblade2 = %f ", blade1,blade2); }
  • 32. 5. Result The following figures show the results of simulating fuzzy logic on Matlab (above) and implementing C programming on CodeBlocks (below).
  • 33.
  • 34.
  • 35.
  • 36. After testing many times, we get other results recorded in table 2 Table2. Theinputparametersandresults comparison Depth Left Obstacle Right Obstacle Velocity Matlab’s results Blade1/Blade2 CodeBlock’s results Blade1/Blade2 75 5 5 75 90/62 92/64.55 80 6 9 18 13/53 15/50 10 6 9 18 17/129 15/130 29.89 8.97 5.3 6.17 129/133 130/130 25.62 3.42 5.32 17.17 68/150 68.8/151.264 15.8452 8.472 2.32 7.127 159/135 162/130 90 9.472 9.32 9.127 90/90 92/90 7 9 9.32 9.13 90/90 92/90 35 4.6 9.5 9.7 53/127 52/130 6. Conclusion There are some little differences between Matlab and CodeBlocks. This comes from the difference of processing input and defuzzification method. If time permits, we think we can improve the C codes to enhance the quality of results efficiently.