0

Soccer Robot C - Basic lessons - Exercises - Bounce off the lines

Another exercise for Robocup Junior Soccer.

Task: bounce the robot off any white line.

Start the robot in heading -15°. When it detects a white stripe, it has to change the direction by 180°. The purpose is not to allow it to cross playfield boundaries. Base Your program on previous exercise:

void RobotSoccer::loop() {
	static int initialDirection;
	if (setup())
		initialDirection = heading();

	int error = heading() - initialDirection;
	go(50, 137, error);

	bool any = false;
	for (int sensor = 0; sensor < 4 && !any; sensor++)
		for (int transistor = 0; transistor < 8 && !any; transistor++)
			if (line(transistor, sensor) && (sensor != 0 || transistor < 6))
				any = true;

	if (any) 
		end();
}