Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

FOR LAB

Simulation of Wall follower robot using fuzzy control on mobotsim

Submitted by: Warda tu Zahra

BSEE 17-21

Dated: 15 March 2021


Lab 01: Introduction to Mobotsim:
MobotSim is a Configurable 2D simulator of differential drive mobile robots. It provides a graphical
interface that represents an environment in which you can easily create, set and edit robots and
objects. In order to set these mobots in motion MOBOTSIM has a BASIC Editor in which the user
can write macros .

Fig 1.1: Mobotsim graphical interface

Fig 1.2: mobotsim BASIC editor


Lab 02: Membership functions:
Background:
Membership function (MF) - A function that specifies the degree to which a given input belongs to a set.
 Degree of membership- The output of a membership function, this value is always limited to between
0 and 1. Also known as a membership value or membership grade.

 Membership functions are used in the fuzzification and defuzzification steps of a FLS (fuzzy logic
system), to map the non-fuzzy input values to fuzzy linguistic terms and vice versa.
There are different forms of membership functions such as:
o Triangular.
o Trapezoidal.
o Piecewise linear.
Implementation:
We have defined 5 triangular membership functions for the distance from obstacle as

 Near(N) (s<=0.25)
 Near medium(NM) (0<=s<=0.5)
 Medium(M) (0.25<=s<=0.75)
 Medium Far(MF) (0.5<=s<=1)
 Far(F) (s>=0.75)

We have used triangular membership functions which can be represented as:


Fig 2.1: distance membership functions

membership functions are defined for dS (change in distance) which are given as:

 ds0 (ds<=-0.2)
 ds1 (-0.2<=ds<=0)
 ds2 (-0.1=ds<=0.1)
 ds3 (0<=ds<=0.2)
 ds4 (ds>=0.2)

Fig 2.1: dS membership functions


Lab 03: Rule base
Background:
The fuzzy controller has four main components:

(1) The “rule-base” holds the knowledge, in the form of a set of rules, of how best to control the
system.
(2) The inference mechanism evaluates which control rules are relevant at the current time and
then decides what the input to the plant should be
(3) The fuzzification interface simply modifies the inputs so that they can be interpreted and
compared to the rules in the rule-base.
(4) the defuzzification interface converts the conclusions reached by the inference mechanism into
the inputs to the plant.

Implementation:
We specify a set of rules (a rule-base) that captures the expert’s knowledge about how to control the
plant.

We can write rule base in linguistic terms as:

 If distance(S) is near(N) and dS is ds (0), speed of left wheel is 100


 If distance(S) is near(N) and dS is ds (0), speed of right wheel is 0

Other rules are also defined which are listed in following table

For left wheel


wl(0,0)=100 wl(1,0)=80 wl(2,0)=50 wl(3,0)=50 wl(4,0)=50
wl(0,1)=80 wl(1,1)=80 wl(2,1)=50 wl(3,1)=50 wl(4,1)=40
wl(0,2)=60 wl(1,2)=50 wl(2,2)=40 wl(3,2)=30 wl(4,2)=30
wl(0,3)=60 wl(1,3)=45 wl(2,3)=40 wl(3,3)=20 wl(4,3)=10
wl(0,4)=60 wl(1,4)=45 wl(2,4)=40 wl(3,4)=20 wl(4,4)=0

For right wheel


wr(0,0)=0 wr(1,0)=5 wr(2,0)=50 wr(3,0)=50 wr(4,0)=50
wr(0,1)=5 wr(1,1)=10 wr(2,1)=50 wr(3,1)=50 wr(4,1)=60
wr(0,2)=10 wr(1,2)=50 wr(2,2)=50 wr(3,2)=70 wr(4,2)=60
wr(0,3)=10 wr(1,3)=55 wr(2,3)=60 wr(3,3)=80 wr(4,3)=70
wr(0,4)=20 wr(1,4)=55 wr(2,4)=60 wr(3,4)=80 wr(4,4)=100
Lab 04: Fuzzy control and final code
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. 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.

In case of our wall follower robot, two control parameters are

 Left wheel velocity(wL) and


 Right wheel velocity (wR).

Robot needs to be maintained at a distance of 0.5m from the left wall. Based on the fuzzy logic,
these requirements are met in simulations by defining the rulebases and incorporating them in
Mobotsim in the form of membership functions. These membership functions include the data
obtained from the sensors that are used in our design i.e. SL, ΔSL.

s=minvalue(s7,s8,s9,s10)

