0

Line Robot - Basic lessons - Exercises - Avoid exit improved

This exercise can be used to avoid room exit in RCJ Rescue Line's evacuation area.

Task: avoid exiting a room.

Let the robot enter evacuation area built according to RCJ Rescue Line rules. Follow right wall but do not allow the robot to exit. Base Your code on the example we already made for this purpose, but notice that it was not perfect. If the robot follows the wall shortly, it will not have enough time to align to wall properly. If it is going too much leftwards (inside the room), it will usually not be a problem since it will detect the wall after the exit at a longer distance, the situation it can overcome. However, if it is going too much righward (toward the wall), it will partially exit the room, probably hitting door frame. This is the problem You have to solve. The former code:

void RobotLine::loop() {
	if (frontLeft() < 90) // Wall ahead?
		go(-50, 50);
	else{
		if (rightFront() > 400) // Exit?
			go(50, 50);
		else{
			int error = (rightFront() - 100) * 0.5;
			error = constrain(error, -50, 50);
			go(50 + error, 50 - error);
		}
	}
}