diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fbae620..28abec5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,9 @@ - + + + @@ -108,8 +110,8 @@ - - + + @@ -118,127 +120,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -261,24 +145,12 @@ - - - - - - - - - - - + - - - + @@ -286,83 +158,9 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -413,21 +211,31 @@ - + - + - + + + + + + + + + + + - + @@ -857,10 +665,8 @@ @@ -888,8 +696,8 @@ - @@ -909,8 +717,6 @@ - - @@ -934,12 +740,40 @@ + + @@ -1223,8 +1057,8 @@ - - + + @@ -1240,7 +1074,7 @@ - + @@ -1363,81 +1197,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1445,125 +1205,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1597,81 +1239,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1679,81 +1247,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1862,13 +1356,6 @@ - - - - - - - @@ -1937,106 +1424,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2067,140 +1454,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2216,7 +1469,55 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/henrypump/poc/AnalogIn.java b/src/main/java/com/henrypump/poc/AnalogIn.java index d2bfa06..3536937 100644 --- a/src/main/java/com/henrypump/poc/AnalogIn.java +++ b/src/main/java/com/henrypump/poc/AnalogIn.java @@ -65,18 +65,39 @@ public class AnalogIn { } public static void main(String[] args){ - System.out.println("Testing Analog Inputs Inputs..."); - AnalogIn testIn0 = new AnalogIn(0, 0, 1020, 0, 4.6); + System.out.println("Testing Analog Inputs..."); + AnalogIn testPosition = new AnalogIn(0, 0, 1020, 0, 145); + AnalogIn testLoad = new AnalogIn(1, 0, 1020, 0, 50000); int loops = 0; - while(loops < 60) { + double currentPosition, currentLoad; + long currentRawPosition, currentRawLoad; + long maxRawPosition = Long.MIN_VALUE; + long maxRawLoad = Long.MIN_VALUE; + + while(loops < 1000) { try { - System.out.println("Raw = " + testIn0.readRaw()); - System.out.println("Scaled = " + testIn0.readScaled()); - sleep(500); + currentRawPosition = testPosition.readRaw(); + currentRawLoad = testLoad.readRaw(); + + if (currentRawPosition > maxRawPosition){ + maxRawPosition = currentRawPosition; + } + + if (currentRawLoad > maxRawLoad){ + maxRawLoad = currentRawLoad; + } + + currentPosition = testPosition.readScaled(); + currentLoad = testLoad.readScaled(); + System.out.println("Position = " + currentPosition + ", Load = " + currentLoad); + + sleep(30); } catch (InterruptedException e) { e.printStackTrace(); } loops++; } + System.out.println("Max Raw Position = " + maxRawPosition); + System.out.println("Max Raw Load = " + maxRawLoad); } } diff --git a/src/main/java/com/henrypump/poc/POC.java b/src/main/java/com/henrypump/poc/POC.java index ca6696f..55cb7b5 100644 --- a/src/main/java/com/henrypump/poc/POC.java +++ b/src/main/java/com/henrypump/poc/POC.java @@ -15,14 +15,14 @@ public class POC implements Runnable{ POC(String dbHostname){ ioEnabled = true; - thisWell = new Well(dbHostname, 99, 99, 7); + thisWell = new Well(dbHostname, 0, 1, 7); thisWell.getWellSetup(); } POC(String simFileName, boolean ioEnabled, String dbHostname){ this.ioEnabled = ioEnabled; if (this.ioEnabled) { - thisWell = new Well(dbHostname, simFileName,99, 99, 7); + thisWell = new Well(dbHostname, simFileName,0, 1, 7); } else { thisWell = new Well(dbHostname, simFileName,99, 99, 99); } @@ -32,21 +32,30 @@ public class POC implements Runnable{ public void run(){ new Thread(new CLScanner(this)).start(); - if(ioEnabled){ - new Thread(new IOControl(this)).start(); - } long sleepMilliseconds = (long) (thisWell.getDt() * 1000); thisWell.checkSafeties(); - while (true) { - for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) { - thisWell.eval(i); - + if(ioEnabled){ + new Thread(new IOControl(this)).start(); + while (true) { + thisWell.eval(); try { Thread.sleep(sleepMilliseconds); } catch (InterruptedException e) { e.printStackTrace(); } } + } else { + while (true) { + for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) { + thisWell.eval(i); + + try { + Thread.sleep(sleepMilliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } } } @@ -84,7 +93,7 @@ public class POC implements Runnable{ } if (args.length == 1){ - dbHostname = args[1]; + dbHostname = args[0]; } if (args.length < 2){ diff --git a/src/main/java/com/henrypump/poc/Well.java b/src/main/java/com/henrypump/poc/Well.java index 707a09d..cfe4d0d 100644 --- a/src/main/java/com/henrypump/poc/Well.java +++ b/src/main/java/com/henrypump/poc/Well.java @@ -206,8 +206,8 @@ public class Well { db = new Database(dbHostname); strokesLifetime = db.getLastStrokeNum() + 1; currentCard = new Card(strokesLifetime); - inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100); - loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000); + inclinometer = new AnalogIn(inclinometerChannel, 0, 1020, 0, 145); + loadCell = new AnalogIn(loadCellChannel, 0, 1020, 0, 50000); initializeMeasurements(); initializeSetpoints(); @@ -1228,6 +1228,46 @@ public class Well { return new LPStatus(dPosition, dLoad, status); }; + private boolean checkEndOfStroke(int numConsecutivePoints){ + int tempDirection = DIRECTION_UNKNOWN; + int startDirection = DIRECTION_UNKNOWN; + boolean directionChanged = false; + + if(inclinometer.getHistory(0) > inclinometer.getHistory(1)){ + tempDirection = DIRECTION_UP; + startDirection = DIRECTION_UP; + } else if (inclinometer.getHistory(0) < inclinometer.getHistory(1)){ + tempDirection = DIRECTION_DOWN; + startDirection = DIRECTION_DOWN; + } + + if (startDirection == DIRECTION_UP) { + for (int i = 1; i < numConsecutivePoints; i++) { + if (inclinometer.getHistory(i) <= inclinometer.getHistory(i + 1)) { + return false; + } + } + tempDirection = DIRECTION_UP; + } + + if (startDirection == DIRECTION_DOWN) { + for (int i = 1; i < numConsecutivePoints; i++) { + if (inclinometer.getHistory(i) >= inclinometer.getHistory(i + 1)) { + return false; + } + } + tempDirection = DIRECTION_DOWN; + } + + if (tempDirection != lastDirection){ + if (tempDirection == DIRECTION_UP && pointCounter > 1){ + directionChanged = true; + } + lastDirection = tempDirection; + } + return directionChanged; + } + public void endOfStroke(){ currentCard.setNumPointsUsed(pointCounter + 1); currentCard.calcStrokeData(150, fluidGradient, @@ -1326,15 +1366,10 @@ public class Well { currentCard.setDownholeLoad(pointCounter, currentDownholeLoad); } - if (inclinometer.getHistory(0) > inclinometer.getHistory(1)) - direction = DIRECTION_UP; - else if (inclinometer.getHistory(0) < inclinometer.getHistory(1)) - direction = DIRECTION_DOWN; - - if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) { + if (checkEndOfStroke(5)) endOfStroke(); - } - lastDirection = direction; + + pointCounter++; } @@ -1396,15 +1431,10 @@ public class Well { currentCard.setDownholeLoad(pointCounter, currentDownholeLoad); } - if (inclinometer.getHistory(0) > inclinometer.getHistory(1)) - direction = DIRECTION_UP; - else if (inclinometer.getHistory(0) < inclinometer.getHistory(1)) - direction = DIRECTION_DOWN; - - if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) { + if (checkEndOfStroke(5)) endOfStroke(); - } - lastDirection = direction; + + pointCounter++; }