-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |