42
Assignment 1 Report on Practical Exercise Submitted as part of the requirements for: CE888 Fuzzy Logic Hybrid System Name: Umair Ahmad Nasir Module Code: CE888 Module Supervisor: Prof. Dr. Hani Hagras Date: 22 th March, 2012

Fuzzy Logic Hybrid System

Embed Size (px)

DESCRIPTION

Left/ Right Wall Following Behaviour with obstacle avoidance

Citation preview

Page 1: Fuzzy Logic Hybrid System

Assignment 1 Report on Practical Exercise

Submitted as part of the requirements for:

CE888 Fuzzy Logic Hybrid System

Name: Umair Ahmad Nasir

Module Code: CE888

Module Supervisor: Prof. Dr. Hani Hagras

Date: 22th March, 2012

Page 2: Fuzzy Logic Hybrid System

Table of Contents Abstract ...................................................................................................................................... 4

1 Aim ..................................................................................................................................... 4

2 Objectives ........................................................................................................................... 4

3 Introduction ........................................................................................................................ 5

3.1 Linguistic Variables .................................................................................................... 5

3.2 Membership Functions ................................................................................................ 6

3.3 Fuzzy Rules ................................................................................................................. 7

3.4 Defuzzication .............................................................................................................. 7

4 Literature Review ............................................................................................................... 7

4.1 Background ................................................................................................................. 7

4.2 Advantages and Disadvantages of Fuzzy Logic Control System ............................. 10

4.2.1 Advantages ......................................................................................................... 10

4.2.2 Disadvantages .................................................................................................... 10

4.3 Higher Fuzzy Level Controller ................................................................................. 11

5 Implementation ................................................................................................................. 13

5.1 Left Wall Following Behaviour ................................................................................ 13

5.1.1 Surface Viewer................................................................................................... 15

5.2 Right Wall Following Behaviour .............................................................................. 16

5.2.1 Surface Viewer................................................................................................... 19

5.3 Obstacle Avoidance Behaviour ................................................................................. 20

5.3.1 Surface Viewer................................................................................................... 22

5.4 Higher Fuzzy Level Controller ................................................................................. 24

5.5 MobileSim Output Map ............................................................................................ 25

6 Improvement ..................................................................................................................... 25

7 Conclusion ........................................................................................................................ 26

8 References ........................................................................................................................ 27

Appendix .................................................................................................................................. 28

Page 3: Fuzzy Logic Hybrid System

Table of Figures

Figure 1: Fuzzy Logic System ................................................................................................... 5

Figure 2: Linguistic Variables ................................................................................................... 6

Figure 3: Membership Functions ............................................................................................... 6

Figure 4 : Higher Fuzzy Level Controller [4] ........................................................................... 12

Figure 5: Fuzzy Sets................................................................................................................. 13

Figure 6: Rule Viewer .............................................................................................................. 15

Figure 7: Output Fuzzy Sets .................................................................................................... 15

Figure 8: Left Velocity vs. LBS and LFS ................................................................................ 16

Figure 9: Right Velocity vs. LBS and LFS .............................................................................. 16

Figure 10: Fuzzy Sets............................................................................................................... 17

Figure 11: Rule Viewer ............................................................................................................ 18

Figure 12: Output Fuzzy Sets .................................................................................................. 18

Figure 13: Left Velocity vs. RBS and RFS.............................................................................. 19

Figure 14: Right Velocity vs. RBS and RFS ........................................................................... 19

Figure 15: OA Fuzzy Sets ........................................................................................................ 20

Figure 16: Rule Viewer ............................................................................................................ 21

Figure 17: OA Output Fuzzy Sets ............................................................................................ 22

Figure 18: Left Sensor, Front Sensor vs. Left Velocity ........................................................... 22

Figure 19: Left Sensor, Right Sensor vs. Left Velocity ........................................................... 23

Figure 20: Right Sensor, Front Sensor vs. Left Velocity ......................................................... 23

Figure 21: Right Sensor, Front Sensor vs. Right Velocity ...................................................... 24

Figure 22 : MobileSim Map ..................................................................................................... 25

Page 4: Fuzzy Logic Hybrid System

Abstract

The purpose of this report is to describe the tasks implemented for the assignment 1of the

Fuzzy Logic Hybrid System. This assignment is about implementation of Left and Right

Edge following fuzzy behaviours of the robot and the obstacle avoidance fuzzy

behaviour that will enable the robot to follow the wall and avoid the obstacles.

This assignment is implemented in three steps. In the first step the Left and the Right

Edge following fuzzy behaviours are implemented to enable the robot to follow the

closest wall. In the second part of the assignment the obstacle avoidance fuzzy behaviour

is implemented that allows to avoid obstacles. In the last part of the assignment fuzzy

coordination (Higher Fuzzy Level Controller) is used to coordinate the obstacle

avoidance, left edge following and right edge following fuzzy behaviours to enable the

robot to follow the edges while avoiding the obstacles.

1 Aim The aims of this assignment are:

1. Design a Left Edge following and Right Edge Following Fuzzy Behaviours that will

enable the robot to follow an edge at a desired distance.

2. Design an Obstacle Avoidance Behaviour that will allow avoid obstacles

3. Use Fuzzy Coordination to coordinate the obstacle avoidance, left edge following and

right Edge following behaviours to enable the robot to follow edges while avoiding

obstacles.

2 Objectives

The objectives of this assignment are:

1. Learning to apply the knowledge gained from the course to design and implement

a fuzzy controller for a mobile robot.

2. Producing a report on the design and implementation of the controller.

Page 5: Fuzzy Logic Hybrid System

3. Showing the functioning of the controller in a lab demonstration.

3 Introduction A fuzzy logic system (FLS) is defined as the nonlinear mapping of an input data set to a

scalar output data [3]. A fuzzy logic system consists of four main parts: fuzzifier, rules

inference engine and defuzzifier. These components and the general architecture of a

FLS is shown in Figure 1

The process of fuzzy logic is explained in Figure 1: 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 fuzzication. 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 defuzzication step.

3.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. In this assignment for the

left wall following three linguistic variables (Low, Medium and High) are used to

represent the distance of the robot from the wall, as shown in figure 2. The linguistic

variable Low is a trapezoid function ranges from 0 to 550. The linguistic variable

Medium is also a trapezoid function ranges from 450 to 750. The linguistic variable

High is a trapezoid function ranges from 550 to 1000.

Fuzzifier

Inference

Defuzzifier

Rules

Crisp Inputs

Fuzzy Input set Fuzzy output set

Crisp Outputs

Figure 1: Fuzzy Logic System

Page 6: Fuzzy Logic Hybrid System

Figure 2: Linguistic Variables

3.2 Membership Functions Membership functions are used in the fuzzication and defuzzication 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. For example, in Figure 2, membership

functions for the linguistic terms of distance variable (Low, Medium and High) are

plotted.

There are different forms of membership functions such as triangular, trapezoidal,

piecewise linear, Gaussian, or singleton (Figure 3). The most common types of

membership functions are triangular, trapezoidal, and Gaussian shapes.

Figure 3: Membership Functions

Page 7: Fuzzy Logic Hybrid System

3.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. The table below show the

examples of some rules for the left wall following implemented in this assignment.

Fuzzy Rule

If Left Front Distance is low and Left Back Distance is low then turn right

If Left Front Distance is Far and Left Back Distance is low then turn left.

If Left Front Distance is Medium and Left Back Distance is Medium then don’t turn.

3.4 Defuzzication After the inference step, the overall result is a fuzzy value. This result should be

defuzzied to obtain a crisp output. This is the purpose of the defuzzier component of a

FLS. Defuzzication is performed according to the membership function of the output

variable. There are different algorithms for defuzzication too. The mostly-used algorithm

is centre of gravity.

4 Literature Review

4.1 Background

Fuzzy logic is one of the newest models in the control system. It was invented in 1964 in

America. Fuzzy logic more closely represents human thought than the fundamentals of

classical control. Fuzzy logic allows a user to describe a system using natural words, and

create a control mechanism based on “expert rules” or in other words, rules developed

through experience. A fuzzy controller is developed without creating a mathematical model

of the system. For example, a fuzzy logic code may contain the following linguistic rule: If

the temperature is high, then fan will run in the fast speed. The combination of these simple

rules allows the system to be easily analysed, controlled, modified, and understood.

Initially, the concepts of Fuzzy Logic were very controversial in the American Academic

Community. However, in the thirty years since the development of Fuzzy Logic, the Japanese

Page 8: Fuzzy Logic Hybrid System

have start working on the prevailing simplicity of the technology, and developed control

systems for products like, self-focusing cameras, dishwashers, and subway systems.

The power of fuzzy logic lies in its simplicity and with its close resemblance with the human

thought process. The foundations of Fuzzy Logic are as old as the discipline of the traditional

logic theory Aristotle developed centuries ago. Classical logic theory is based on the principle

of “crisp” sets, or the law of the omitted middle which says that X must be member of set A

or not member of set A. Everything falls in one group or another; there is nothing lies

between the two points.

Even Aristotle recognized the defect in this reasoning. Human thought allows consideration

of vagueness and imprecision. The concepts of fuzzy logic attempt to describe the universe in

a more natural manner. Lofti Zadeh, recognized these flaws with traditional logic theory, and

invented the concepts of fuzzy logic in 1964.

Fuzzy logic allows each element of the set being considered, to belong to a set to a certain

degree. This degree of belonging is represented in fuzzy sets by a membership value that

varies between 0 and 1.

Classical set theory is a special case of fuzzy set theory that contains a discontinuous break in

the membership of a set in the jump between true and not true. Fuzzy logic allows a more

continuous, smooth variation from membership to non-membership in a set.

A membership function represents how each point in the input space is plotted with a

degree of membership to the set in consideration. Membership functions can come in many

shapes from triangular, trapezoid, Gaussian etc. membership functions. Although shapes of

membership functions vary, ranges of the function usually vary between 0 and 1.

In a vehicle control algorithm, one of the important aspects is the distance relative to some

reference object.

The principles of classical set theory and classical logic are translated into fuzzy set

counterparts through the use of mathematical relations.

In classical set theory, the principle of set intersection is used to identify common

membership between 2 sets. Intersection is usually indicated through an AND statement. To

be a member of a set described by an AND statement, the item under consideration must be a

member of both sets combined with the AND statement.

Page 9: Fuzzy Logic Hybrid System

For example, the following categories represent a distance considered to be near the wall, a

distance considered far from the wall, and a distance considered to be both near the wall and

far (1 indicates set membership, 0 indicates non-membership).

Near Distance Far Distance Near Distance and Far Distance 0 0 0 0 1 0 1 0 0 1 1 1

In fuzzy set theory, the process of intersection is interpreted through the use of the

mathematical “minimum function” , which returns the minimum of two values. The

minimum function can also be used to interpret AND statements in the Classical Logic

example. For example, the following categories represent a distance considered to be near the

wall, a distance considered far from the wall , and a distance considered to be both near the

wall and far.

Near Distance Far Distance Near Distance and Far Distance 0.2 0.5 0.2 0.1 0.05 0.05 1.0 0 0 0.1 0.5 0.1

In classical set theory, the principle of set union is used to classify the entire membership of

two sets. Union is usually indicated through an OR statement. To be a member of a set

described by an OR statement, the item under observation should be a member of one of the

sets combined with the OR statement. For example, the following categories represent a

motor speed to be slow forward, fast forward, and slow forward or forward.

Slow Forward Fast Forward Slow Forward or Fast Forward 0 0 0 0 1 1 1 0 1 1 1 1

Page 10: Fuzzy Logic Hybrid System

In fuzzy set theory, the process of intersection may be handled by the use of the mathematical

“maximum function” , which returns the maximum of two values. For example, the

following categories represent a motor speed to be slow forward, fast forward, and slow

forward or fast forward.

Slow Forward Fast Forward Slow Forward or Fast Forward 0.2 0.5 0.5 0.1 0.05 0.1 1.0 0.4 1.0 0.9 1.0 1.0

4.2 Advantages and Disadvantages of Fuzzy Logic Control System

