Page 93 - The Definitive Guide to Building Java Robots
P. 93
Preston_5564C03.fm Page 74 Wednesday, October 5, 2005 7:21 AM
74 CHAPTER 3 ■ MOTION
// 3 millieconds at 9600 baud
public static final int MIN_STEP_SIZE = 3;
// 2 milliseconds for standard servo
public static final int MIN_DELAY_SIZE = 2;
// delay in milliseconds between move
private int moveDelay = 50;
// byte size of single step
private int stepSize = MIN_STEP_SIZE;
private int speed = 0;
// MiniSSC doing work
private MiniSsc ssc;
// constructor takes JSerialPort
public PanTilt(JSerialPort sPort) throws Exception{
ssc = new MiniSsc(sPort);
}
// move both servos to positions
private void move() throws Exception {
horz(horzPos);
vert(vertPos);
}
// move both servos with input parameters
// h = horizontal servo
// v = vertical servo
public void moveBoth(int h, int v) throws Exception{
// set private fields
horzPos = h;
vertPos = v;
// move
move();
}
public void horz(int pos) throws Exception{
// check to see if position within limits
if (pos < MAX_LEFT || pos > MAX_RIGHT ) {
throw new Exception("Out of horizontal range.");
}
// set pos
horzPos = pos;
// move
ssc.move(HORZ_SERVO,pos);
}