diff --git a/.idea/misc.xml b/.idea/misc.xml index 62592b9..51124c6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,10 +1,13 @@ + + + - + diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..71f77f4 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,11 @@ +import process.SecondOrderSystem; + +/** + * Created by marlon on 6/13/14. + */ +public class Main { + public static void main(String[] args){ + SecondOrderSystem G = new SecondOrderSystem("G"); + G.start(); + } +} diff --git a/src/main/java/gui/Gui.java b/src/main/java/gui/Gui.java new file mode 100644 index 0000000..f41d56e --- /dev/null +++ b/src/main/java/gui/Gui.java @@ -0,0 +1,66 @@ +package gui; + +import javafx.beans.property.*; +import javafx.fxml.FXML; +import javafx.scene.chart.CategoryAxis; +import javafx.scene.chart.LineChart; +import javafx.scene.chart.NumberAxis; +import javafx.scene.chart.XYChart; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import java.sql.Timestamp; + +/** + * Created by marlon on 6/16/14. + */ +public class Gui { + private static final int TRENDING_DATA_LIMIT = 50; + private static final long SAMPLING_TIME = 500; + + @FXML private TextField tankAreaTextField; + @FXML private TextField gravityTextField; + @FXML private TextField obstructionTextField; + @FXML private TextField samplingTimeTextField; + @FXML private TextField kp; + @FXML private TextField Ti; + @FXML private Button applyButton; + @FXML private CategoryAxis categoryAxis; + @FXML private NumberAxis numberAxis; + @FXML private LineChart trendings; + + private DoubleProperty output; + private long lastUpdate; + private ObjectProperty timestamp; + + private final XYChart.Series systemOutput = new XYChart.Series<>(); + + public Gui() { + output = new SimpleDoubleProperty(this, "systemOutput", 0.0); + lastUpdate = System.currentTimeMillis(); + timestamp = new ObjectPropertyBase(new Timestamp(System.currentTimeMillis())) { + @Override protected void invalidated() { + if ((System.currentTimeMillis() - lastUpdate) > SAMPLING_TIME) { + systemOutput.getData().add(new XYChart.Data<>(output.getValue(), new Timestamp(System.currentTimeMillis()))); + while (systemOutput.getData().size() > TRENDING_DATA_LIMIT) { + systemOutput.getData().remove(0); + } + } + } + @Override public Object getBean() { + return this; + } + @Override public String getName() { + return "timestamp"; + } + }; + + numberAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(numberAxis) { + @Override + public String toString(Number object) { + return String.format("%6.2f", object); + } + }); + trendings.getData().add(systemOutput); + } + +} diff --git a/src/main/java/process/FirstOrderSystem.java b/src/main/java/process/FirstOrderSystem.java new file mode 100644 index 0000000..0d1e710 --- /dev/null +++ b/src/main/java/process/FirstOrderSystem.java @@ -0,0 +1,36 @@ +package process; + +/** + * Created by marlon on 6/16/14. + * + * The transfer function is in form: + * + * G(s) = zero + * ------ + * s+pole + * + */ +public class FirstOrderSystem { + private double zero; + private double pole; + + public FirstOrderSystem(double zero) { + this.zero = zero; + } + + public double getZero() { + return zero; + } + + public void setZero(double zero) { + this.zero = zero; + } + + public double getPole() { + return pole; + } + + public void setPole(double pole) { + this.pole = pole; + } +} diff --git a/src/main/java/process/SecondOrderSystem.java b/src/main/java/process/SecondOrderSystem.java new file mode 100644 index 0000000..851fcef --- /dev/null +++ b/src/main/java/process/SecondOrderSystem.java @@ -0,0 +1,58 @@ +package process; + +/** + * Created by marlon on 6/11/14. + */ +public class SecondOrderSystem extends Thread { + + public static enum Order{FIRST, SECOND, THIRD} + + private double output; + private double input; +// private double tau; +// private double timeConstant; +// private double delayTime; +// private double riseTime; +// private double peakTime; +// private double maximumOvershoot; +// private double settlingTime; + private double currentTime; + private boolean simulationActivated; + private double[] delayedInput; + private double[] delayedOutput; + private double samplingTime; + private long period; + + public SecondOrderSystem(String name) { + super(name); + input = 0; + output = 0; + currentTime = System.currentTimeMillis(); + simulationActivated = true; + delayedInput = new double[1]; + delayedOutput = new double[1]; + samplingTime = 0.01; + period = (long) (samplingTime*10000); + } + + @Override + public void run() { + while(simulationActivated){ + output = -(delayedOutput[0]*(samplingTime - 35.14)/(samplingTime + 35.14)) + + (input*((0.66*samplingTime)/(samplingTime + 35.14))) + + (delayedInput[0]*((0.66*samplingTime)/(samplingTime+35.14))); + + try { + Thread.sleep(period); + } catch (InterruptedException e) { + e.printStackTrace(); + simulationActivated = false; + } + + delayedOutput[0] = output; + delayedInput[0] = input; + System.out.println("input:" + input + ". \t" + "output:" + output); + } + } + +}