4.2.1 Advantages • Fewer values, rules, and decisions are required • More observed variables can be evaluated. Linguistic, no numerical, variables are

used, making it similar to the way humans think. • It relates output to input, without having to understand all the variables, permitting the

design of a system that may be more accurate and stable than one with a conventional control system.

• Simplicity allows the solution of previously unsolved problems. • They are cheaper to male than conventional systems because they are easier to design.

• They have increased robustness. • They simplify knowledge acquisition and representation. • A few rules encompass great complexity.

4.2.2 Disadvantages • It’s hard to develop a model from a fuzzy system.

• Though they are easier to design and faster to prototype than conventional control systems, fuzzy systems require more simulation and fine tuning before they are operational.

Page 11: Fuzzy Logic Hybrid System

4.3 Higher Fuzzy Level Controller The single rule base fuzzy level controller have some very serious restriction, that the number

of rules increases in an exponential manner with the number of variables involved. If a robot

have only eight input sensors, and it represented each input by only three fuzzy sets then for

a single rule base 38=6561 rules, are required which is very difficult to design, also this huge

rule base result into slower controller response.

The solution of this large rule base problem is solved by using the hierarchically level fuzzy

controller. In this controller the input space is broken down into multiple low level fuzzy

behaviours. Each behaviour reacts to specific types of situations, and then integrating the

recommendations of these behaviours through a high level fuzzy coordination layer. Each

behaviour is an independent and self-contained FLC with a small number of inputs and

outputs and a small rule base and it operates a single purpose (e.g. left edge-following, right

edge following obstacle avoidance) while operating in a reactive fashion. The hierarchical

fuzzy systems have a nice property that the total number of rules increases linearly rather

than exponentially as in the single rule base FLC. For example, we divide the robot controller

into three co-operating behaviours namely obstacle avoidance, left and right edge following.

If we represented each input using three fuzzy sets, then the obstacle avoidance behaviour,

using three laser sensors(Front, left and right), will have a rule base of 23 = 8 rules. The left

edge following behaviour, using two left side laser sensors (laserRange [14], laserRange

[17]), will have a rule base of 32 = 9 rules, and the right edge following behaviour will have

the same number of rules. Thus the total number of rules in lower level behaviours is 8 + 9 +

9 = 26 rules and the total number of rules in the lower level coordination layers are 3 (number

of behaviours), thus we need a very small number of rules as compare to 6561 rules in the

case of the single rule base FLC and these rules are easily implemented.

In this higher fuzzy level controller, each low level behaviour is a lower level fuzzy level

controller. Each low level behaviour will receive crisp input from the laser sensors and

produce the output that is available to the HFLC. We have used four low level behaviours

which are obstacle avoidance, goal seeking, left and right edge. In the following subsections,

we will explain further each of these low level behaviours. These basic FLCs compose the

basics of our robots low level, intermediate and high level behaviours.

In the HFLC architecture, at the high level have a high level FLC which do coordination with

all the low level FLCs based behaviours. Each low level behaviour has a state of activation

Page 12: Fuzzy Logic Hybrid System

indicating the behaviour should be activated. The state of activation of behaviours is

represented by fuzzy set as shown in Figure to handle the linguistic and numerical

uncertainties associated with these state. Each behaviour is activated with a strength given by

the membership value of the state, i.e. the degree of firing of the fuzzy set.

The higher FLC receives the crisp inputs from the laser sensors of the robot. These crisp

inputs are then fuzzified by matching each input to its HFLC fuzzy membership function.

When the crisp inputs are fuzzified against the HFLC membership functions. The high level

coordination FLC has a coordination rule base which contains coordination rules that

describe in a fuzzy way when each behaviour should be activated to influence the operation

of the robot at each moment.

Context Fuzzifier

Coordination Rule Base

Defuzzifier

Inference Input Fuzzy sets

Input to Context

Input Fuzzy sets

Crips Output

Rule Base

Inference

Fuzzifier

Defuzzifier Behaviour 1

Rule Base

Inference

Fuzzifier

Defuzzifier Behaviour 2

Rule Base

Inference

Fuzzifier

Defuzzifier Behaviour 3

Figure 4 : Higher Fuzzy Level Controller [4]

Page 13: Fuzzy Logic Hybrid System

5 Implementation

5.1 Left Wall Following Behaviour

The Right Wall Following (RWF) fuzzy behaviour is implemented by using 2 laser sensors

(laserRange [14], laserRange [17]) of the pioneer robot. The Right Front Sensor (LFS),

laserRange [14], measure the distance of the robot from the wall from the left front corner.

The Left Back Sensor (LBS), laserRange [17], measure the distance of the robot from the

wall from the left back corner. The left wall following behaviour fuzzy level controller is fed

with these two sensors to represent the distance of the robot from the wall. Hence, the LWF

fuzzy behaviour controller receives two inputs where each represents the distance from the

front and back corner of the left wall. Each of the FLC inputs were represented by three fuzzy

sets Low, Medium and High as shown in Figure. The linguistic variable Low is a trapezoid

function ranges from 0 to 550. The linguistic variable Medium is also a trapezoid function

ranges from 450 to 750. The linguistic variable High is a trapezoid function ranges from 550

to 1000.

As the LWF FLC has the two inputs and each of the FLC input is represented by three fuzzy

sets (Low, Medium, High). Hence, the RWF behaviour has a rule base of 33 = 9 rules. Once

the input data was fuzzified, the eight defined fuzzy logic rules in the Table were executed in

order to assign fuzzy values for left and right velocity of the robot.

Figure 5: Fuzzy Sets

Page 14: Fuzzy Logic Hybrid System

In the section of rule base, we used both common sense and strategy to determine what one

should do with the situation presented.

For example, if the input 1 (laserRange [14]) is LOW and the input 2 (laserRange [17]) is

also Low then the left velocity will be High and the right velocity will be Low. This indicates

that the robot will move right away from the wall. Similarly, if the distance from the left

front sensor is High from the left side and the distance from the left Back Sensor of the robot

is Low then the robot will not turn to the left direction. The Figure below shows the rule

viewer of the Matlab Fuzzy Toolbox for the left wall following fuzzy controller. It is clear

