Skip to content

Commit

Permalink
Merge pull request #5 from hsu-aut/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aljoshakoecher authored May 28, 2020
2 parents 89e2493 + 9d57ab6 commit ebe6aca
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.hsu-hh.aut</groupId>
<artifactId>ft-lab-simulation</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<name>FT Lab Simulation</name>
<description>Simple Simulation of an automated lab plant</description>

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/model/elements/StorageModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
37 changes: 30 additions & 7 deletions src/main/java/model/simulation/FtPlantSimulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -321,6 +330,11 @@ public void update() {
} else {
b1_s23.deactivate();
}

if (conveyorLeft.getRelativeWorkpiecePosition() == 0) {
conveyorLeft.removeWorkpiece();
this.wpState = WorkpieceState.AtStorage;
}
break;
}
case OnUpperConveyor: {
Expand All @@ -332,6 +346,12 @@ public void update() {
} else {
b1_s24.deactivate();
}

if (conveyorTop.getRelativeWorkpiecePosition() == 0) {
conveyorTop.removeWorkpiece();
this.wpState = WorkpieceState.AtStorage;
}

break;
}
}
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/model/simulation/SensorTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit ebe6aca

Please sign in to comment.