# PID Controller for line following robot

I had this idea of using the PID Controller as the algorithm of the line following mechanism for my Robot. The problem (which is a nature behavior of the PID controller ) on the line gaps ( where there are no line e.g. 10 cm) the robot doesn't go straight forward but turns right . I thought about it a lot , and i couldn't find any better idea for modifying this algorithm to work in this situation but, adding two more sensors and specify the (white area on the 3 sensors ) as a special situation where the robot should go straight forward .

Now my question is is there any better idea , that i can use ?

• You need to put intelligent cases. I was using weight based PID algorithm so if there's no sensing of the line from any of the sensors, I would just have a weight of 0 from each sensor, making the robot go straight at the base speed. I have implemented the same on my line follower. Have a look at it here – Kartik Madhira Mar 28 '17 at 0:56

Using PID control in Line Follower of course require you to define the Error value for every condition of sensors, treat empty line just like straight line: which is 0 error. You should provide more info about your sensor setup, though it is better to have many sensors aligned in the front of the robot.

following is simple illustration example of the error look-up table based on sensors reading if you have 8 sensors, bit 1 represents reading of black Line:

sensor   : error
11000000 :-3
01100000 :-2
00110000 :-1
00011000 : 0
00000000 : 0 # line gap
00001100 :+1
00000110 :+2
00000011 :+3


with 0 error, PID calculation should result in straight forward move

There are a lot of methods if your just search this forum of just google it.... For example, please see a similar problem (recapturing when there is a large gap in lines for line tracking) implementing PID algorithm in line following robot