Fixes Analog IO class
This commit is contained in:
933
.idea/workspace.xml
generated
933
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -65,18 +65,39 @@ public class AnalogIn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
System.out.println("Testing Analog Inputs Inputs...");
|
System.out.println("Testing Analog Inputs...");
|
||||||
AnalogIn testIn0 = new AnalogIn(0, 0, 1020, 0, 4.6);
|
AnalogIn testPosition = new AnalogIn(0, 0, 1020, 0, 145);
|
||||||
|
AnalogIn testLoad = new AnalogIn(1, 0, 1020, 0, 50000);
|
||||||
int loops = 0;
|
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 {
|
try {
|
||||||
System.out.println("Raw = " + testIn0.readRaw());
|
currentRawPosition = testPosition.readRaw();
|
||||||
System.out.println("Scaled = " + testIn0.readScaled());
|
currentRawLoad = testLoad.readRaw();
|
||||||
sleep(500);
|
|
||||||
|
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) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
loops++;
|
loops++;
|
||||||
}
|
}
|
||||||
|
System.out.println("Max Raw Position = " + maxRawPosition);
|
||||||
|
System.out.println("Max Raw Load = " + maxRawLoad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ public class POC implements Runnable{
|
|||||||
|
|
||||||
POC(String dbHostname){
|
POC(String dbHostname){
|
||||||
ioEnabled = true;
|
ioEnabled = true;
|
||||||
thisWell = new Well(dbHostname, 99, 99, 7);
|
thisWell = new Well(dbHostname, 0, 1, 7);
|
||||||
thisWell.getWellSetup();
|
thisWell.getWellSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
POC(String simFileName, boolean ioEnabled, String dbHostname){
|
POC(String simFileName, boolean ioEnabled, String dbHostname){
|
||||||
this.ioEnabled = ioEnabled;
|
this.ioEnabled = ioEnabled;
|
||||||
if (this.ioEnabled) {
|
if (this.ioEnabled) {
|
||||||
thisWell = new Well(dbHostname, simFileName,99, 99, 7);
|
thisWell = new Well(dbHostname, simFileName,0, 1, 7);
|
||||||
} else {
|
} else {
|
||||||
thisWell = new Well(dbHostname, simFileName,99, 99, 99);
|
thisWell = new Well(dbHostname, simFileName,99, 99, 99);
|
||||||
}
|
}
|
||||||
@@ -32,11 +32,19 @@ public class POC implements Runnable{
|
|||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
new Thread(new CLScanner(this)).start();
|
new Thread(new CLScanner(this)).start();
|
||||||
if(ioEnabled){
|
|
||||||
new Thread(new IOControl(this)).start();
|
|
||||||
}
|
|
||||||
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
||||||
thisWell.checkSafeties();
|
thisWell.checkSafeties();
|
||||||
|
if(ioEnabled){
|
||||||
|
new Thread(new IOControl(this)).start();
|
||||||
|
while (true) {
|
||||||
|
thisWell.eval();
|
||||||
|
try {
|
||||||
|
Thread.sleep(sleepMilliseconds);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
while (true) {
|
while (true) {
|
||||||
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
||||||
thisWell.eval(i);
|
thisWell.eval(i);
|
||||||
@@ -48,6 +56,7 @@ public class POC implements Runnable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +93,7 @@ public class POC implements Runnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 1){
|
if (args.length == 1){
|
||||||
dbHostname = args[1];
|
dbHostname = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length < 2){
|
if (args.length < 2){
|
||||||
|
|||||||
@@ -206,8 +206,8 @@ public class Well {
|
|||||||
db = new Database(dbHostname);
|
db = new Database(dbHostname);
|
||||||
strokesLifetime = db.getLastStrokeNum() + 1;
|
strokesLifetime = db.getLastStrokeNum() + 1;
|
||||||
currentCard = new Card(strokesLifetime);
|
currentCard = new Card(strokesLifetime);
|
||||||
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
|
inclinometer = new AnalogIn(inclinometerChannel, 0, 1020, 0, 145);
|
||||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
loadCell = new AnalogIn(loadCellChannel, 0, 1020, 0, 50000);
|
||||||
|
|
||||||
initializeMeasurements();
|
initializeMeasurements();
|
||||||
initializeSetpoints();
|
initializeSetpoints();
|
||||||
@@ -1228,6 +1228,46 @@ public class Well {
|
|||||||
return new LPStatus(dPosition, dLoad, status);
|
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(){
|
public void endOfStroke(){
|
||||||
currentCard.setNumPointsUsed(pointCounter + 1);
|
currentCard.setNumPointsUsed(pointCounter + 1);
|
||||||
currentCard.calcStrokeData(150, fluidGradient,
|
currentCard.calcStrokeData(150, fluidGradient,
|
||||||
@@ -1326,15 +1366,10 @@ public class Well {
|
|||||||
currentCard.setDownholeLoad(pointCounter, currentDownholeLoad);
|
currentCard.setDownholeLoad(pointCounter, currentDownholeLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inclinometer.getHistory(0) > inclinometer.getHistory(1))
|
if (checkEndOfStroke(5))
|
||||||
direction = DIRECTION_UP;
|
|
||||||
else if (inclinometer.getHistory(0) < inclinometer.getHistory(1))
|
|
||||||
direction = DIRECTION_DOWN;
|
|
||||||
|
|
||||||
if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) {
|
|
||||||
endOfStroke();
|
endOfStroke();
|
||||||
}
|
|
||||||
lastDirection = direction;
|
|
||||||
pointCounter++;
|
pointCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1396,15 +1431,10 @@ public class Well {
|
|||||||
currentCard.setDownholeLoad(pointCounter, currentDownholeLoad);
|
currentCard.setDownholeLoad(pointCounter, currentDownholeLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inclinometer.getHistory(0) > inclinometer.getHistory(1))
|
if (checkEndOfStroke(5))
|
||||||
direction = DIRECTION_UP;
|
|
||||||
else if (inclinometer.getHistory(0) < inclinometer.getHistory(1))
|
|
||||||
direction = DIRECTION_DOWN;
|
|
||||||
|
|
||||||
if (direction == DIRECTION_UP && lastDirection == DIRECTION_DOWN && pointCounter > 0) {
|
|
||||||
endOfStroke();
|
endOfStroke();
|
||||||
}
|
|
||||||
lastDirection = direction;
|
|
||||||
pointCounter++;
|
pointCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user