ds=s-z

Code
“membership functions” “rule base” “main”

Function f1(s,b,c) Dim wl(4,4) Sub Main


If s>b And s<c Then wl(0,0)=100 SetMobotPosition(0,5,2,90)
f1=(-c+s)/(b-c) wl(0,1)=80 ds=0
ElseIf s<b Then wl(0,2)=60 z=0
f1=1 wl(0,3)=60 For t=0 To 45
Elsef1=0 wl(0,4)=60 s7=MeasureRange(0,7,0)
End If wl(1,0)=80 s8=MeasureRange(0,8,0)
End Function wl(1,1)=80 s9=MeasureRange(0,9,0)
Function f2(s,a,b,c) wl(1,2)=50 s10=MeasureRange(0,10,0)
If s>a And s<c Then wl(1,3)=45 s=minvalue(s7,s8,s9,s10)
u=1 wl(1,4)=45 ds=s-z
Elseu=0 wl(2,0)=50 Dim mfs(4)
End If wl(2,1)=50 mfs(0)=f1(s,0,0.25)
If s>a And s<=b Then wl(2,2)=40 mfs(1)=f2(s,0,0.25,0.5)
f2=(s-a)/(b-a)*u wl(2,3)=40 mfs(2)=f2(s,0.25,0.5,0.75)
ElseIf s>b And s<c wl(2,4)=40 mfs(3)=f2(s,0.5,0.75,1)
Then wl(3,0)=50 mfs(4)=f3(s,0.75,1)
f2=(1+((s-b)/(b- wl(3,1)=50 Dim mfds(4)
c)))*u wl(3,2)=30 mfds(0)=f1(ds,-0.2,-0.1)
Elsef2=0 wl(3,3)=20 mfds(1)=f2(ds,-0.2,-0.1,0)
End If wl(3,4)=20 mfds(2)=f2(ds,-0.1,0,0.1)
End Function wl(4,0)=50 mfds(3)=f2(ds,0,0.1,0.2)
Function f3(s,a,b) wl(4,1)=40 mfds(4)=f3(ds,0.1,0.2)
If s>a And s<b Then wl(4,2)=30 ''''premise calculation''''
f3=(s-a)/(b-a) wl(4,3)=10 y1=0
ElseIf s>b Then wl(4,4)=0 deno1=0
f3=1 For i=0 To 4
Elsef3=0 Dim wr(4,4) For j=0 To 4
End If wr(0,0)=0 premise=minfn(mfs(i),mfds(j))
End Function wr(0,1)=5 velocity=premise*wl(i,j)
wr(0,2)=10 deno1=deno1+premise
Function minvalue(m,n,o,p) wr(0,3)=10 Debug.Print(deno1)
If m<n And m<o And wr(0,4)=20 y1=y1+velocity
m<p Then wr(1,0)=5 Next
minvalue=m wr(1,1)=10 Next
ElseIf n<m And n<o wr(1,2)=50 Debug.Print(deno1)
And n<p Then wr(1,3)=55 Debug.Print(y1)
minvalue=n wr(1,4)=55 wleft=y1/deno1
ElseIf o<m And o<n wr(2,0)=50 y2=0
And o<p Then wr(2,1)=50 deno2=0
minvalue=o wr(2,2)=50 For i=0 To 4
ElseIf p<m And p<n wr(2,3)=60 For j=0 To 4
And p<o Then wr(2,4)=60 premise=minfn(mfs(i),mfds(j))
minvalue=p wr(3,0)=50 velocity=premise*wr(i,j)
End If wr(3,1)=50 deno2=deno2+premise
End Function wr(3,2)=70 Debug.Print(deno2)
Function minfn(e,f) wr(3,3)=80 y2=y2+velocity
If e<f Then wr(3,4)=80 Next
minfn=e wr(4,0)=50 Next
ElseIf f<e Then wr(4,1)=60 Debug.Print(deno2)
minfn=f wr(4,2)=60 Debug.Print(y2)
Elseminfn=e wr(4,3)=70 wright=y2/deno2
End If wr(4,4)=100 SetWheelSpeed(0,wleft,wright)
End Function StepForward
z=s
Next
End Sub
Fig 4.1: output

Discussion:
Left wall follower robot is designed using fuzzy control logic. Rule base is defined and then membership
functions are used to fuzzify and defuzzify the output. The whole code is then simulated in mobotsim.
Ideally, the robot should move in a straight line but it gets tilted as velocities of wheels are decided
manually.

You might also like