from the figure that when all the two inputs (Yellow colours trapezoid) of the RWF FLC are

low then first rule is fired. The resultant output, left and right velocity is also shown,

indicating what the left and the right velocities would be low.

Left Front Sensor Left Back Sensor Left Velocity Right Velocity Low Low High Low Low Medium High Low Low High High Low

Medium Low Low High Medium Medium Medium Medium Medium High High Low

High Low Low High High Medium Low High High High High High

Page 15: Fuzzy Logic Hybrid System

Figure 6: Rule Viewer The Left Wall Following Fuzzy level controller has the two outputs, Left Velocity and Right

Velocity. Each of the LWF FLC outputs were represented by three fuzzy sets Low, Medium

and High as shown in Figure. The linguistic variable Low is a trapezoid function ranges from

0 to 70. The linguistic variable Medium is also a trapezoid function ranges from 70 to 140.

The linguistic variable High is a trapezoid function ranges from 140 to 210.

5.1.1 Surface Viewer The surface viewer of the LWF FLC is plotted against the Left Front Sensor (LFS), Left Back

Sensor (LBS) sensors and the left and the right velocity. The figure below shows the 3

dimensional surface graphs of the LFS, LBS and the left velocity of the robot. It is clear from

the graph that the increase in the LBS increases the left velocity whereas with increase in LFS

the left velocity decreases.

Figure 7: Output Fuzzy Sets

Page 16: Fuzzy Logic Hybrid System

Figure 8: Left Velocity vs. LBS and LFS In the surface graph of the LBS and LFS input against the right velocity it is clear when the

LFS value becomes high the right velocity increase.

Figure 9: Right Velocity vs. LBS and LFS

Right Wall Following Behaviour

The Right Wall Following (RWF) fuzzy behaviour is implemented by using 2 laser sensors of

the pioneer robot. The Right Front Sensor (RFS), laserRange [3], measure the distance of the

robot from the wall from the right front corner. The Right Back Sensor (RBS), laserRange

[0], measure the distance of the robot from the wall from the right back corner. The right

wall following behaviour fuzzy level controller is fed with these two sensors to represent the

distance of the robot from the wall. Hence, the RWF fuzzy behaviour controller receives two

Page 17: Fuzzy Logic Hybrid System

inputs where each represents the distance from the front and back corner of the right wall.

Each of the FLC inputs were represented by three fuzzy sets Low, Medium and High as

shown in Figure. The linguistic variable Low is a trapezoid function ranges from 0 to 550.

The linguistic variable Medium is also a trapezoid function ranges from 450 to 750. The

linguistic variable High is a trapezoid function ranges from 550 to 1000.

Figure 10: Fuzzy Sets As the RWF FLC has the two inputs and each of the FLC input is represented by three fuzzy

sets (Low, Medium, High). Hence, the RWF behaviour has a rule base of 33 = 9 rules. Once

the input data was fuzzified, the eight defined fuzzy logic rules in the Table were executed in

order to assign fuzzy values for left and right velocity of the robot.

In the section of rule base, we used both common sense and strategy to determine what one

should do with the situation presented.

Right Front Sensor Right Back Sensor Left Velocity Right Velocity Low Low Low High Low Medium Low High Low High Low High

Medium Low High Low Medium Medium Medium Medium Medium High Low High

High Low High Low High Medium High Low High High High High

Page 18: Fuzzy Logic Hybrid System

For example, if the input 1 (laserRange [3]) is LOW and the input 2 (laserRange [0]) is also

LOW then the left velocity will be LOW and the right velocity will be HIGH. This indicates

that the robot will move left away from the wall. Similarly, if the distance from the right

front sensor is High from the Right side and the distance from the Right Back Sensor of the

robot is Low then the robot will not turn to the right direction. The Figure below shows the

rule viewer of the Matlab Fuzzy Toolbox. It is clear from the figure that when all the two

inputs (Yellow colours trapezoid) of the RWF FLC are low then first rule is fired. The

resultant output, left and right velocity is also shown, indicating what the left and the right

velocities would be low.

Figure 11: Rule Viewer

The Right Wall Following Fuzzy level controller has the two outputs, Left Velocity and

Right Velocity. Each of the RWF FLC outputs were represented by three fuzzy sets Low,

Medium and High as shown in Figure. The linguistic variable Low is a trapezoid function

ranges from 0 to 70. The linguistic variable Medium is also a trapezoid function ranges from

70 to 140. The linguistic variable High is a trapezoid function ranges from 140 to 1000.

Figure 12: Output Fuzzy Sets

Page 19: Fuzzy Logic Hybrid System

5.1.2 Surface Viewer The surface viewer of the RWF FLC is plotted against the Right Front Sensor (RFS), Right

Back Sensor (RBS) sensors and the left and the right velocity. The figures below shows the 3

dimensional surface graphs of the RFS, RBS and the left velocity, right velocity of the robot.

It is clear from the graph that the increase in the RFS increases the left velocity .

Figure 13: Left Velocity vs. RBS and RFS

In the surface graph of the RBS input and the RFS input against the right velocity it is clear

when the right velocity becomes High with the increase in RBS and RFS input values.

Figure 14: Right Velocity vs. RBS and RFS

Page 20: Fuzzy Logic Hybrid System

5.2 Obstacle Avoidance Behaviour

The Obstacle Avoidance (OA) behaviour is implemented by using 6 laser sensors of the

pioneer robot. In order to decrease the rule base size we grouped those sensors into three

groups. The first group detect obstacles facing the robot; this group consists of the front

sensors (laserRange [8], laserRange [10]). The obstacle avoidance fuzzy level controller is

fed with the minimum of those two sensors to represent the sensor reading for obstacles

located in front of the robot. The other two groups represented obstacles that are located on

the robot’s right and left sides. These two groups use left sensors (laserRange [17],

laserRange [14]), and right sensors (laserRange [0], laserRange [3]) of the robot’s case.

Again, the OA FLC was fed with the minimum of those two sensors on the right and left.

Hence, the OA receives three inputs where each represents the minimum distance from the

front, left and right sides respectively. Each of the FLC inputs were represented by two fuzzy

sets Near and Far as shown in Figure. The linguistic variable Near is a trapezoid function

