Soccer Robot C - Basic lessons - Exercises - Approach ball
Part of the strategy to catch a ball in Robocup Junior Soccer.
Task: approach RCJ ball.
Put a RCJ ball at about 1 m in front of the robot and let it catch the ball. Base Your program on previous code:
void RobotSoccer::loop() {
static int initialDirection;
if (setup())
initialDirection = heading();
int error = heading() - initialDirection;
go(40, 0, error);
}
Solution
void RobotSoccer::loop() {
static int initialDirection;
if (setup())
initialDirection = heading();
int rotationalError = heading() - initialDirection;
int directionalError = -ballAngle();
go(40, directionalError, rotationalError);
if (analogRead(35) < 400)
end();
}
2 errors are calculated: "rotationalError", as before, and "directionalError", a deviation from ball's direction. The latter value determines robot's direction. When barrier is interrupted, the robot will stop.
Notice that this is not the best strategy. If the ball is not ahead, but more sideways, the robot will not approach the ball from behind. This is more a simple basis for You to develop Your strategy.