Skip to content

Commit

Permalink
First Stable Test
Browse files Browse the repository at this point in the history
  • Loading branch information
marl0rd committed Jun 24, 2014
1 parent 0d044ab commit d3aea8e
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 48 deletions.
67 changes: 33 additions & 34 deletions src/main/java/gui/GuiController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gui;

import process.ConicalTankProcess;
import continuous.FirstOrderSystem;
import continuous.PIController;
import continuous.PITuning;
Expand All @@ -18,6 +17,7 @@
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import simulation.*;
import source.Source;
import util.Preferences;
import java.io.IOException;
import java.sql.Date;
Expand All @@ -34,36 +34,34 @@ public class GuiController extends AnchorPane {
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("mm:ss.SSS");

// ********** Fields **********//
private ConicalTankProcess conicalTank;
private Source source;
private FirstOrderSystem process;
private PIController controller;
private PITuning piTuning;
private Loop loop;

@FXML private TextField heightSetPointTextField;
@FXML private TextField flowSetPointTextField;
@FXML private Button newProcessParametersButton;
@FXML private Button newControlParametersButton;
@FXML private MenuItem startSimulationMenuItem;
@FXML private MenuItem stopSimulationMenuItem;
@FXML private MenuItem preferencesMenuItem;
@FXML private Label heightOperationPointLabel;
@FXML private Label inflowOperationPointLabel;
@FXML private Label samplingTimeLabel;
@FXML private Label kpLabel;
@FXML private Label kiLabel;
@FXML private Label integralTimeLabel;
@FXML private Label tauLabel;
@FXML private Label gainLabel;
@FXML private Label inputLabel;
@FXML private Label outputLabel;
@FXML private CategoryAxis categoryAxis;
@FXML private NumberAxis numberAxis;
@FXML private LineChart<String, Double> trendings;
@FXML private ListView<String> consoleListView;
@FXML private TextField dampingRatioTextField;
@FXML private TextField settlingTimeTextField;
private XYChart.Series<String, Double> outputTrendingSeries;
@FXML private ChoiceBox<Preferences.ControlType> controlTypeChoiceBox;
@FXML private ChoiceBox<Preferences.Source> sourceChoiceBox;
@FXML private ChoiceBox<Preferences.ControllerType> controllerChoiceBox;
@FXML private ChoiceBox<String> processChoiceBox;
@FXML private TextField sourceValueTextField;
@FXML private MenuItem startSimulationMenuItem;
@FXML private MenuItem stopSimulationMenuItem;
@FXML private MenuItem preferencesMenuItem;
@FXML private Label inputValueLabel;
@FXML private Label samplingTimeLabel;
@FXML private Label kpLabel;
@FXML private Label kiLabel;
@FXML private Label integralTimeLabel;
@FXML private Label tauLabel;
@FXML private Label gainLabel;
@FXML private Label outputValueLabel;
@FXML private CategoryAxis categoryAxis;
@FXML private NumberAxis numberAxis;
@FXML private LineChart<String, Double> trendings;
@FXML private TextField dampingRatioTextField;
@FXML private TextField settlingTimeTextField;
private XYChart.Series<String, Double> outputTrendingSeries;

// ********** Constructor **********//
public GuiController() {
Expand All @@ -76,18 +74,18 @@ public GuiController() {
throw new RuntimeException(exception);
}

conicalTank = new ConicalTankProcess();
process = conicalTank.getTransferFunction();
process = new FirstOrderSystem();
controller = new PIController();
piTuning = new PITuning(controller, process);
loop = new Loop(process, controller);

initializeLineChart();
initializeGraphics();
registerListeners();
}

// ********** Methods **********//
private void initializeLineChart() {
private void initializeGraphics() {
//LineCharts
outputTrendingSeries = new XYChart.Series<>();
numberAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(numberAxis) {
@Override
Expand All @@ -96,16 +94,17 @@ public String toString(Number object) {
}
});
trendings.getData().add(outputTrendingSeries);

// ChoiceBoxes
controlTypeChoiceBox.getItems().addAll(Preferences.ControlType.values());
sourceChoiceBox.getItems().addAll(Preferences.Source.values());

}

private void registerListeners() {
// GUI Changes:
startSimulationMenuItem.setOnAction(value -> startSimulation());
stopSimulationMenuItem.setOnAction(value -> stopSimulation());

newProcessParametersButton.setOnAction(value -> recalculate());
newControlParametersButton.setOnAction(value -> recalculate());

preferencesMenuItem.setOnAction(value -> showPreferences());

// The loop inform about new values, so they are displayed in the gui:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/simulation/FirstOrderSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/**
* Created by marlon on 6/17/14.
*
* | gain |
* | gain |
* simulation.input ------>| --------- |-------> simulation.output
* | tau*s + 1 |
* | tau*s + 1 |
*
*/
public class FirstOrderSimulator extends Thread{
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/source/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package source;

import util.Preferences;

/**
* One constant value function
*/
public class Constant extends Source implements Runnable{
private double value;

public Constant() {
samplingTime = Preferences.samplingTime;
simulationMode = Preferences.simulationMode;
}

@Override
public void run() {
started = true;
while (started){
output = value;
delay();
}
}

public void delay(){
// The samplingTime of simulation is based in second, the sleep method is based in milliseconds
try {
Thread.sleep((long) ((samplingTime * simulationMode.factor)* 1000));
} catch (InterruptedException e) {
started = false;
}
}

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sources;
package source;

/**
* Function of Pulse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sources;
package source;

/**
* Ramp Function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sources;
package source;

/**
* Function random
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sources;
package source;

/**
* Created by marlon on 6/24/14.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/source/Source.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package source;

import util.Preferences;

/**
* Created by marlon on 6/24/14.
*/
public class Source {
protected double samplingTime;
protected Preferences.SimulationMode simulationMode;
protected double output;
protected boolean started;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sources;
package source;

/**
* Step Function
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/sources/Constant.java

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/util/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ public static enum SimulationMode {
}
}
public static enum LoopType {CLOSE_LOOP, OPEN_LOOP}
public static enum ControlType {CLASSIC, ADAPTATIVE}
public static enum ControllerType {P, PI, PID}
public static enum Source {CONSTANT, PUSE_GENERATOR, RAMP, RANDOM, SINE_WAVE, STEP}

private static final SimulationMode DEFAULT_SIMULATION_MODE = SimulationMode.SLOW;
private static final LoopType DEFAULT_LOOP_TYPE = LoopType.CLOSE_LOOP;
private static final ControlType DEFAULT_CONTROL_TYPE = ControlType.ADAPTATIVE;
private static final Source DEFAULT_SOURCE = Source.CONSTANT;
private static final double DEFAULT_SAMPLING_TIME = 0.1;


public static SimulationMode simulationMode = DEFAULT_SIMULATION_MODE;
public static double samplingTime = DEFAULT_SAMPLING_TIME;
public static LoopType loopType = DEFAULT_LOOP_TYPE;
public static ControlType controlType = DEFAULT_CONTROL_TYPE;
public static Source source = DEFAULT_SOURCE;

}

0 comments on commit d3aea8e

Please sign in to comment.