ranges from 0 to 600. The linguistic variable Far is also a trapezoid function ranges from 400

to 1000.

Figure 15: OA Fuzzy Sets As the OA FLC has the three inputs and each of the FLC input is represented by two fuzzy

sets. Hence, the OA behaviour has a rule base of 23 = 8 rules. The Table below shows the all

the rules implemented for the OA FLC.

Page 21: Fuzzy Logic Hybrid System

Left Sensors Front Sensors Right Sensors Left Velocity Right Velocity Near Near Near Low Low Near Near Far High Low Near Far Near Medium Medium Near Far Far High Low Far Near Near Low High Far Near Far High Low Far Far Near Low High Far Far Far High High

In the section of rule base, we used both common sense and strategy to determine what one

should do with the situation presented.

For example, if the obstacle is Near from the front side Near from the Left side and Far from

the Right side of the robot then the robot will turn right to avoid the obstacle. Similarly, if the

obstacle is Far from the front side Far from the Left side and Far from the Right side of the

robot then the robot will not turn in any direction and go straight. The Figure below shows

the rule viewer of the Matlab Fuzzy Toolbox. It is clear from the figure that when all the

three inputs (Yellow colours trapezoid) of the OA FLC are low then first rule is fired. The

resultant output, left and right velocity is also shown, indicating that the left and the right

velocities would be low.

Figure 16: Rule Viewer

Page 22: Fuzzy Logic Hybrid System

The Obstacle avoidance Fuzzy level controller has the two outputs, Left Velocity and Right

Velocity. Each of the OA FLC outputs were represented by three fuzzy sets Low, Medium

and High as shown in Figure. The linguistic variable Low is a trapezoid function ranges from

0 to 70. The linguistic variable High is also a trapezoid function ranges from 70 to 140. The

linguistic variable High is a trapezoid function ranges from 140 to 210.

5.2.1 Surface Viewer

The surface viewer of the OA FLC is plotted against the left, right sensors and the left and the

right velocity. The figure bellows shows the 3 dimensional surface graphs of the Front

sensors, left sensors and the left velocity of the robot. It is clear from the graph that the

increase in the front distance increase the left velocity whereas the with the decrease in the

right velocity the left velocity increases.

Figure 18: Left Sensor, Front Sensor vs. Left Velocity In the surface graph of the left sensor input and the right sensors input against the left

velocity it is clear when the left distance becomes low its increases the left velocity and when

the right distance increase its result in increase of the left velocity.

Figure 17: OA Output Fuzzy Sets

Page 23: Fuzzy Logic Hybrid System

Figure 19: Left Sensor, Right Sensor vs. Left Velocity

In the surface graph of the right sensor input and the front sensors input against the left

velocity it is clear when the right distance becomes high the left velocity increases rapidly

and when the right distance increase its result in small increase of the left velocity.

Figure 20: Right Sensor, Front Sensor vs. Left Velocity

In the surface graph of the right sensors input and the front sensors input against the right

velocity it is clear when the front distance, increases the left velocity and when the right

distance decreases its result in increase of the left velocity. When the right distance is low and

the right distance is high the right velocity becomes high.

Page 24: Fuzzy Logic Hybrid System

Figure 21: Right Sensor, Front Sensor vs. Right Velocity

Similarly the graph for all the other possible inputs and outputs pattern can be generated

using the Matlab Fuzzy tool box.

5.3 Higher Fuzzy Level Controller

To implement the higher fuzzy level controller three inputs are used. The first input take the

minimum of the two front sensors (laserRange[8], laserRange[10]).The second and third

input takes the minimum of two left sensors (laserRange[14], laserRange[17]) and right

sensors (laserRange[3], laserRange[0]) respectively. The crisp input X1 to the obstacle

avoidance behaviour state is the minimum value of the front laser sensors (laserRange [8],

laserRange [10]). The obstacle avoidance behaviour should be active when the robot path is

obstructed by an obstacle and the closer the robot gets to the obstacle, the higher will be the

activation of the obstacle avoidance behaviour. X1 is fuzzified using the fuzzy membership

functions of to a membership value. The crisp input X2 to the left edge following behaviour

context is the minimum value of the left side laser sensors (laserRange [17], laserRange [14]).

The crisp input X3 to the right edge following behaviour context is the minimum value of the

right side laser sensors (laserRange [0], laserRange [4]) . After all the crisp inputs are

matched and fuzzified against their fuzzy inputs, the fuzzified values are then fed to the

inference engine which determines which rules are fired from the coordination rule base. The

coordination rule base contains a coordination rule for each behaviour.

All three behaviours have three coordination rules as follows:

Page 25: Fuzzy Logic Hybrid System

IF X1 is LOW THEN Obstacle Avoidance,

IF X2 is LOW THEN Left Edge Following,

IF X3 is LOW THEN Right Edge Following.

5.4 MobileSim Output Map

The Figure below show the track that the robot flow using the higher fuzzy level controller

that include the left wall following, left wall following and the obstacle avoidance behaviour.

Figure 22 : MobileSim Map

6 Improvement

There are several easy improvements that could be made to future iterations of this project in

order to improve the robot's performance. The most affected would be to use of larger range

of the IR sensors to improve the performance of the robot. This can be implemented by

taking the minimum of the sensors value. Another approach would be that, defining more

membership functions could help improve the rule base by creating more fine-tuned

responses. However, this would again increase the complexity of the system. Thus, this

project has successfully implemented a simple fuzzy control scheme for left, right and

obstacle avoidance of a mobile robot.

Page 26: Fuzzy Logic Hybrid System

7 Conclusion

The fuzzy logic system implemented allowed the robot to quickly respond to obstacles it

could detect in its environment. This allowed it to follow walls and bend around corners

decently without hitting any obstacles. So the challenged task that one of the Pioneer

mobile robots is deployed in an unstructured environment and it is supposed to follow

the right and left wall with avoiding the obstacles in the path. Through this assignment

we were able to understand and implement the fuzzy level control system on the mobile

robot. It is obvious that the mobile robot’s autonomous navigation is going to take the

mobile robotics to a new dimension and will also play a more and more important role in

exploration and inspection tasks.

