[Home]ReallyReallySimpleWallSmoothing

Robo Home | Changes | Preferences | AllPages

"Really, really simple wall smoothing" is my method of WallSmoothing that emerged completely by accident. I wanted to build a standard PerpendicularMovement bot. I built in a simple trig-based, sort-of-works wall avoidance algorithm - and suddenly, I discovered that my rate of hitting walls had cut by about four-fifths. Basically, since it tries to only move forward if there isn't a wall in the way, and you are curving around the enemy, if the enemy is in the center of the field you will move around him forever while asymptotically never quite hitting the walls. My rough version of this is:

public void onScannedRobot(ScannedRobotEvent e) {
	setTurnRight(Util.normalRelativeAngle(e.getBearing() + 90));
			
	double x = getX();
	double y = getY();
	
	double angleUR = Math.atan(y / (getBattleFieldWidth() - x));
	double angleLR = Math.atan((getBattleFieldHeight() - y) / (getBattleFieldWidth() - x));
	double angleLL = Math.atan((getBattleFieldHeight() - y) / x);
	double angleUL = Math.atan(y / x);
	double heading = getHeading();
	
	double axis;
	if ((heading > angleUL && heading <= angleUR) || (heading > angleLR && heading <= angleLL)) {
		axis = y;
	} else {
		axis = x;
	}
	double aheadDistanceToWall = (axis / Math.cos(heading)) - 36;
	double backDistanceToWall = (axis / Math.cos(Util.normalAbsoluteAngle(heading - 180))) - 36;
	if (aheadDistanceToWall > 100) {
		setAhead(100 - 18);
	} else if (backDistanceToWall > 100) {
		setBack(100 - 18);
	}
}

--AaronR


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited February 2, 2007 5:46 EST by AaronR (diff)
Search: