line following robot matlab
program LINE FOLLOWING
white = 0, black = 0
CALIBRATE()
midpoint = ( white - black ) / 2 + black
kp = 1, ki = 1, kd = 1
lasterror=0
repeat
value = Read Light Sensor
error = midpoint - value
integral = error + integral
derivative = error - lasterror
correction = kp * error + ki * integral + kd * derivative
Turn B+C Motors by correction
lasterror = error
done repeat
done program