This robot uses the HiTecnic gyro sensor to balance on two wheels ( http://www.hitechnic.com/ ) and the Lego optical sensor to follow the edge of the line.
A simple proportional controller is used for the line following - the measured reflected light intensity is compared to a target value. If the reflected light is brighter than the target, the sensor is too far into the white tape and a right turn is commanded. If the reflected light is too low a left turn is commanded. The rate at which it turns is proportional to the difference between the target and measured values.
Similarly, if the gyro sensor detects that the robot is falling forward, it commands the wheels to accelerate - or decelerate if it is falling backwards.