From 189e4fe37803dbfbaa3d9222c03d25d4e02071b7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Jun 2014 12:03:32 -0430 Subject: [PATCH 1/3] Cleaned the code a bit. Fixed the extension bit masks. --- src/ve/ucv/ciens/ccg/nxtarbot/NxtAR_bot.java | 18 ++++++++---------- .../ccg/nxtarbot/protocol/MotorMasks.java | 5 +++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ve/ucv/ciens/ccg/nxtarbot/NxtAR_bot.java b/src/ve/ucv/ciens/ccg/nxtarbot/NxtAR_bot.java index 51a1331..8e40d5f 100644 --- a/src/ve/ucv/ciens/ccg/nxtarbot/NxtAR_bot.java +++ b/src/ve/ucv/ciens/ccg/nxtarbot/NxtAR_bot.java @@ -40,7 +40,7 @@ public class NxtAR_bot{ private static SensorReportThread sendThread; /** - *

Finishes the communication threads anc closes the Bluetooth data streams, + *

Finishes the communication threads and closes the Bluetooth data streams, * then quits the application.

*/ private static void quit(){ @@ -78,7 +78,7 @@ public class NxtAR_bot{ // Start the light sensor and calibrate it. LightSensor lightSensor = new LightSensor(SensorPort.S1); - lightSensor.setFloodlight(false); + lightSensor.setFloodlight(true); System.out.println("Point at dark\nand press ENTER"); Button.ENTER.waitForPress(); @@ -89,6 +89,7 @@ public class NxtAR_bot{ Button.ENTER.waitForPress(); lightSensor.calibrateHigh(); System.out.println("--/--"); + System.out.println("Waiting for BT\nconnection"); // Connect with a Bluetooth device in raw mode. Then get the connection // streams. @@ -97,6 +98,7 @@ public class NxtAR_bot{ dataOutputStream = bluetoothConnection.openDataOutputStream(); dataInputStream = bluetoothConnection.openDataInputStream(); + System.out.println("--/--"); System.out.println("Connected"); // Start the networking threads and wait for them to finish. @@ -118,19 +120,15 @@ public class NxtAR_bot{ *

Force quit button listener.

*/ private static class QuitButtonListener implements ButtonListener{ - /** - * Force quit. - */ @Override public void buttonPressed(Button b){ + // Force quit. + System.out.println("--/--"); + System.out.println("Quitting"); System.exit(0); - //quit(); } - /** - * Do nothing. - */ @Override - public void buttonReleased(Button b){ } + public void buttonReleased(Button b){ /* Ignore */ } } } diff --git a/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java b/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java index 505f301..2239da9 100644 --- a/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java +++ b/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java @@ -18,6 +18,7 @@ package ve.ucv.ciens.ccg.nxtarbot.protocol; /** *

Bit masks used to code/decode the control instructions sent by NxtAR-cam to * NxtAR-bot.

+ * *

Expansions 1-3 are currently unused.

*/ public abstract class MotorMasks { @@ -27,6 +28,6 @@ public abstract class MotorMasks { public static final byte DIRECTION = (byte)0x08; public static final byte RECENTER = (byte)0x10; public static final byte EXPANSION_1 = (byte)0x20; - public static final byte EXPANSION_2 = (byte)0x20; - public static final byte EXPANSION_3 = (byte)0x20; + public static final byte EXPANSION_2 = (byte)0x40; + public static final byte EXPANSION_3 = (byte)0x80; } From a2ca1382e655fb77866c193ab8d1ab964c6427bc Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 23 Jun 2014 16:07:58 -0430 Subject: [PATCH 2/3] Added support for automatic actions. --- .../ccg/nxtarbot/protocol/MotorMasks.java | 4 ++-- .../nxtarbot/threads/MotorControlThread.java | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java b/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java index 2239da9..1d9d86a 100644 --- a/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java +++ b/src/ve/ucv/ciens/ccg/nxtarbot/protocol/MotorMasks.java @@ -19,7 +19,7 @@ package ve.ucv.ciens.ccg.nxtarbot.protocol; *

Bit masks used to code/decode the control instructions sent by NxtAR-cam to * NxtAR-bot.

* - *

Expansions 1-3 are currently unused.

+ *

Expansions 2-3 are currently unused.

*/ public abstract class MotorMasks { 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 DIRECTION = (byte)0x08; 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_3 = (byte)0x80; } diff --git a/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java b/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java index a6e4503..2129250 100644 --- a/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java +++ b/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java @@ -68,7 +68,7 @@ public class MotorControlThread extends Thread{ */ @Override public void run(){ - boolean motorA, motorB, motorC, recenterMotorB; + boolean motorA, motorB, motorC, recenterMotorB, rotate90; int direction, rotation, tacho; byte[] message = new byte[2]; @@ -79,11 +79,12 @@ public class MotorControlThread extends Thread{ message[1] = inputStream.readByte(); // Decode the instruction parameters. + rotate90 = (message[0] & MotorMasks.ROTATE_90) > 0 ? true : false; recenterMotorB = (message[0] & MotorMasks.RECENTER) > 0 ? true : false; - motorA = (message[0] & MotorMasks.MOTOR_A) > 0 ? true : false; - motorB = (message[0] & MotorMasks.MOTOR_B) > 0 ? true : false; - motorC = (message[0] & MotorMasks.MOTOR_C) > 0 ? true : false; - direction = (message[0] & MotorMasks.DIRECTION) > 0 ? BasicMotorPort.FORWARD : BasicMotorPort.BACKWARD; + motorA = (message[0] & MotorMasks.MOTOR_A) > 0 ? true : false; + motorB = (message[0] & MotorMasks.MOTOR_B) > 0 ? true : false; + motorC = (message[0] & MotorMasks.MOTOR_C) > 0 ? true : false; + direction = (message[0] & MotorMasks.DIRECTION) > 0 ? BasicMotorPort.FORWARD : BasicMotorPort.BACKWARD; if(motorA){ // Set motor A to run at specified speed. @@ -113,16 +114,22 @@ public class MotorControlThread extends Thread{ } if(recenterMotorB){ - System.out.println("RECENTER"); // Return motor B to it's origin. + System.out.println("RECENTER"); Motor.B.setSpeed(50 * Battery.getVoltage()); tacho = Motor.B.getTachoCount() % 360; rotation = -(tacho); Motor.B.rotate(rotation, false); } + if(rotate90){ + // Rotate 90 degrees. + System.out.println("ROTATE 90"); + Motor.B.rotate(90, false); + } + }catch(IOException io){ - // On disconnection terminate. + // On disconnection, terminate. done = true; } } From ab327cbf15f12fc4c8a09d6fa1d3515ae53b3b26 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 25 Jun 2014 16:11:51 -0430 Subject: [PATCH 3/3] Changed rotation amount when a ROTATE_90 message is received. --- src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java b/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java index 2129250..afb91d4 100644 --- a/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java +++ b/src/ve/ucv/ciens/ccg/nxtarbot/threads/MotorControlThread.java @@ -125,7 +125,7 @@ public class MotorControlThread extends Thread{ if(rotate90){ // Rotate 90 degrees. System.out.println("ROTATE 90"); - Motor.B.rotate(90, false); + Motor.B.rotate(-120, false); } }catch(IOException io){