Line Robot - Basic lessons - Exercises - Avoid walls
This exercise will also be handy for RCJ Rescue Line.
Task: avoid walls.
Start with the program used to follow right wall, from the previous lesson. Upgrade it in the way that it doesn't hit walls in front of it. The last program is here:
void RobotLine::loop(){
if (rightFront() > 100)
go(80, 20);
else
go(20, 80);
}
Solution
void RobotLine::loop() {
if (frontLeft() < 90)
go(-50, 50);
else{
if (rightFront() > 100)
go(80, 20);
else
go(20, 80);
}
}
First priority is a possible wall ahead so it will be the subject of the first "if". When found, rotate in place, until it disappears. Only then we can go on with next "if" and restart wall-following.