Skip to content

Commit

Permalink
GUI Created
Browse files Browse the repository at this point in the history
  • Loading branch information
marl0rd committed Jun 17, 2014
1 parent 0f4113a commit 611d984
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
66 changes: 66 additions & 0 deletions src/main/java/gui/Gui.java
Original file line number Diff line number Diff line change
@@ -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<Double, Timestamp> trendings;

private DoubleProperty output;
private long lastUpdate;
private ObjectProperty<Timestamp> timestamp;

private final XYChart.Series<Double, Timestamp> systemOutput = new XYChart.Series<>();

public Gui() {
output = new SimpleDoubleProperty(this, "systemOutput", 0.0);
lastUpdate = System.currentTimeMillis();
timestamp = new ObjectPropertyBase<Timestamp>(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);
}

}
36 changes: 36 additions & 0 deletions src/main/java/process/FirstOrderSystem.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
58 changes: 58 additions & 0 deletions src/main/java/process/SecondOrderSystem.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

}

0 comments on commit 611d984

Please sign in to comment.