as line sensors we use the Light Sensor Array and a normal Lego Light Sensor.
first, the robot calculates the position of the line:
int error = 350 - (sensor[0] + sensor[1]*100 + sensor[2]*200 ... ) / (sensor[0] + sensor[1] + sensor[2] ... );note: that the values are reversed, so black is 100 and white is 0
then, it does the error * Kp and runs the motors with that.
when the line is not directly under the line sensor array the error is -350, in this case, we look at what happend before the robot lost the line to determine if the line was lost or if ther is a gap