Fixes Analog IO class

This commit is contained in:
Patrick McDonagh
2017-03-13 15:28:17 -05:00
parent 512c275c84
commit f63826b9b5
4 changed files with 211 additions and 850 deletions

933
.idea/workspace.xml generated

File diff suppressed because it is too large Load Diff

View File

@@ -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);
}
}

View File

@@ -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){

View File

@@ -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++;
}