4 Commits

3 changed files with 27 additions and 21 deletions

View File

@@ -40,7 +40,7 @@ public class NxtAR_bot{
private static SensorReportThread sendThread; private static SensorReportThread sendThread;
/** /**
* <p>Finishes the communication threads anc closes the Bluetooth data streams, * <p>Finishes the communication threads and closes the Bluetooth data streams,
* then quits the application.</p> * then quits the application.</p>
*/ */
private static void quit(){ private static void quit(){
@@ -78,7 +78,7 @@ public class NxtAR_bot{
// Start the light sensor and calibrate it. // Start the light sensor and calibrate it.
LightSensor lightSensor = new LightSensor(SensorPort.S1); LightSensor lightSensor = new LightSensor(SensorPort.S1);
lightSensor.setFloodlight(false); lightSensor.setFloodlight(true);
System.out.println("Point at dark\nand press ENTER"); System.out.println("Point at dark\nand press ENTER");
Button.ENTER.waitForPress(); Button.ENTER.waitForPress();
@@ -89,6 +89,7 @@ public class NxtAR_bot{
Button.ENTER.waitForPress(); Button.ENTER.waitForPress();
lightSensor.calibrateHigh(); lightSensor.calibrateHigh();
System.out.println("--/--"); System.out.println("--/--");
System.out.println("Waiting for BT\nconnection");
// Connect with a Bluetooth device in raw mode. Then get the connection // Connect with a Bluetooth device in raw mode. Then get the connection
// streams. // streams.
@@ -97,6 +98,7 @@ public class NxtAR_bot{
dataOutputStream = bluetoothConnection.openDataOutputStream(); dataOutputStream = bluetoothConnection.openDataOutputStream();
dataInputStream = bluetoothConnection.openDataInputStream(); dataInputStream = bluetoothConnection.openDataInputStream();
System.out.println("--/--");
System.out.println("Connected"); System.out.println("Connected");
// Start the networking threads and wait for them to finish. // Start the networking threads and wait for them to finish.
@@ -118,19 +120,15 @@ public class NxtAR_bot{
* <p>Force quit button listener.</p> * <p>Force quit button listener.</p>
*/ */
private static class QuitButtonListener implements ButtonListener{ private static class QuitButtonListener implements ButtonListener{
/**
* Force quit.
*/
@Override @Override
public void buttonPressed(Button b){ public void buttonPressed(Button b){
// Force quit.
System.out.println("--/--");
System.out.println("Quitting");
System.exit(0); System.exit(0);
//quit();
} }
/**
* Do nothing.
*/
@Override @Override
public void buttonReleased(Button b){ } public void buttonReleased(Button b){ /* Ignore */ }
} }
} }

View File

@@ -18,7 +18,8 @@ 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;
@@ -26,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)0x20; public static final byte EXPANSION_2 = (byte)0x40;
public static final byte EXPANSION_3 = (byte)0x20; 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,6 +79,7 @@ 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;
@@ -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(-120, false);
}
}catch(IOException io){ }catch(IOException io){
// On disconnection terminate. // On disconnection, terminate.
done = true; done = true;
} }
} }