Controllers (Broken)
This commit is contained in:
parent
22410c419f
commit
819da6a4c3
3 changed files with 57 additions and 32 deletions
|
@ -25,7 +25,16 @@ public final class ControllerSpin extends ActorThread<WashingMessage> {
|
|||
|
||||
/** Recursive listener method */
|
||||
public void listener() {
|
||||
m = poll(60000 / Settings.SPEEDUP).orElse(new WashingMessage(this, Order.NOOP));
|
||||
if(isInterrupted()) {
|
||||
spin.interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
m = take();
|
||||
} catch (Exception e) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
switch (m.order()) {
|
||||
case Order.SPIN_OFF -> spin.setMode(WashingIO.Spin.IDLE);
|
||||
|
@ -52,7 +61,7 @@ public final class ControllerSpin extends ActorThread<WashingMessage> {
|
|||
changed = true;
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
private void loop() throws InterruptedException {
|
||||
io.setSpinMode(spinMode);
|
||||
|
||||
if (changed) {
|
||||
|
@ -60,13 +69,17 @@ public final class ControllerSpin extends ActorThread<WashingMessage> {
|
|||
changed = false;
|
||||
}
|
||||
|
||||
usleep(60000 / Settings.SPEEDUP);
|
||||
Thread.sleep(60000 / Settings.SPEEDUP);
|
||||
loop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
loop();
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,17 +23,20 @@ public final class ControllerTemp extends ActorThread<WashingMessage> {
|
|||
heater.start();
|
||||
|
||||
while (true) {
|
||||
m = poll(60000 / Settings.SPEEDUP).orElse(new WashingMessage(this, Order.NOOP));
|
||||
try {
|
||||
m = take();
|
||||
} catch (Exception e) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
switch (m.order()) {
|
||||
case Order.TEMP_SET_40 -> heater.setTarget(40);
|
||||
case Order.TEMP_SET_60 -> heater.setTarget(60);
|
||||
case Order.TEMP_IDLE -> heater.setTarget(0);
|
||||
case Order.TEMP_IDLE -> heater.setTarget(0); // TODO: Error
|
||||
default -> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,12 +64,13 @@ public final class ControllerTemp extends ActorThread<WashingMessage> {
|
|||
@Override
|
||||
public void run() {
|
||||
double current;
|
||||
try {
|
||||
while (!isInterrupted()) {
|
||||
current = io.getTemperature();
|
||||
|
||||
if (io.getWaterLevel() == 0) {
|
||||
io.heat(false);
|
||||
usleep(60000 / Settings.SPEEDUP);
|
||||
sleep(60000 / Settings.SPEEDUP);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -76,15 +80,20 @@ public final class ControllerTemp extends ActorThread<WashingMessage> {
|
|||
|
||||
else if (current >= target) {
|
||||
io.heat(false);
|
||||
if(!hovering) {
|
||||
|
||||
if (!hovering) {
|
||||
sendAck();
|
||||
hovering = true;
|
||||
usleep(60000 / Settings.SPEEDUP);
|
||||
sleep(60000 / Settings.SPEEDUP);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
usleep(60000 / Settings.SPEEDUP);
|
||||
sleep(60000 / Settings.SPEEDUP);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
io.heat(false);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package wash.control;
|
|||
import actor.ActorThread;
|
||||
import wash.control.WashingMessage.Order;
|
||||
import wash.io.WashingIO;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class ControllerWater extends ActorThread<WashingMessage> {
|
||||
|
||||
|
@ -26,9 +24,13 @@ public class ControllerWater extends ActorThread<WashingMessage> {
|
|||
public void run() {
|
||||
waterpid.start();
|
||||
while (true) {
|
||||
m = poll(60000 / Settings.SPEEDUP).orElse(new WashingMessage(this, Order.NOOP));
|
||||
// m = poll(60000 / Settings.SPEEDUP).orElse(new WashingMessage(this, Order.NOOP));
|
||||
try {
|
||||
m = take();
|
||||
} catch (Exception e) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// io.getWaterLevel();
|
||||
switch (m.order()) {
|
||||
case Order.WATER_DRAIN -> waterpid.setTarget(0);
|
||||
case Order.WATER_FILL -> waterpid.setTarget(20);
|
||||
|
@ -40,6 +42,7 @@ public class ControllerWater extends ActorThread<WashingMessage> {
|
|||
}
|
||||
}
|
||||
|
||||
/** A pid controller that is not actually a pid controller */
|
||||
public final class WaterPid extends Thread {
|
||||
private double target;
|
||||
private final double tolerance; // Acceptable range around target
|
||||
|
|
Loading…
Reference in a new issue