Line Robot - Basic lessons - Exercises - Around obstacle
Another task from RCJ Rescue Line competition.
Task: go around an obstacle on line.
Put an obstacle on line and program Your robot to go around it. After finding the black line behind the obstacle, and stepping on it, stop the robot. Use the program we made before, which stops the robot in front of an obstacle on line:
void RobotLine::loop() {
if (line(5))
go(10, 80);
else if (line(3))
go(80, 10);
else
go(60, 60);
if (frontLeft() < 60)
end();
}
Solution
void RobotLine::loop() {
if (line(5))
go(10, 80);
else if (line(3))
go(80, 10);
else
go(60, 60);
if (frontLeft() < 60){
go(-100, 100);
delayMs(500);
go(60, 40);
while(!line(8))
delayMs(1);
end();
}
}
We changed the second "if". Instead of quitting the program after encountering an obstacle, the robot first rotates in place for 500 ms and starts moving in a circular path around the obstacle. "while" checks if the line is found. When it is, program will end. Change the parameters as the ones in program are just an example.