Page 27: Fuzzy Logic Hybrid System

8 References

[1] Fuzzy Logic a Practical Approach, Morgan Kaufmann Pub, 1994.

[2] Fuzzy Logic with Engineering Applications, 2nd ed., Wiley, 2004.

[3] J. Mendel. Fuzzy logic systems for engineering: a tutorial. Proceedings of the IEEE, 83(3):345 - 377, Mar 1995.

[4] Hagras, Hani A. et al. “A Fuzzy Based Hierarchical Coordination and Control System for a Robotic Agent Team in the Robot Hockey Competition”, IEEE International Conference on Fuzzy Systems (FUZZ), 2010

[5] Nabeel K. Abid Al- Sahib, Ahmed Rahman Jasim, “Guiding Mobile Robot by Applying Fuzzy Approach on Sonar Sensors”, Vol. 6, No. 3, pp 36 - 44 , 2010, Al-Khwarizmi Engineering Journal,

Page 28: Fuzzy Logic Hybrid System

Appendix Code:

#include <Aria.h> #include <stdio.h> #include <iostream> #include <conio.h> using namespace std; void lwf(double x1, double x2); void rwf(double x1, double x2); void oba(double x1, double x2,double x3); void hlfc(double x1, double x2, double x3); double tpzmf(double val, double a, double b, double c, double d); // GLOBAL double laserRange[18]; double laserAngle[18]; double leftVel=0; double rightVel=0; double loutput1 =0; double loutput2 =0; double routput1=0; double routput2=0; double ooutput1=0; double ooutput2=0; double houtput1=0; double houtput2=0; // Main Function int main(int argc, char **argv) { // create instances Aria::init(); ArRobot robot; ArPose pose; // parse command line arguments

Page 29: Fuzzy Logic Hybrid System

ArArgumentParser argParser(&argc, argv); argParser.loadDefaultArguments(); argParser.addDefaultArgument("-connectLaser"); // connect to Sensor ArSensorReading *sonarSensor[8]; // Connect to Robot ArRobotConnector robotConnector(&argParser, &robot); if (robotConnector.connectRobot()) std::cout<<"Robot connected!"<<std::endl; robot.runAsync(false); robot.lock(); robot.enableMotors(); robot.unlock(); // connect to LASER ArLaserConnector laserConnector(&argParser, &robot, &robotConnector); if (laserConnector.connectLasers()) std::cout<<"Laser connected!"<<std::endl; ArLaser *laser = robot.findLaser(1); while (true) { // Read from Laser for (int i = 0; i < 18; i++) { laserRange[i] = laser->currentReadingPolar(10*i-90,10*(i+1)-90, &laserAngle[i]); } laser->unlockDevice(); double a1 = min(laserRange[10],laserRange[8]); double a2 = min(laserRange[14],laserRange[17]); double a3 = min(laserRange[3],laserRange[0]); // Higher Fuzzy Level Controller hlfc(a1,a2,a3); leftVel= houtput1; rightVel= houtput2; robot.lock(); if (robotConnector.getRemoteIsSim()) robot.setVel2(rightVel, leftVel); else robot.setVel2(leftVel, rightVel); robot.unlock(); ArUtil::sleep(100);

Page 30: Fuzzy Logic Hybrid System

} // termination // stop the robot robot.lock(); robot.stop(); robot.unlock(); // terminate all threads and exit Aria::exit(); return 0; } // Left Wall Following void lwf(double x1, double x2) { float mf1 = 0; float mf2 = 0; float lf1 =0; float lf2 =0; float lf3 =0; float lf4 =0; float lf5 =0; float lf6 =0; float lf7 =0; float lf8 =0; float lf9 =0; int dislowx1=0; int dismedx1=0; int dishighx1=0; int dislowx2=0; int dismedx2=0; int dishighx2=0; double la = 0; double lb = 0; double lc = 450; double ld = 550; double ca = 450; double cb = 550; double cc = 550; double cd = 750; double ra = 550;

Page 31: Fuzzy Logic Hybrid System

double rb = 750; double rc = 1000; double rd = 1000; double cel = 35; double cem = 75; double ceh = 150; /* Test for set membership for left first sensor parameter */ if(x1<ld) dislowx1=1; if(x1>ld) dishighx1 =1; if(x1 > lb && x1 < ld) dismedx1=1; /* Test for set membership for left second sensor parameter */ if(x2<ld) dislowx2=1; if(x2>ld) dishighx2 =1; if(x2 > lb && x2 < ld) dismedx2=1; //Rule Base /* If x1 is low and x2 is low */ if (dislowx1 ==1 && dislowx2==1) { mf1 = tpzmf(x1, la,lb,lc,ld); mf2 = tpzmf(x2,la,lb,lc,ld); lf1 = min(mf1,mf2); } /* If x1 is low and x2 is medium */ if (dislowx1 ==1 && dismedx2==1) { mf1 = tpzmf(x1, la,lb,lc,ld); mf2 = tpzmf(x2, ca,cb,cc,cd); lf2 = min(mf1,mf2); } /* If x1 is low and x2 is High */

Page 32: Fuzzy Logic Hybrid System

if (dislowx1 ==1 && dishighx2==1) { mf1 = tpzmf(x1, la,lb,lc,ld); mf2 = tpzmf(x2, ra,rb,rc,rd); lf3 = min(mf1,mf2); } /* If x1 is medium and x2 is low */ if (dismedx1 ==1 && dislowx2==1) { mf1 = tpzmf(x1, ca,cb,cc,cd); mf2 = tpzmf(x2, la,lb,lc,ld); lf4 = min(mf1,mf2); } /* If x1 is medium and x2 is medium */ if (dismedx1 ==1 && dismedx2==1) { mf1 = tpzmf(x1, ca,cb,cc,cd); mf2 = tpzmf(x2, ca,cb,cc,cd); lf5 = min(mf1,mf2); } /* If x1 is medium and x2 is high */ if (dismedx1 ==1 && dishighx2==1) { mf1 = tpzmf(x1, ca,cb,cc,cd); mf2 = tpzmf(x2, ra,rb,rc,rd); lf6 = min(mf1,mf2); } /* If x1 is High and x2 is low */ if (dishighx1 ==1 && dislowx2==1) { mf1 = tpzmf(x1, ra,rb,rc,rd); mf2 = tpzmf(x2, la,lb,lc,ld); lf7 = min(mf1,mf2); }

