Pages

Monday, January 18, 2010

Fuzzy Line Follower Robot

As a continuation article to Auto Car 04 - Input Infra Red 02 and Fuzzy Controller is Artificial Human Controller I would like to explain about the application of fuzzy logic to line following robot.

Before going further, I would like to say something about fuzzy logic. According to Zadeh, the creator of fuzzy logic, we no need some value that is too exact. In the line following term, the definition of exact is at the voltage level of the infra red sensors.

From the previous article one Input Infra Red, the digital value is gotten from the comparator. What is the analog value oscillates around the compared voltage value? The digital signal comes out will oscillates around 0's and 1's. This is highly unacceptable and will yield wrong movement to the robots.

One of the solution is to have fuzzy logic embedded into the system of data input. Analog value from the infra red sensor will be our universe of discourse (means the analog input to the fuzzy system).



Analog value will be fuzzified into degree of truth. For example the analog value will have 0 to 5 volts, if the value is 3, it will be 40% low and 60% high.

Fuzzified inputs will go through truth table like everyone did in normal line follower. Which takes the example below:

0001 - Turn hard right
0011 - Turn right
0010 - Turn little right
0110 - Go straight
0100 - Turn little left
1100 - Turn left
1000 - Turn hard left.
Etc.

Each of the conclusion (meanings turn hard right, turn right, etc) will go through the minimum function of all the truth of the input. For example, for straight conclusion will go through Minimum (Truth of first infra red being low, Truth of second infra red being high, Truth of third infra red being high, Truth of fourth infra red being low).

If the line is really at the middle, then all the truth will be quite high, therefore, the truth of Straight will be high. An example:

The line is at the middle:
(Infra red numbering from left to right)

Infra red input 1 voltage: 1.1
Infra red input 2 voltage: 4.5
Infra red input 3 voltage: 4.2
Infra red input 4 voltage: 0.8

Truth of infra red 1 being low: 1Low = 1 - ( 1.1/5 ) = 0.78
Truth of infra red 1 being high: 1High = 1.1/5 = 0.22
Truth of infra red 2 being low: 2Low = 1 - (4.5/5) = 0.1
Truth of infra red 2 being high: 2High = 4.5/5 = 0.9
Truth of infra red 3 being low: 3Low = 1 - (4.2/5) = 0.16
Truth of infra red 3 being high: 3High = 4.2/5 = 0.84
Truth of infra red 4 being low: 4Low= 1 - (0.8/5) = 0.84
Truth of infra red 4 being high: 4High = 0.8/5 = 0.16

Truth of Turn Hard Right (0001) = Minimum (1Low, 2Low, 3Low, 4High) = 0.1
Truth of Turn Right (0011) = Minimum (1Low, 2Low, 3High, 4High) = 0.1
Truth of Turn Little Right (0010) = Minimum (1Low, 2Low, 3High, 4Low) = 0.1
Truth of Straight (0110) = Minimum (1Low, 2High, 3High, 4Low) = 0.78
Truth of Turn Little Left (0100) = Minimum (1Low, 2High, 3Low, 4Low) = 0.16
Truth of Turn Left (1100) = Minimum (1High, 2High, 3Low, 4Low) = 0.16
Truth of Turn Hard Left (1000) = Minimum (1High, 2Low, 3Low, 4Low) = 0.1

After getting the conclusion from each output, we will use defuzification to determine the current position. Usually we will use centroid defuzzification. We will assign each truth to have a weight:

Turn Hard Right = 3
Turn Right = 2
Turn Little Right = 1
Go Straight = 0
Turn Little Left = -1
Turn Left = -2
Turn Hard Left = -3

Current Line Position
= (0.1 * 3 + 0.1 * 2 + 0.1 * 1 + 0.78 * 0 + 0.16 * -1 + 0.16 * -2 + 0.1 * -3) /
(0.1 + 0.1 + 0.1 + 0.78 + 0.16 + 0.16 + 0.1)

= -0.12 (Negative means left)
(Which sounds logical because the value of infra red voltage is biased to the left.)

The best part is, if there is a voltage surge in other non-line-positioned infra red, your can define it as noise. For example if the line is at the left, the logic should be 1100, but there is noise at the right most infra red, making the truth of 1101 very high. This can be defined as noise.

Of course this is not the exact way to define a fuzzy logic mathematics and sets but this is only an example of fuzzy logic and the implementation in line following.

Now comes the disadvantage part. The number of infra red inputs makes the calculation time increases exponentially. Let N be the number of infra red, then the calculation time might be 2^N. The more logic there is, the more time is needed.

All in all, this is just another method for line following. Of course you might have PID and Digital Logic and those fancy stuff, it is the effect that counts.

2 comments:

ROBINSON SATHIYASEELAN said...

thank you very much for your article.
Because of you I have done a good presentation on fuzzy logic line follower in my university ( Uva wellassa University of Sri Lanka).

Khin Hooi Ng said...

you are welcome