0

Line Robot - Basic lessons - Line following with 2 transistors

Line following can be quite easy, but also very difficult. We will start from the simple side, using a straight line and only 2 transistors. Check Your MRMS reflectance sensors 9x, CAN, analog, I2C (mrm-ref-can). There are small numbers printed next to transistors. If, looking from the back of the the robot towards the front, the transistor 5 is left to 3, the next program will be good for Your case. If not (the sensor is rotated 180°), swap arguments (numbers in parantheses) of the function "line" (5 and 3). "line(5)" will become "line(3)" and "line(3)" "line(5)".
void RobotLine::loop() {
	if (line(5))
		go(10, 80);
	else if (line(3))
		go(80, 10);
	else
		go(60, 60);
}
The first "if" checks if the line is below transistor 3 (the left one). If so, the robot must turn left because the line is on the left and we want to have it right in the centre. To turn left, the right motors must spin faster than the left ones, and that is just what the command "go(30, 50);" does. Likewise, if the sensor is not under 3, the transistor 4 (the right one) is checked. If the surface is black here, the line is too much to the right and we have to turn right. That is what "go(50, 30);" does.

Task: curves.

Try a new layout: a stripe that is not straight, but has some mild curves and one sharper bend. Change the program above so that it follows the new line.