Page 33: Fuzzy Logic Hybrid System

/* If x1 is High and x2 is Medium */ if (dishighx1 ==1 && dismedx2==1) { mf1 = tpzmf(x1, ra,rb,rc,rd); mf2 = tpzmf(x2, ca,cb,cc,cd); lf8 = min(mf1,mf2); } /* If x1 is High and x2 is High */ if (dishighx1 ==1 && dishighx2==1) { mf1 = tpzmf(x1, ra,rb,rc,rd); mf2 = tpzmf(x2, ra,rb,rc,rd); lf9 = min(mf1,mf2); } /* Defuzzification */ loutput1 = (lf1*ceh+lf2*ceh+lf3*ceh+lf4*cel+lf5*cem+lf6*ceh+lf7*cel+lf8*cel+lf9*ceh)/(lf1+lf2+lf3+lf4+lf5+lf6+lf7+lf8+lf9); loutput2 = (lf1*cel+lf2*cel+lf3*cel+lf4*ceh+lf5*cem+lf6*cel+lf7*ceh+lf8*ceh+lf9*ceh)/(lf1+lf2+lf3+lf4+lf5+lf6+lf7+lf8+lf9); } // Right Wall Following Behaviour void rwf(double x1, double x2) { float mf1 = 0; float mf2 =0; float rf1 =0; float rf2 =0; float rf3 =0; float rf4 =0; float rf5 =0; float rf6 =0; float rf7 =0; float rf8 =0; float rf9 =0; int dislowx1=0; int dismedx1=0; int dishighx1=0;

Page 34: Fuzzy Logic Hybrid System

int dislowx2=0; int dismedx2=0; int dishighx2=0; double la = 0; double lb = 0; double lc = 450; double ld = 550; double ca = 450; double cb = 550; double cc = 550; double cd = 750; double ra = 550; double rb = 750; double rc = 1000; double rd = 1000; double cel = 35; double cem = 75; double ceh = 150; /* Test for set membership for left first sensor parameter */ if(x1<ld) dislowx1=1; if(x1>ld) dishighx1 =1; if(x1 > lb && x1 < ld) dismedx1=1; /* Test for set membership for left second sensor parameter */ if(x2<ld) dislowx2=1; if(x2>ld) dishighx2 =1; if(x2 > lb && x2 < ld) dismedx2=1; //Rule Base /* If x1 is low and x2 is low */ if (dislowx1 ==1 && dislowx2==1) {

Page 35: Fuzzy Logic Hybrid System

mf1 = tpzmf(x1, la,lb,lc,ld); mf2 = tpzmf(x2,la,lb,lc,ld); rf1 = min(mf1,mf2); } /* If x1 is low and x2 is medium */ if (dislowx1 ==1 && dismedx2==1) { mf1 = tpzmf(x1, la,lb,lc,ld); mf2 = tpzmf(x2, ca,cb,cc,cd); rf2 = min(mf1,mf2); } /* If x1 is low and x2 is High */ if (dislowx1 ==1 && dishighx2==1) { mf1 = tpzmf(x1, la,lb,lc,ld); mf2 = tpzmf(x2, ra,rb,rc,rd); rf3 = min(mf1,mf2); } /* If x1 is medium and x2 is low */ if (dismedx1 ==1 && dislowx2==1) { mf1 = tpzmf(x1, ca,cb,cc,cd); mf2 = tpzmf(x2, la,lb,lc,ld); rf4 = min(mf1,mf2); } /* If x1 is medium and x2 is medium */ if (dismedx1 ==1 && dismedx2==1) { mf1 = tpzmf(x1, ca,cb,cc,cd); mf2 = tpzmf(x2, ca,cb,cc,cd); rf5 = min(mf1,mf2); } /*

Page 36: Fuzzy Logic Hybrid System

If x1 is medium and x2 is high */ if (dismedx1 ==1 && dishighx2==1) { mf1 = tpzmf(x1, ca,cb,cc,cd); mf2 = tpzmf(x2, ra,rb,rc,rd); rf6 = min(mf1,mf2); } /* If x1 is High and x2 is low */ if (dishighx1 ==1 && dislowx2==1) { mf1 = tpzmf(x1, ra,rb,rc,rd); mf2 = tpzmf(x2, la,lb,lc,ld); rf7 = min(mf1,mf2); } /* If x1 is High and x2 is Medium */ if (dishighx1 ==1 && dismedx2==1) { mf1 = tpzmf(x1, ra,rb,rc,rd); mf2 = tpzmf(x2, ca,cb,cc,cd); rf8 = min(mf1,mf2); } /* If x1 is High and x2 is High */ if (dishighx1 ==1 && dishighx2==1) { mf1 = tpzmf(x1, ra,rb,rc,rd); mf2 = tpzmf(x2, ra,rb,rc,rd); rf9 = min(mf1,mf2); } /* Defuzzification */ routput1 = (rf1*cel+rf2*cel+rf3*cel+rf4*ceh+rf5*cem+rf6*cel+rf7*ceh+rf8*ceh+rf9*ceh)/(rf1+rf2+rf3+rf4+rf5+rf6+rf7+rf8+rf9); routput2 = (rf1*ceh+rf2*ceh+rf3*ceh+rf4*cel+rf5*cem+rf6*ceh+rf7*cel+rf8*cel+rf9*ceh)/(rf1+rf2+rf3+rf4+rf5+rf6+rf7+rf8+rf9);

Page 37: Fuzzy Logic Hybrid System

} // Obstacle Avoidance Behaviour void oba(double x1, double x2, double x3) { double mf1 = 0; double mf2 =0; double mf3 =0; int obisnearx1=0; int obisfarx1=0; int obisnearx2=0; int obisfarx2=0; int obisnearx3=0; int obisfarx3=0; double na = 0; double nb = 0; double nc = 400; double nd = 800; double fa = 400; double fb = 800; double fc = 1000; double fd = 1000; double cel = 35; double cem = 100; double ceh = 150; float of1 =0; float of2 =0; float of3 =0; float of4 =0; float of5 =0; float of6 =0; float of7 =0; float of8 =0; float of9 =0; /* Test for set membership for left first sensor parameter */ if(x1<nd) obisnearx1=1;

