mRec;
@@ -103,29 +89,30 @@
mTravelPlans.add(mLowPower);
mTravelPlans.add(mFlightPath);
mTravelPlans.add(mOnMyOwn);
-
- mTargetLock = new ReentrantLock();
mStatus = status;
- }
-
- /**
- * Changes autopilot status (on or off)
- * @param onoff The new autopilot status
- */
- public void autoPilot(boolean onoff) {
- mAutoPilot.set(onoff);
- mHandler.removeMessages(EVAL_NAV);
- if (mAutoPilot.get()) {
- mHandler.sendEmptyMessage(EVAL_NAV);
- Log.i(TAG, "Autopilot engaged");
- }
- else
- Log.i(TAG, "Autopilot disengaged");
- }
-
- /** Evaluates a new navigation vector, based on current status and the relevant NavTask */
- private void evalNextVector() {
+
+ //FOR TESTING ONLY:
+ /*String taskList = "{ " +
+ "{ DEST!targ1!300!-74.012345!40.74!10!100!232 { DEST!targ2!300!-77.07950!38.97300!100!250!233 " +
+ " DEST!targ3!587!-117.15!32.72!10!600!234 } } }";*/
+ String taskList = "{ VEL!name1!1!0!0!0!180000!-10 VEL!name1!-1!0!0!0!10000!-10 VEL!name1!0!1!0!0!10000!-10 VEL!name1!0!-1!0!0!10000!-10 VEL!name1!0!0!1!0!10000!-10 VEL!name1!0!0!-1!0!10000!-10 -4}";
+ setTask(BASIC_AUTO, taskList);
+ setTask(NO_CONN, "{ VEL!No_Conn!0!0!-1!0!" + THREE_HRS_IN_MS + "!-1!-5 -6}");
+ setTask(LOW_POWER, "{ VEL!Low_Power!0!0!-1!0!"+ THREE_HRS_IN_MS + "!-1!-7 -8}");
+ //mNavStatus.set(BASIC_AUTO);
+
+
+ //autoPilot(true);
+ }
+
+
+
+ /**
+ * Evaluates a new navigation vector, based on current status and the relevant NavTask.
+ * @param newNavTarget If supplied and has length >= 4, writes the new target here. May be null.
+ */
+ public void evalNextVector(double[] newNavTarget) {
/*Determine what the current task should be. Copies to a local variable in case
* 'status' changes during execution of the method */
@@ -140,79 +127,14 @@
}
mTask.getVelocity(myList, mTempTarget);
setTarget(mTempTarget);
-
-
-
- long interval = mTask.getInterval(myList);
- Log.v(TAG, "Nav Interval is " + interval);
+ if (newNavTarget != null) {
+ getTarget(newNavTarget);
+ }
+
+ //long interval = mTask.getInterval(myList);
+ //Log.v(TAG, "Nav Interval is " + interval);
//Send the current NavList to the server, in case any tasks have been completed
updateReceivers("NAV:AUTOTASK:" + thisStatus + ":" + myList.toString());
-
- mHandler.removeMessages(EVAL_NAV);
- if (mAutoPilot.get()) {
- if (interval > 0) {
- mHandler.sendEmptyMessageDelayed(EVAL_NAV, interval);
- }
- else {
- mHandler.sendEmptyMessage(EVAL_NAV);
- }
- }
- }
-
- /**
- * Starts the navigation thread
- */
- public void run() {
- Looper.prepare();
- Thread.currentThread().setName("Navigation");
- mHandler = new Handler() {
- public void handleMessage(Message msg)
- {
- switch (msg.what) {
- case EVAL_NAV:
- if (mAutoPilot.get())
- evalNextVector();
- break;
- }
- }
- };
-
- //FOR TESTING ONLY:
- /*String taskList = "{ " +
- "{ DEST!targ1!300!-74.012345!40.74!10!100!232 { DEST!targ2!300!-77.07950!38.97300!100!250!233 " +
- " DEST!targ3!587!-117.15!32.72!10!600!234 } } }";*/
- String taskList = "{ VEL!name1!1!0!0!0!10000!-10 VEL!name1!-1!0!0!0!10000!-10 VEL!name1!0!1!0!0!10000!-10 VEL!name1!0!-1!0!0!10000!-10 VEL!name1!0!0!1!0!10000!-10 VEL!name1!0!0!-1!0!10000!-10 -4}";
- setTask(BASIC_AUTO, taskList);
- setTask(NO_CONN, "{ VEL!No_Conn!0!0!-1!0!" + THREE_HRS_IN_MS + "!-1!-5 -6}");
- setTask(LOW_POWER, "{ VEL!Low_Power!0!0!-1!0!"+ THREE_HRS_IN_MS + "!-1!-7 -8}");
- //mNavStatus.set(BASIC_AUTO);
-
-
- //autoPilot(true);
-
- Looper.loop();
- }
-
- /**
- * Obtains current navigation target vector. If the data is
- * locked, immediately throws an exception.
- *
- * @return A new array containing the navigation target vector.
- * @throws IllegalAccessException If the data is currently locked.
- */
- public double[] getTarget() throws IllegalAccessException {
- double[] myTarget = new double[4];
- if (mTargetLock.tryLock()) {
- for (int i = 0; i < 4; i++) {
- myTarget[i] = mTarget[i];
- }
- mTargetLock.unlock();
- }
- else {
- Log.w(TAG, "Target vector is locked.");
- throw new IllegalAccessException();
- }
- return mTarget;
}
/**
@@ -223,17 +145,11 @@
* @param expectedValues The array in which to write the
* vector--must be at least of length 4.
*/
- public void getTarget(double[] expectedValues) {
- if (expectedValues.length < 4)
+ public void getTarget(double[] navTarget) {
+ if (navTarget.length < 4)
return;
- if (mTargetLock.tryLock()) {
- for (int i = 0; i < 4; i++) {
- expectedValues[i] = mTarget[i];
- }
- mTargetLock.unlock();
- }
- else {
- Log.w(TAG, "Target vector is locked.");
+ synchronized (mTarget) {
+ System.arraycopy(mTarget, 0, navTarget, 0, 4);
}
}
@@ -256,10 +172,8 @@
for (int i = 0; i < 3; i++) {
mTempTarget[i] = 0;
}
- mTempTarget[3] = mStatus.getReadingFieldNow(AZIMUTH, mTempTarget[3]);
+ mTempTarget[3] = mStatus.getReadingField(AZIMUTH);
setTarget(mTempTarget);
- mHandler.removeMessages(EVAL_NAV);
- mHandler.sendEmptyMessageDelayed(EVAL_NAV, HOVER_PAUSE);
}
/**
@@ -267,33 +181,17 @@
* @param source The source of the message, if a reply is needed. May be null.
*/
public void receiveMessage(String msg, Receivable source) {
- Log.d(TAG, "Receiving " + msg);
String[] parts = msg.split(":");
- if (parts[0].equals("GUID")) {
- if (parts[1].equals("VECTOR")) {
- autoPilot(false);
- }
- }
+
if (parts[0].equals("NAV")) {
if (parts[1].equals("SET")) {
Log.v(TAG, "Updating Nav Status");
- if (parts[2].equals("MANUAL")) {
- autoPilot(false);
- if (parts.length > 3) {
- updateReceivers("GUID:LOCALVEC");
- updateReceivers("GUID:AUTOMATIC");
- double[] newTarget = new double[4];
- for (int i = 0; i < 4; i++) {
- newTarget[i] = new Double(parts[i + 3]);
- }
- setTarget(newTarget);
- }
- }
+
if (parts[2].equals("AUTOPILOT")) {
mNavStatus.set(BASIC_AUTO);
updateReceivers("GUID:ABSVEC");
updateReceivers("GUID:AUTOMATIC");
- autoPilot(true);
+ //autoPilot(true);
}
if (parts[2].equals("AUTOTASK")) {
Integer taskList = new Integer(parts[3]);
@@ -317,15 +215,12 @@
}
if (parts[0].equals("CSYS")) {
if (parts[1].equals("NOCONN")) {
- Log.d(TAG, "no conn in Nav");
updateStatus(NO_CONN);
- autoPilot(true);
- updateReceivers("GUID:AUTOMATIC");
+ //autoPilot(true);
}
if (parts[1].equals("LOWPOWER")) {
updateStatus(LOW_POWER);
- autoPilot(true);
- updateReceivers("GUID:AUTOMATIC");
+ //autoPilot(true);
}
}
}
@@ -344,24 +239,18 @@
* Sets the navigation target vector to the values contained by the supplied array (length must be at least 4).
* @param newTarget The new target vector.
*/
- protected void setTarget(double[] newTarget) {
+ private void setTarget(double[] newTarget) {
if (newTarget.length < 4) {
return;
}
- final double[] myCopy = newTarget.clone();
- new Thread() {
- public void run() {
+ synchronized (mTarget) {
String newNav = "New_Nav_Vector: ";
- mTargetLock.lock();
- for (int i = 0; i < 4; i++) {
- mTarget[i] = myCopy[i];
- newNav += myCopy[i] + ":";
- }
- mTargetLock.unlock();
- Log.i(TAG, newNav);
+ for (int i = 0; i < 4; i++) {
+ mTarget[i] = newTarget[i];
+ newNav += newTarget[i] + ":";
+ }
updateReceivers(newNav);
- }
- }.start();
+ }
}
/**
@@ -384,8 +273,6 @@
Log.i(TAG, "Nav set index " + whichPlan + " to task " + myList);
//Confirm change to server:
updateReceivers("NAV:AUTOTASK:" + whichPlan + ":" + myList.toString());
- if (mAutoPilot.get())
- evalNextVector();
}
else {
Log.e(TAG, "Nav received invalid task!");
diff --git a/org/haldean/chopper/pilot/StatusReporter.java b/org/haldean/chopper/pilot/StatusReporter.java
index fca9c05..276a609 100644
--- a/org/haldean/chopper/pilot/StatusReporter.java
+++ b/org/haldean/chopper/pilot/StatusReporter.java
@@ -6,7 +6,6 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
-import android.util.Log;
/**
* Sends regular chopper status reports to all registered receivers.
@@ -61,26 +60,17 @@
LinkedList infoList = new LinkedList();
/* Lock data, send it, unlock. If the lock is unavailable (unlikely), skip this datapiece for this iteration */
- try {
- double myAzimuth = mStatus.getReadingFieldNow(AZIMUTH);
- double myPitch = mStatus.getReadingFieldNow(PITCH);
- double myRoll = mStatus.getReadingFieldNow(ROLL);
- infoList.add("ORIENT:" + myAzimuth + ":" + myPitch + ":" + myRoll);
- }
- catch (IllegalAccessException e) {
- Log.w(TAG, "Orientation Report Unavailable");
- }
-
- try {
- double myXaccel = mStatus.getReadingFieldNow(X_ACCEL);
- double myYaccel = mStatus.getReadingFieldNow(Y_ACCEL);
- double myZaccel = mStatus.getReadingFieldNow(Z_ACCEL);
- infoList.add("ACCEL:" + myXaccel + ":" + myYaccel + ":" + myZaccel);
- }
- catch (IllegalAccessException e) {
- Log.w(TAG, "Acceleration Report Unavailable");
- }
-
+ double myAzimuth = mStatus.getReadingField(AZIMUTH);
+ double myPitch = mStatus.getReadingField(PITCH);
+ double myRoll = mStatus.getReadingField(ROLL);
+ infoList.add("ORIENT:" + myAzimuth + ":" + myPitch + ":" + myRoll);
+
+
+ double myXaccel = mStatus.getReadingField(X_ACCEL);
+ double myYaccel = mStatus.getReadingField(Y_ACCEL);
+ double myZaccel = mStatus.getReadingField(Z_ACCEL);
+ infoList.add("ACCEL:" + myXaccel + ":" + myYaccel + ":" + myZaccel);
+
/*try {
double myXflux = mStatus.getReadingFieldNow(X_FLUX);
double myYflux = mStatus.getReadingFieldNow(Y_FLUX);
@@ -91,16 +81,13 @@
Log.w(TAG, "Flux Report Unavailable");
}*/
- try {
- double[] mySpeeds = mStatus.getMotorFieldsNow();
- infoList.add("MOTORSPEED:" + mySpeeds[0] +
- ":" + mySpeeds[1] +
- ":" + mySpeeds[2] +
- ":" + mySpeeds[3]);
- }
- catch (IllegalAccessException e) {
- Log.w(TAG, "MotorSpeeds Report Unavailable");
- }
+ double[] mySpeeds = new double[4];
+ mStatus.getMotorFields(mySpeeds);
+ infoList.add("MOTORSPEED:" + mySpeeds[0] +
+ ":" + mySpeeds[1] +
+ ":" + mySpeeds[2] +
+ ":" + mySpeeds[3]);
+
/*
try {
double[] myPowers = mStatus.getMotorFieldsNow();
@@ -136,30 +123,18 @@
Log.w(TAG, "Pressure Report Unavailable");
}
*/
- try {
- double myTemp = mStatus.getReadingFieldNow(TEMPERATURE);
- infoList.add("TEMPERATURE:" + myTemp);
- }
- catch (IllegalAccessException e) {
- Log.w(TAG, "Temperature Report Unavailable");
- }
-
+ infoList.add("TEMPERATURE:" + mStatus.getReadingField(TEMPERATURE));
infoList.add("BATTERY:" + mStatus.getBatteryLevel());
/* Send GPS data */
String gpsData = new String("GPS");
- try {
- for (int i = 0; i < GPS_FIELDS; i++) {
- double myValue = mStatus.getGpsFieldNow(i);
- gpsData += ":" + myValue;
- }
-
- gpsData += ":" + mStatus.getGpsExtrasNow();
- infoList.add(gpsData);
- }
- catch (IllegalAccessException e) {
- Log.w(TAG, "GPS Report Unavailable");
- }
+
+ for (int i = 0; i < GPS_FIELDS; i++) {
+ double myValue = mStatus.getGpsField(i);
+ gpsData += ":" + myValue;
+ }
+ gpsData += ":" + mStatus.getGpsExtras();
+ infoList.add(gpsData);
return infoList;
}
diff --git a/org/haldean/chopper/server/EnsignCrusher.java b/org/haldean/chopper/server/EnsignCrusher.java
index 354e1a6..b055e5a 100644
--- a/org/haldean/chopper/server/EnsignCrusher.java
+++ b/org/haldean/chopper/server/EnsignCrusher.java
@@ -16,8 +16,9 @@
* @author William Brown
*/
public class EnsignCrusher {
- private static String navGoToManual = "NAV:SET:MANUAL";
- private static String navGoToAutomatic = "NAV:SET:AUTOPILOT";
+ private static String navGoToDirect = "GUID:DIRECT"; // Direct control of motor speeds.
+ private static String navGoToManual = "GUID:MANUAL"; // Manual control of chopper target angles.
+ private static String navGoToAutomatic = "GUID:AUTO"; // Full automatic navigation.
private static double bearing = 0;
/* In meters per second (we hope.) */
@@ -99,7 +100,7 @@
* the motor closest to North.
*/
public static void setMotorSpeeds(double[] speeds) {
- String taskString = "GUID:VECTOR";
+ String taskString = navGoToDirect;
for (int i=0; i<4; i++) {
taskString += ":" + speeds[i];
}
diff --git a/org/haldean/chopper/server/PadController.java b/org/haldean/chopper/server/PadController.java
index 2550771..8b8d1b9 100644
--- a/org/haldean/chopper/server/PadController.java
+++ b/org/haldean/chopper/server/PadController.java
@@ -90,7 +90,7 @@
buttons[BUTTON_X] = c;
else if (id == Component.Identifier.Button.Y)
buttons[BUTTON_Y] = c;
- else if (id == Component.Identifier.Button.BACK)
+ else if ((id == Component.Identifier.Button.BACK) || (id == Component.Identifier.Button.SELECT))
buttons[BUTTON_BACK] = c;
else if (id == Component.Identifier.Button.LEFT_THUMB)
buttons[BUTTON_L] = c;
@@ -120,7 +120,7 @@
axes[AXIS_R_TRIGGER] = c;
else if (id == Component.Identifier.Axis.POV)
axes[D_PAD] = c;
- }
+ }
}
}