Added support for automatic actions.

This commit is contained in:
2014-06-23 16:07:58 -04:30
parent 189e4fe378
commit a2ca1382e6
2 changed files with 16 additions and 9 deletions

View File

@@ -19,7 +19,7 @@ package ve.ucv.ciens.ccg.nxtarbot.protocol;
* <p>Bit masks used to code/decode the control instructions sent by NxtAR-cam to * <p>Bit masks used to code/decode the control instructions sent by NxtAR-cam to
* NxtAR-bot.</p> * NxtAR-bot.</p>
* *
* <p>Expansions 1-3 are currently unused.</p> * <p>Expansions 2-3 are currently unused.</p>
*/ */
public abstract class MotorMasks { public abstract class MotorMasks {
public static final byte MOTOR_A = (byte)0x01; public static final byte MOTOR_A = (byte)0x01;
@@ -27,7 +27,7 @@ public abstract class MotorMasks {
public static final byte MOTOR_C = (byte)0x04; public static final byte MOTOR_C = (byte)0x04;
public static final byte DIRECTION = (byte)0x08; public static final byte DIRECTION = (byte)0x08;
public static final byte RECENTER = (byte)0x10; public static final byte RECENTER = (byte)0x10;
public static final byte EXPANSION_1 = (byte)0x20; public static final byte ROTATE_90 = (byte)0x20;
public static final byte EXPANSION_2 = (byte)0x40; public static final byte EXPANSION_2 = (byte)0x40;
public static final byte EXPANSION_3 = (byte)0x80; public static final byte EXPANSION_3 = (byte)0x80;
} }

View File

@@ -68,7 +68,7 @@ public class MotorControlThread extends Thread{
*/ */
@Override @Override
public void run(){ public void run(){
boolean motorA, motorB, motorC, recenterMotorB; boolean motorA, motorB, motorC, recenterMotorB, rotate90;
int direction, rotation, tacho; int direction, rotation, tacho;
byte[] message = new byte[2]; byte[] message = new byte[2];
@@ -79,11 +79,12 @@ public class MotorControlThread extends Thread{
message[1] = inputStream.readByte(); message[1] = inputStream.readByte();
// Decode the instruction parameters. // Decode the instruction parameters.
rotate90 = (message[0] & MotorMasks.ROTATE_90) > 0 ? true : false;
recenterMotorB = (message[0] & MotorMasks.RECENTER) > 0 ? true : false; recenterMotorB = (message[0] & MotorMasks.RECENTER) > 0 ? true : false;
motorA = (message[0] & MotorMasks.MOTOR_A) > 0 ? true : false; motorA = (message[0] & MotorMasks.MOTOR_A) > 0 ? true : false;
motorB = (message[0] & MotorMasks.MOTOR_B) > 0 ? true : false; motorB = (message[0] & MotorMasks.MOTOR_B) > 0 ? true : false;
motorC = (message[0] & MotorMasks.MOTOR_C) > 0 ? true : false; motorC = (message[0] & MotorMasks.MOTOR_C) > 0 ? true : false;
direction = (message[0] & MotorMasks.DIRECTION) > 0 ? BasicMotorPort.FORWARD : BasicMotorPort.BACKWARD; direction = (message[0] & MotorMasks.DIRECTION) > 0 ? BasicMotorPort.FORWARD : BasicMotorPort.BACKWARD;
if(motorA){ if(motorA){
// Set motor A to run at specified speed. // Set motor A to run at specified speed.
@@ -113,16 +114,22 @@ public class MotorControlThread extends Thread{
} }
if(recenterMotorB){ if(recenterMotorB){
System.out.println("RECENTER");
// Return motor B to it's origin. // Return motor B to it's origin.
System.out.println("RECENTER");
Motor.B.setSpeed(50 * Battery.getVoltage()); Motor.B.setSpeed(50 * Battery.getVoltage());
tacho = Motor.B.getTachoCount() % 360; tacho = Motor.B.getTachoCount() % 360;
rotation = -(tacho); rotation = -(tacho);
Motor.B.rotate(rotation, false); Motor.B.rotate(rotation, false);
} }
if(rotate90){
// Rotate 90 degrees.
System.out.println("ROTATE 90");
Motor.B.rotate(90, false);
}
}catch(IOException io){ }catch(IOException io){
// On disconnection terminate. // On disconnection, terminate.
done = true; done = true;
} }
} }