Page 94 - The Definitive Guide to Building Java Robots
P. 94
Preston_5564C03.fm Page 75 Wednesday, October 5, 2005 7:21 AM
CHAPTER 3 ■ MOTION 75
public void horzDegree(int angle) throws Exception{
// check to see if angle is within limits of 0-180
if (angle <0 || angle > 180) {
throw new Exception("Out of range, angle 0-180.");
}
// convert fraction of 255
double theta = ((double)angle/180 ) * 255.0 ;
// move
horz((int)theta);
}
public void vert(int pos) throws Exception{
if (pos < MAX_DOWN || pos > MAX_UP ) {
throw new Exception("Out of vertical range.");
}
vertPos = pos;
ssc.move(VERT_SERVO,pos);
}
public void vertDegree(int angle) throws Exception{
if (angle <0 || angle > 180) {
throw new Exception("Out of range, angle 0-180.");
}
double theta = ((double)angle/180 ) * 255.0 ;
vert((int)theta);
}
// reset to neutral position
public void reset( ) throws Exception{
horzPos = HORZ_NEUTRAL;
vertPos = VERT_NEUTRAL;
move();
}
// move right specific step size
public void moveRight(int size) throws Exception{
horz(horzPos+size);
}
// move right current stepSize
public void moveRight()throws Exception {
moveRight(stepSize);
}