# History of BackAsFront

Robo Home | Changes | Preferences | AllPages

Revision 3 . . (edit) November 10, 2003 12:21 EST by PEZ
Revision 1 . . April 24, 2003 18:45 EST by PEZ

Difference (from prior major revision) (minor diff)

Changed: 6c6,28
 -- PEZ
 I have observed, for a very long time, that my bots often fail to optimize the turn-angle. I don't understand why, but I have studied code from some OpenSource bots in the hopes of finding a GoToBot that succeeds in this. To my surprise I discovered that iiley's bots are goto-bots. Surprising because I have often studied the source of these bots without noticing this. Most of these bots are minis and they take quite a few turns in order to shrink codesize... Anyway, here's a translation of how iiley does it. (From comments in the code, credits should go to David Alves and Dummy here, but I'm not sure if they mainly contributed to the obfuscation, eh ... shrinkage ... or the algorithm as such). ` void moveWithBackAsFront(double distance, double bearing) { double angle = Utils.normalRelativeAngle(bearing - getHeadingRadians()); double turnAngle = Math.atan(Math.tan(angle)); setTurnRightRadians(turnAngle); int direction = angle == turnAngle ? 1 : -1; setAhead(distance * direction); } ` You just pass the distance you want to travel and the bearing (in radians) to this function and it will sort out the shortest way to turn and what direction (forwards or backwards) to drive. The "atan(tan(angle))" stuff there does a sort of lossy normalization of any angle to the "-PI/2 -> +PI/2" space. It works much better than in my old goTo() functions. So here is the quite codesize-small goTo() of the development version of Tityus: ` void goTo(Point2D destination) { double angle = Utils.normalRelativeAngle(absoluteBearing(robotLocation, destination) - getHeadingRadians()); double turnAngle = Math.atan(Math.tan(angle)); setTurnRightRadians(turnAngle); setAhead(robotLocation.distance(destination) * (angle == turnAngle ? 1 : -1)); } ` -- PEZ

Robo Home | Changes | Preferences | AllPages
Search: