removes control IO from the Well class, creates threaded IOControl class
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
import javax.sound.midi.Soundbank;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
67
src/main/java/com/henrypump/poc/IOControl.java
Normal file
67
src/main/java/com/henrypump/poc/IOControl.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.henrypump.poc;
|
||||
|
||||
/**
|
||||
* Created by patrickjmcd on 2/10/17.
|
||||
*/
|
||||
public class IOControl implements Runnable {
|
||||
|
||||
private final POC poc;
|
||||
private DigitalIn startBtn, stopBtn;
|
||||
private DigitalOut led2, led3, led4, led5;
|
||||
private DigitalOut runningIndicator, runCommand;
|
||||
private double pos = 0;
|
||||
private int runStatus;
|
||||
|
||||
IOControl(POC poc){
|
||||
this.poc = poc;
|
||||
// IO
|
||||
startBtn = new DigitalIn(8);
|
||||
stopBtn = new DigitalIn(9);
|
||||
led2 = new DigitalOut(2, 0);
|
||||
led3 = new DigitalOut(3, 0);
|
||||
led4 = new DigitalOut(4, 0);
|
||||
led5 = new DigitalOut(5, 0);
|
||||
runningIndicator = new DigitalOut(6,0);
|
||||
runCommand = new DigitalOut(7,0);
|
||||
}
|
||||
|
||||
private void startWell(){
|
||||
poc.thisWell.start("startbutton");
|
||||
}
|
||||
|
||||
private void stopWell(){
|
||||
poc.thisWell.stop("startbutton");
|
||||
}
|
||||
|
||||
private void exitPOC(){
|
||||
allOutputsOff();
|
||||
System.exit(99);
|
||||
}
|
||||
|
||||
public void allOutputsOff(){
|
||||
led2.write(0,true);
|
||||
led3.write(0,true);
|
||||
led4.write(0,true);
|
||||
led5.write(0,true);
|
||||
runningIndicator.write(0, true);
|
||||
runCommand.write(0,true);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (startBtn.read() == 1) startWell();
|
||||
if (stopBtn.read() == 1) stopWell();
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
exitPOC();
|
||||
}
|
||||
|
||||
pos = poc.thisWell.getCurrentSurfacePosition();
|
||||
runStatus = poc.thisWell.getRunStatus();
|
||||
led2.write(pos > 20.0 ? 1 : 0);
|
||||
led3.write(pos > 40.0 ? 1 : 0);
|
||||
led4.write(pos > 60.0 ? 1 : 0);
|
||||
led5.write(pos > 80.0 ? 1 : 0);
|
||||
|
||||
runningIndicator.write(runStatus==Well.RUNSTATUS_RUNNING ? 1 : 0);
|
||||
runCommand.write((runStatus == Well.RUNSTATUS_RUNNING || runStatus == Well.RUNSTATUS_STARTING) ? 1: 0);
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,7 @@ public class POC implements Runnable{
|
||||
protected Well thisWell;
|
||||
private int simLoops;
|
||||
private Thread t;
|
||||
private DigitalIn startBtn, stopBtn;
|
||||
private DigitalOut led2, led3, led4, led5;
|
||||
private DigitalOut runIndicator;
|
||||
|
||||
|
||||
private boolean ioEnabled;
|
||||
|
||||
@@ -25,14 +23,7 @@ public class POC implements Runnable{
|
||||
// thisWell.printTapers();
|
||||
this.simLoops = simLoops;
|
||||
|
||||
// IO
|
||||
startBtn = new DigitalIn(8);
|
||||
stopBtn = new DigitalIn(9);
|
||||
led2 = new DigitalOut(2, 0);
|
||||
led3 = new DigitalOut(3, 0);
|
||||
led4 = new DigitalOut(4, 0);
|
||||
led5 = new DigitalOut(5, 0);
|
||||
runIndicator = new DigitalOut(6,0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -41,25 +32,9 @@ public class POC implements Runnable{
|
||||
if (this.ioEnabled) {
|
||||
thisWell = new Well(wellName, simFileName,99, 99, 7);
|
||||
|
||||
// IO
|
||||
startBtn = new DigitalIn(8);
|
||||
stopBtn = new DigitalIn(9);
|
||||
led2 = new DigitalOut(2, 0);
|
||||
led3 = new DigitalOut(3, 0);
|
||||
led4 = new DigitalOut(4, 0);
|
||||
led5 = new DigitalOut(5, 0);
|
||||
runIndicator = new DigitalOut(6,0);
|
||||
|
||||
} else {
|
||||
thisWell = new Well(wellName, simFileName,99, 99, 99);
|
||||
// IO
|
||||
startBtn = new DigitalIn(99);
|
||||
stopBtn = new DigitalIn(99);
|
||||
led2 = new DigitalOut(99, 0);
|
||||
led3 = new DigitalOut(99, 0);
|
||||
led4 = new DigitalOut(99, 0);
|
||||
led5 = new DigitalOut(99, 0);
|
||||
runIndicator = new DigitalOut(99,0);
|
||||
}
|
||||
|
||||
thisWell.parseJSONFile(wellSetupJsonFile);
|
||||
@@ -67,40 +42,21 @@ public class POC implements Runnable{
|
||||
this.simLoops = simLoops;
|
||||
}
|
||||
|
||||
public void allOutputsOff(){
|
||||
led2.write(0,true);
|
||||
led3.write(0,true);
|
||||
led4.write(0,true);
|
||||
led5.write(0,true);
|
||||
}
|
||||
|
||||
public void run(){
|
||||
new Thread(new CLScanner(this)).start();
|
||||
int led2out, led3out, led4out,led5out;
|
||||
double pos;
|
||||
if(ioEnabled){
|
||||
new Thread(new IOControl(this)).start();
|
||||
}
|
||||
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
|
||||
thisWell.setupFluidRatio(0.50, 0.50, 1.12);
|
||||
thisWell.checkSafeties();
|
||||
while (true) {
|
||||
while (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING) {
|
||||
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
|
||||
if (startBtn.read() == 1) thisWell.start("startbutton");
|
||||
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
thisWell.eval(i);
|
||||
|
||||
pos = thisWell.getCurrentSurfacePosition();
|
||||
led2.write(pos > 20.0 ? 1 : 0);
|
||||
led3.write(pos > 40.0 ? 1 : 0);
|
||||
led4.write(pos > 60.0 ? 1 : 0);
|
||||
led5.write(pos > 80.0 ? 1 : 0);
|
||||
|
||||
runIndicator.write(thisWell.getRunStatus()==Well.RUNSTATUS_RUNNING ? 1 : 0);
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepMilliseconds);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -108,17 +64,6 @@ public class POC implements Runnable{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (startBtn.read() == 1) thisWell.start("startbutton");
|
||||
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
|
||||
if (startBtn.read() == 1 && stopBtn.read() == 1) {
|
||||
System.exit(0);
|
||||
}
|
||||
led2.write(0);
|
||||
led3.write(0);
|
||||
led4.write(0);
|
||||
led5.write(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ public class Well {
|
||||
/* IO */
|
||||
AnalogIn inclinometer;
|
||||
AnalogIn loadCell;
|
||||
DigitalOut runCommand;
|
||||
private double currentSurfacePosition;
|
||||
private double currentSurfaceLoad;
|
||||
private double currentDownholePosition;
|
||||
@@ -181,7 +180,6 @@ public class Well {
|
||||
currentCard = new Card(strokesLifetime);
|
||||
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
|
||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
||||
runCommand = new DigitalOut(runCommandChannel, 0);
|
||||
|
||||
strokeSpeed = new Measurement("Stroke Speed", true, db, 0.5, 600);
|
||||
downholeGrossStroke = new Measurement("Downhole Gross Stroke", true, db, 0.5, 600);
|
||||
@@ -212,7 +210,6 @@ public class Well {
|
||||
currentCard = new Card(strokesLifetime);
|
||||
inclinometer = new AnalogIn(inclinometerChannel, 0, 100, 0, 100);
|
||||
loadCell = new AnalogIn(loadCellChannel, 0, 50000, 0, 50000);
|
||||
runCommand = new DigitalOut(runCommandChannel, 0);
|
||||
|
||||
strokeSpeed = new Measurement("Stroke Speed", true, db, 0.5, 600);
|
||||
downholeGrossStroke = new Measurement("Downhole Gross Stroke", true, db, 0.5, 600);
|
||||
@@ -987,12 +984,6 @@ public class Well {
|
||||
pointCounter++;
|
||||
}
|
||||
|
||||
if (runStatus == RUNSTATUS_RUNNING || runStatus == RUNSTATUS_STARTING){
|
||||
runCommand.write(1);
|
||||
} else {
|
||||
runCommand.write(0);
|
||||
}
|
||||
|
||||
if(isNewDay()){
|
||||
strokeSpeed.endOfDay();
|
||||
downholeGrossStroke.endOfDay();
|
||||
@@ -1048,12 +1039,6 @@ public class Well {
|
||||
pointCounter++;
|
||||
}
|
||||
|
||||
if (runStatus == RUNSTATUS_RUNNING || runStatus == RUNSTATUS_STARTING){
|
||||
runCommand.write(1);
|
||||
} else {
|
||||
runCommand.write(0);
|
||||
}
|
||||
|
||||
if(isNewDay()){
|
||||
strokeSpeed.endOfDay();
|
||||
downholeGrossStroke.endOfDay();
|
||||
@@ -1107,9 +1092,6 @@ public class Well {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void allOutputsOff(){
|
||||
runCommand.write(0, true);
|
||||
}
|
||||
|
||||
public static void main( String[] args ){
|
||||
Well thisWell = new Well("Barney", args[1], 99, 99, 99);
|
||||
|
||||
Reference in New Issue
Block a user