Page 263 - The Definitive Guide to Building Java Robots
P. 263
Preston_5564C07.fm Page 244 Monday, September 26, 2005 5:38 AM
244 CHAPTER 7 ■ NAVIGATION
if (theta > 90 && theta < 180) {
theta = theta - 90;
phi = (int) ((theta / 90.0) * (REL_SOUTH - REL_EAST)) + REL_EAST;
}
if (theta > 180 && theta < 270) {
theta = theta - 180;
phi = (int) ((theta / 90.0) * (REL_WEST - REL_SOUTH)) + REL_SOUTH;
}
if (theta > 270 && theta < 360) {
theta = theta - 270;
phi = (int) ((theta / 90.0) * ((360 + REL_NORTH) - REL_WEST)) ➥
+ REL_WEST;
}
// in case actual directions
if (theta == 0) {
phi = REL_NORTH;
}
if (theta == 90) {
phi = REL_EAST;
}
if (theta == 180) {
phi = REL_SOUTH;
}
if (theta == 270) {
phi = REL_WEST;
}
if (phi > 360) {
phi = phi - 360;
}
return phi;
}
// setter for drive speed
public void setSpeed(int s) throws Exception {
drive.setSpeed(s);
}
// getter for drive speed
public int getSpeed() {
return drive.getSpeed();
}
// distance vector is in inches
public void move(DistanceVector dVect) throws Exception {
// convert since in inches
dVect.magnitude = getSurfaceRate(dVect.magnitude);