Line Robot - Basic lessons - Exercises - Stop in front of obstacle on line
This is another task that will help us to develop a program for RCJ Rescue Line.
Task: follow line and stop in front of an obstacle.
Put an obstacle on a black stripe glued on top of a white surface. Program the robot to follow the line and stop in front of the obstacle. As a template, You can use the previous program for line-following with 2 transistors:
void RobotLine::loop() {
if (line(5))
go(10, 80);
else if (line(3))
go(80, 10);
else
go(60, 60);
}
Solution
void RobotLine::loop() {
if (line(5))
go(10, 80);
else if (line(3))
go(80, 10);
else
go(60, 60);
if (frontLeft() < 60)
end();
}
When the obstacle is less than 60 mm ahead, the program will end, automatically stopping the motors.