Page 102 - The Definitive Guide to Building Java Robots
P. 102
Preston_5564C03.fm Page 83 Wednesday, October 5, 2005 7:21 AM
CHAPTER 3 ■ MOTION 83
public class LM32 extends Ssc implements SSCProtocol, GroupMoveProtocol {
// buffer to store commands
private StringBuffer cmds = new StringBuffer();
// default speed in milliseconds
public static int DEFAULT_SPEED = 500;
// busy or not
private boolean busy = false;
// constructor taking JSerialPort
public LM32(JSerialPort sPort) throws Exception {
super(sPort);
super.setMaxPin(32);
}
// move command with parameter of milliseconds
public void move(int ms) throws Exception {
// this will pause the current thread for the arm move until
// it is finished completing its action
while (busy) {
Utils.pause(2);
}
// set the object status to busy
setBusy(ms);
// append final command
String cmd = cmds.append("T" + ms + CMD_TERM).toString();
// send bytes to LM32
execute(cmd.getBytes(), 0);
// clear command string
cmds = new StringBuffer(); //resets the string buffer for new set of
// commands
}
// override current SSC command
public void sscCmd(int ch, int pos) throws Exception {
cmd(ch, pos, DEFAULT_SPEED);
}
/**
* @param ch - channel 0-31
* @param pos - position 0-255
* @param spd - speed in milliseconds
*/