diff --git a/pom.xml b/pom.xml
index 8bed6b0..42bc141 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
de.hsu-hh.aut
ft-lab-simulation
- 1.0.0
+ 1.0.1
FT Lab Simulation
Simple Simulation of an automated lab plant
diff --git a/src/main/java/model/elements/StorageModule.java b/src/main/java/model/elements/StorageModule.java
index 77b2cfe..5c35f73 100644
--- a/src/main/java/model/elements/StorageModule.java
+++ b/src/main/java/model/elements/StorageModule.java
@@ -3,8 +3,20 @@
public class StorageModule {
+ // TODO: This whole class is currently more or less useless.
+ // It could in the future be used to delay getting of the workpiece and for getting different workpiece colors (randomly or in a row)
+
+ private boolean gettingWorkpiece = false;
+
public boolean isGettingWorkpiece() {
- return true; //this.gettingWorkpiece;
+ // return gettingWorkpiece and reset it
+ boolean gettingWorkpiece = this.gettingWorkpiece;
+ this.gettingWorkpiece = false;
+ return gettingWorkpiece;
+ }
+
+ public void getWorkpiece() {
+ this.gettingWorkpiece = true;
}
}
diff --git a/src/main/java/model/simulation/FtPlantSimulation.java b/src/main/java/model/simulation/FtPlantSimulation.java
index 99185ca..77e3c0f 100644
--- a/src/main/java/model/simulation/FtPlantSimulation.java
+++ b/src/main/java/model/simulation/FtPlantSimulation.java
@@ -16,6 +16,7 @@
import gui.element.shape.ShapeHelper;
import javafx.scene.paint.Color;
import model.elements.BinarySensor;
+import model.elements.BinarySwitch;
import model.elements.Conveyor;
import model.elements.Gate;
import model.elements.SensorDefinition;
@@ -137,16 +138,23 @@ public void update() {
switch (this.wpState) {
case AtStorage: {
- setRandomWorkpieceColor();
Conveyor conveyor1 = (Conveyor) this.updateables.get(SimulationElementName.Conveyor1);
BinarySensor sensorConveyor1 = this.sensors.get(SensorDefinition.B1_S02);
+ BinarySwitch b1_S06 = (BinarySwitch) this.sensors.get(SensorDefinition.B1_S06);
+
+ if(b1_S06.getState() == true) {
+ setRandomWorkpieceColor();
+ this.storageModule.getWorkpiece();
+ }
+
if (this.storageModule.isGettingWorkpiece()) {
this.controller.log("Simulation update: Getting workpiece from storage");
- this.wpState = WorkpieceState.OnConveyor1;
// assumption: workpiece gets always placed on first conveyor so that sensor can detect it
sensorConveyor1.activate();
conveyor1.addWorkpiece(true);
+ this.wpState = WorkpieceState.OnConveyor1;
}
+
break;
}
case OnConveyor1: {
@@ -254,7 +262,7 @@ public void update() {
BinarySensor b1_s17 = this.sensors.get(SensorDefinition.B1_S17);
BinarySensor b1_s09 = this.sensors.get(SensorDefinition.B1_S09);
- if (conveyor4.getRelativeWorkpiecePosition() < 40 && conveyor4.getRelativeWorkpiecePosition() > 30) {
+ if (conveyor4.getRelativeWorkpiecePosition() < 35 && conveyor4.getRelativeWorkpiecePosition() > 20) {
b1_s17.activate();
} else {
b1_s17.deactivate();
@@ -273,6 +281,7 @@ public void update() {
if (turntable.isHorizontal() && turntable.getConveyor().getMotorLeft().isOn()) {
this.controller.log("Simulation update: Moving workpiece onto the turntable");
this.wpState = WorkpieceState.OnTurntable;
+ b1_s09.deactivate();
conveyor4.removeWorkpiece();
conveyorOnTurntable.addWorkpiece(true);
}
@@ -302,7 +311,7 @@ public void update() {
conveyorOnTurntable.removeWorkpiece();
conveyorLeft.addWorkpiece(true);
}
- if (turntable.isVertical() && conveyorLeft.getMotorLeft().isOn()) {
+ if (turntable.isVertical() && conveyorTop.getMotorLeft().isOn()) {
this.controller.log("Moving workpiece to upper conveyor");
this.wpState = WorkpieceState.OnUpperConveyor;
conveyorOnTurntable.removeWorkpiece();
@@ -321,6 +330,11 @@ public void update() {
} else {
b1_s23.deactivate();
}
+
+ if (conveyorLeft.getRelativeWorkpiecePosition() == 0) {
+ conveyorLeft.removeWorkpiece();
+ this.wpState = WorkpieceState.AtStorage;
+ }
break;
}
case OnUpperConveyor: {
@@ -332,6 +346,12 @@ public void update() {
} else {
b1_s24.deactivate();
}
+
+ if (conveyorTop.getRelativeWorkpiecePosition() == 0) {
+ conveyorTop.removeWorkpiece();
+ this.wpState = WorkpieceState.AtStorage;
+ }
+
break;
}
}
@@ -369,12 +389,15 @@ private void triggerColorSensors() {
BinarySensor sensorRight = this.sensors.get(SensorDefinition.B1_S05);
BinarySensor sensorLeft = this.sensors.get(SensorDefinition.B1_S04);
- SensorTrigger sensorRightTrigger = new SensorTrigger(sensorRight, numberOfMagnetsRight, 200);
- SensorTrigger sensorLeftTrigger = new SensorTrigger(sensorLeft, numberOfMagnetsLeft, 200);
+ SensorTrigger sensorRightTrigger = new SensorTrigger(sensorRight, numberOfMagnetsRight, 300);
+ SensorTrigger sensorLeftTrigger = new SensorTrigger(sensorLeft, numberOfMagnetsLeft, 300);
ExecutorService executorRight = Executors.newCachedThreadPool();
+ ExecutorService executorLeft = Executors.newCachedThreadPool();
executorRight.submit(sensorRightTrigger);
- executorRight.submit(sensorLeftTrigger);
+ executorLeft.submit(sensorLeftTrigger);
+
+ executorLeft.shutdown();
executorRight.shutdown();
}
diff --git a/src/main/java/model/simulation/SensorTrigger.java b/src/main/java/model/simulation/SensorTrigger.java
index 244e930..e909f0a 100644
--- a/src/main/java/model/simulation/SensorTrigger.java
+++ b/src/main/java/model/simulation/SensorTrigger.java
@@ -17,16 +17,16 @@ public class SensorTrigger implements Runnable {
public void run() {
for (int i = 0; i < triggerAmount; i++) {
System.out.println("trigger sensor: " + this.sensor.getTagName() + " for time: " + i);
- this.sensor.activate();
try {
Thread.sleep(this.waitTime);
+ this.sensor.activate();
+ Thread.sleep(this.waitTime);
+ this.sensor.deactivate();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
- this.sensor.deactivate();
}
}