Line Robot - Basic lessons - Exercises - Follow and catch
A combination of a few previous lessons.
Task: follow a wall and catch a ball.
Put a ball about 10-15 cm from the wall. Let the robot follow the wall with arm in catch-ready position. As soon as the ball enters space between jaws, catch and lift it. End the program. Use wall-following example:
void RobotLine::loop() {
if (rightFront() > 100)
go(80, 20);
else
go(20, 80);
}
Solution
void RobotLine::loop() {
if (setup())
armCatchReady();
if (rightFront() > 100)
go(80, 20);
else
go(20, 80);
if (analogRead(35) < 600){
armCatch();
delayMs(500);
armPutReady();
delayMs(500);
end();
}
}
- In the first run, open jaws ("armCatchReady()").
- Continue following right wall (second "if").
- Third "if" detects if barrier found a ball.
- If so, catch and lift the ball. Allow some time (500 ms) between servo movements to give it enough time to reach new target positions. End the program.