Page 38: Fuzzy Logic Hybrid System

if(x1>nc) obisfarx1 =1; /* Test for set membership for left second sensor parameter */ if(x2<nd) obisnearx2=1; if(x2>nc) obisfarx2 =1; /* Test for set membership for left second sensor parameter */ if(x3<nd) obisnearx3=1; if(x3>nc) obisfarx3 =1; // Rule Base if (obisnearx1 ==1 && obisnearx2 ==1 && obisnearx3 ==1) { mf1 = tpzmf(x1, na,nb,nc,nd); mf2 = tpzmf(x2,na,nb,nc,nd); mf3 = tpzmf(x3,na,nb,nc,nd); of1 = min(mf1,min(mf2,mf3)); } if (obisnearx1 ==1 && obisnearx2 ==1 && obisfarx3 ==1) { mf1 = tpzmf(x1, na,nb,nc,nd); mf2 = tpzmf(x2,na,nb,nc,nd); mf3 = tpzmf(x3,fa,fb,fc,fd); of2 = min(mf1,min(mf2,mf3)); } if (obisnearx1 ==1 && obisfarx2 ==1 && obisnearx3 ==1) { mf1 = tpzmf(x1,na,nb,nc,nd); mf2 = tpzmf(x2,fa,fb,fc,fd); mf3 = tpzmf(x3,na,nb,nc,nd); of3 = min(mf1,min(mf2,mf3)); } if (obisnearx1 ==1 && obisfarx2 ==1 && obisfarx3 ==1) { mf1 = tpzmf(x1, na,nb,nc,nd); mf2 = tpzmf(x2,fa,fb,fc,fd); mf3 = tpzmf(x3,fa,fb,fc,fd); of4 = min(mf1,min(mf2,mf3));

Page 39: Fuzzy Logic Hybrid System

} if (obisfarx1 ==1 && obisnearx2==1 && obisnearx3==1) { mf1 = tpzmf(x1, fa,fb,fc,fd); mf2 = tpzmf(x2,na,nb,nc,nd); mf3 = tpzmf(x3,na,nb,nc,nd); of5 = min(mf1,min(mf2,mf3)); } if (obisfarx1 ==1 && obisnearx2==1 && obisfarx3==1) { mf1 = tpzmf(x1,fa,fb,fc,fd); mf2 = tpzmf(x2,na,nb,nc,nd); mf3 = tpzmf(x3,fa,fb,fc,fd); of6 = min(mf1,min(mf2,mf3)); } if (obisfarx1 ==1 && obisfarx2==1 && obisnearx3==1) { mf1 = tpzmf(x1, fa,fb,fc,fd); mf2 = tpzmf(x2,fa,fb,fc,fd); mf3 = tpzmf(x3,na,nb,nc,nd); of7 = min(mf1,min(mf2,mf3)); } if (obisfarx1 ==1 && obisfarx2==1 && obisfarx3==1) { mf1 = tpzmf(x1, fa,fb,fc,fd); mf2 = tpzmf(x2, fa,fb,fc,fd); mf3 = tpzmf(x3, fa,fb,fc,fd); of8 = min(mf1,min(mf2,mf3)); } /* Defuzzification */ ooutput1= (0*of1+ceh*of2+cem*of3+ceh*of4+cel*of5+cel*of6+cel*of7+ceh*of8)/(of1+of2+of3+of4+of5+of6+of7+of8); ooutput2= (0*of1+cel*of2+cem*of3+cel*of4+ceh*of5+ceh*of6+ceh*of7+ceh*of8)/(of1+of2+of3+of4+of5+of6+of7+of8); } // Higher Fuzzy Level Controller static void hlfc(double x1, double x2, double x3) { float mf1 = 0; float mf2 =0; float mf3 =0;

Page 40: Fuzzy Logic Hybrid System

int doaislow=0; int doaishigh=0; int dlwislow=0; int dlwishigh=0; int drwislow=0; int drwishigh=0; double doala = 0; double doalb = 0; double doalc = 400; double doald = 800; double doaha = 400; double doahb = 800; double doahc = 1000; double doahd = 1000; double dwla = 0; double dwlb = 0; double dwlc = 250; double dwld = 550; double dwha = 250; double dwhb = 550; double dwhc = 1000; double dwhd = 1000; double cel = 35; double cem = 100; double ceh = 150; float f1 =0; float f2 =0; float f3 =0; float f4 =0; float f5 =0; float f6 =0; float f7 =0; float f8 =0; if(x1<doald) doaislow=1; if(x1>doalc) doaishigh=1; if(x2<dwld) dlwislow=1;

Page 41: Fuzzy Logic Hybrid System

if(x2>dwlc) dlwishigh=1; if(x3<dwld) drwislow=1; if(x3>dwlc) drwishigh=1; //Rule Base if (doaislow==1) { oba(x2,x1,x3); f1 = tpzmf(x1, doala,doalb,doalc,doald); } if(dlwislow==1) { lwf(laserRange[14],laserRange[17]); f2 = tpzmf(x2,dwla,dwlb,dwlc,dwld); } if(drwislow==1) { rwf(laserRange[3],laserRange[0] f3 = tpzmf(x3,dwla,dwlb,dwlc,dwld); } // Defuzzification houtput1= (ooutput1*f1+loutput1*f2+routput1*f3)/(f1+f2+f3); houtput2= (ooutput2*f1+loutput2*f2+routput2*f3)/(f1+f2+f3); } // Membership Value Function double tpzmf(double val, double a, double b, double c, double d) { double mf; if(val<a) { mf =0; } else if ((val>a && val<=b)) { mf = val-a/(b-a); } else if ((val >b && val <=c)) { mf =1; }

Page 42: Fuzzy Logic Hybrid System

else if ((val >c && val <=d)) { mf = d-val/(d-c); } else if (val>d) { mf = 0; } return mf; }