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 */
|
/** Recursive listener method */
|
||||||
public void listener() {
|
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()) {
|
switch (m.order()) {
|
||||||
case Order.SPIN_OFF -> spin.setMode(WashingIO.Spin.IDLE);
|
case Order.SPIN_OFF -> spin.setMode(WashingIO.Spin.IDLE);
|
||||||
|
@ -52,7 +61,7 @@ public final class ControllerSpin extends ActorThread<WashingMessage> {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loop() {
|
private void loop() throws InterruptedException {
|
||||||
io.setSpinMode(spinMode);
|
io.setSpinMode(spinMode);
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
@ -60,13 +69,17 @@ public final class ControllerSpin extends ActorThread<WashingMessage> {
|
||||||
changed = false;
|
changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(60000 / Settings.SPEEDUP);
|
Thread.sleep(60000 / Settings.SPEEDUP);
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
loop();
|
loop();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,20 @@ public final class ControllerTemp extends ActorThread<WashingMessage> {
|
||||||
heater.start();
|
heater.start();
|
||||||
|
|
||||||
while (true) {
|
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()) {
|
switch (m.order()) {
|
||||||
case Order.TEMP_SET_40 -> heater.setTarget(40);
|
case Order.TEMP_SET_40 -> heater.setTarget(40);
|
||||||
case Order.TEMP_SET_60 -> heater.setTarget(60);
|
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 -> {
|
default -> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +64,13 @@ public final class ControllerTemp extends ActorThread<WashingMessage> {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
double current;
|
double current;
|
||||||
|
try {
|
||||||
while (!isInterrupted()) {
|
while (!isInterrupted()) {
|
||||||
current = io.getTemperature();
|
current = io.getTemperature();
|
||||||
|
|
||||||
if (io.getWaterLevel() == 0) {
|
if (io.getWaterLevel() == 0) {
|
||||||
io.heat(false);
|
io.heat(false);
|
||||||
usleep(60000 / Settings.SPEEDUP);
|
sleep(60000 / Settings.SPEEDUP);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,15 +80,20 @@ public final class ControllerTemp extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
else if (current >= target) {
|
else if (current >= target) {
|
||||||
io.heat(false);
|
io.heat(false);
|
||||||
|
|
||||||
if (!hovering) {
|
if (!hovering) {
|
||||||
sendAck();
|
sendAck();
|
||||||
hovering = true;
|
hovering = true;
|
||||||
usleep(60000 / Settings.SPEEDUP);
|
sleep(60000 / Settings.SPEEDUP);
|
||||||
continue;
|
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 actor.ActorThread;
|
||||||
import wash.control.WashingMessage.Order;
|
import wash.control.WashingMessage.Order;
|
||||||
import wash.io.WashingIO;
|
import wash.io.WashingIO;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
public class ControllerWater extends ActorThread<WashingMessage> {
|
public class ControllerWater extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
|
@ -26,9 +24,13 @@ public class ControllerWater extends ActorThread<WashingMessage> {
|
||||||
public void run() {
|
public void run() {
|
||||||
waterpid.start();
|
waterpid.start();
|
||||||
while (true) {
|
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()) {
|
switch (m.order()) {
|
||||||
case Order.WATER_DRAIN -> waterpid.setTarget(0);
|
case Order.WATER_DRAIN -> waterpid.setTarget(0);
|
||||||
case Order.WATER_FILL -> waterpid.setTarget(20);
|
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 {
|
public final class WaterPid extends Thread {
|
||||||
private double target;
|
private double target;
|
||||||
private final double tolerance; // Acceptable range around target
|
private final double tolerance; // Acceptable range around target
|
||||||
|
|
Loading…
Reference in a new issue