From d3aea8ee6937482c2294e33c1c9e0e91b68eff2d Mon Sep 17 00:00:00 2001 From: marlon Date: Tue, 24 Jun 2014 13:56:05 -0500 Subject: [PATCH] First Stable Test --- src/main/java/gui/GuiController.java | 67 +++++++++---------- .../java/simulation/FirstOrderSimulator.java | 4 +- src/main/java/source/Constant.java | 41 ++++++++++++ .../{sources => source}/PulseGenerator.java | 2 +- src/main/java/{sources => source}/Ramp.java | 2 +- src/main/java/{sources => source}/Random.java | 2 +- .../java/{sources => source}/SineWave.java | 2 +- src/main/java/source/Source.java | 14 ++++ src/main/java/{sources => source}/Step.java | 2 +- src/main/java/sources/Constant.java | 7 -- src/main/java/util/Preferences.java | 8 +++ 11 files changed, 103 insertions(+), 48 deletions(-) create mode 100644 src/main/java/source/Constant.java rename src/main/java/{sources => source}/PulseGenerator.java (81%) rename src/main/java/{sources => source}/Ramp.java (78%) rename src/main/java/{sources => source}/Random.java (79%) rename src/main/java/{sources => source}/SineWave.java (83%) create mode 100644 src/main/java/source/Source.java rename src/main/java/{sources => source}/Step.java (78%) delete mode 100644 src/main/java/sources/Constant.java diff --git a/src/main/java/gui/GuiController.java b/src/main/java/gui/GuiController.java index 901cf9f..342f367 100644 --- a/src/main/java/gui/GuiController.java +++ b/src/main/java/gui/GuiController.java @@ -1,6 +1,5 @@ package gui; -import process.ConicalTankProcess; import continuous.FirstOrderSystem; import continuous.PIController; import continuous.PITuning; @@ -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; @@ -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 trendings; - @FXML private ListView consoleListView; - @FXML private TextField dampingRatioTextField; - @FXML private TextField settlingTimeTextField; - private XYChart.Series outputTrendingSeries; + @FXML private ChoiceBox controlTypeChoiceBox; + @FXML private ChoiceBox sourceChoiceBox; + @FXML private ChoiceBox controllerChoiceBox; + @FXML private ChoiceBox 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 trendings; + @FXML private TextField dampingRatioTextField; + @FXML private TextField settlingTimeTextField; + private XYChart.Series outputTrendingSeries; // ********** Constructor **********// public GuiController() { @@ -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 @@ -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: diff --git a/src/main/java/simulation/FirstOrderSimulator.java b/src/main/java/simulation/FirstOrderSimulator.java index cffaff1..ed9f2fd 100644 --- a/src/main/java/simulation/FirstOrderSimulator.java +++ b/src/main/java/simulation/FirstOrderSimulator.java @@ -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{ diff --git a/src/main/java/source/Constant.java b/src/main/java/source/Constant.java new file mode 100644 index 0000000..5badf22 --- /dev/null +++ b/src/main/java/source/Constant.java @@ -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; + } +} diff --git a/src/main/java/sources/PulseGenerator.java b/src/main/java/source/PulseGenerator.java similarity index 81% rename from src/main/java/sources/PulseGenerator.java rename to src/main/java/source/PulseGenerator.java index 1abb7e6..3d79c2e 100644 --- a/src/main/java/sources/PulseGenerator.java +++ b/src/main/java/source/PulseGenerator.java @@ -1,4 +1,4 @@ -package sources; +package source; /** * Function of Pulse diff --git a/src/main/java/sources/Ramp.java b/src/main/java/source/Ramp.java similarity index 78% rename from src/main/java/sources/Ramp.java rename to src/main/java/source/Ramp.java index 17d209b..ac56755 100644 --- a/src/main/java/sources/Ramp.java +++ b/src/main/java/source/Ramp.java @@ -1,4 +1,4 @@ -package sources; +package source; /** * Ramp Function diff --git a/src/main/java/sources/Random.java b/src/main/java/source/Random.java similarity index 79% rename from src/main/java/sources/Random.java rename to src/main/java/source/Random.java index 4ec7342..0413363 100644 --- a/src/main/java/sources/Random.java +++ b/src/main/java/source/Random.java @@ -1,4 +1,4 @@ -package sources; +package source; /** * Function random diff --git a/src/main/java/sources/SineWave.java b/src/main/java/source/SineWave.java similarity index 83% rename from src/main/java/sources/SineWave.java rename to src/main/java/source/SineWave.java index e945286..69f6747 100644 --- a/src/main/java/sources/SineWave.java +++ b/src/main/java/source/SineWave.java @@ -1,4 +1,4 @@ -package sources; +package source; /** * Created by marlon on 6/24/14. diff --git a/src/main/java/source/Source.java b/src/main/java/source/Source.java new file mode 100644 index 0000000..9b703fa --- /dev/null +++ b/src/main/java/source/Source.java @@ -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; + +} diff --git a/src/main/java/sources/Step.java b/src/main/java/source/Step.java similarity index 78% rename from src/main/java/sources/Step.java rename to src/main/java/source/Step.java index 81853a9..27d4281 100644 --- a/src/main/java/sources/Step.java +++ b/src/main/java/source/Step.java @@ -1,4 +1,4 @@ -package sources; +package source; /** * Step Function diff --git a/src/main/java/sources/Constant.java b/src/main/java/sources/Constant.java deleted file mode 100644 index aab1f37..0000000 --- a/src/main/java/sources/Constant.java +++ /dev/null @@ -1,7 +0,0 @@ -package sources; - -/** - * One constant value function - */ -public class Constant extends Thread { -} diff --git a/src/main/java/util/Preferences.java b/src/main/java/util/Preferences.java index 753af03..d161acd 100644 --- a/src/main/java/util/Preferences.java +++ b/src/main/java/util/Preferences.java @@ -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; }