[Home]BlackPearl/Questions

Robo Home | BlackPearl | Changes | Preferences | AllPages

Difference (from prior major revision) (no other diffs)

Changed: 27c27,29
-- PEZ
-- PEZ

I thought it would be something silly like that. I shall give it a try and let you know. Getting stronger all the time. -- jim

Can some one explain this to me. I came across this snippet of code and did not know what it does. I spoke to nano who told me that it limits the angle to +/-90 degrees. I thought this was excellent. It solves one of BlackPearl's problems (it some times circles off the wall). When I installed it though it has a side effect of slowly closing the distance to my enemy which is not the desired result. As I do not completely understand whats happening I can not correct it. Can some one clue me in here? Here is the relevant code:
{...
setTurnRightRadians(Math.atan(Math.tan(getTurnAngle())));
...}

private double getTurnAngle() {
   return (eBearing + (Math.PI / 2) + (.2618 * direction * ((eDistance > MAX_STAND_OFF_DISTANCE || wallDist(getX(), getY()) < 20 || cornered()) ?            CLOSE_IN : (eDistance < MIN_STAND_OFF_DISTANCE ? BACK_OFF : 0))));
}
I have tried several different ways to correct it but I have had no luck. It almost seems as if my direction is off by 180 for some reason. -- jim

The atan/tan method is rather crude... I suggest using the built in one robocode.util.Utils.normalRelativeAngle(angle) (in radians). Did you copy across all the constants the same, because they may not work correctly with the rest of your code. -- Tango

I have copied across all everything just as it appears in the code (minus all the commented out attempts). I have used the built in one but I still circle off the walls sometimes and it is very frustrating. Very predictable too. The method here seems to alleviate that. At least I know the intent of the snippet is equivelant to normalizing the angle. -- jim

The difference is that it normalizes the angle to -90 to 90 space, doesn't it? -- PEZ

normalRelativeAngle is -180 to 180, the atan(tan()) method is -90 to 90. The problem is likely that you aren't accounting for the direction change that is sometimes needed here. Example: You need to turn 92 degrees, plug this code in, and get that -88 degrees is a faster turn. The difference? Turning -88 puts you facing in the opposite direction as +92 does, though the movement axis of the bot is along the same line. So when you actually do this normalization you need to change direction if it affects the angle. Try something like the BackAsFront functionality in the GotoBot? snippets. -- Kuuran

Yeah, here's the relevant part of it:

	double turnAngle = Math.atan(Math.tan(angle));
        setTurnRightRadians(turnAngle);
        setAhead(robotLocation.distance(destination) * (angle == turnAngle ? 1 : -1));
-- PEZ

I thought it would be something silly like that. I shall give it a try and let you know. Getting stronger all the time. -- jim


Robo Home | BlackPearl | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited February 16, 2004 0:26 EST by Sparafucil3 (diff)
Search: