From f195c39db785805411d552b5a100983f9f7e3109 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 15 Nov 2024 09:26:15 +0100 Subject: [PATCH] Correctly implemented programs --- wash/src/wash/program/WashingProgram1.java | 32 ++++++-- wash/src/wash/program/WashingProgram2.java | 55 ++++++++++++- wash/src/wash/program/WashingProgram3.java | 17 ++-- wash/src/wash/program/WashingProgramStop.java | 80 ------------------- 4 files changed, 88 insertions(+), 96 deletions(-) delete mode 100644 wash/src/wash/program/WashingProgramStop.java diff --git a/wash/src/wash/program/WashingProgram1.java b/wash/src/wash/program/WashingProgram1.java index 5783210..581ce97 100644 --- a/wash/src/wash/program/WashingProgram1.java +++ b/wash/src/wash/program/WashingProgram1.java @@ -39,19 +39,39 @@ public final class WashingProgram1 extends ActorThread { // Lock the hatch io.lock(true); + // Let water into the machine water.send(new WashingMessage(this, WATER_FILL)); receive(); - // Instruct SpinController to rotate barrel slowly, back and forth - // Expect an acknowledgment in response. - spin.send(new WashingMessage(this, SPIN_SLOW)); + // Heat to 40 C + temp.send(new WashingMessage(this, TEMP_SET_40)); receive(); - // Spin for five simulated minutes (one minute == 60000 milliseconds) + // Keep the temperature for 30 min + Thread.sleep(30 * 60000 / Settings.SPEEDUP); + + // Drain + temp.send(new WashingMessage(this, TEMP_IDLE)); + receive(); + water.send(new WashingMessage(this, WATER_DRAIN)); + receive(); + + // Rinse 5*2 minutes in cold water + for(int a = 0; a < 5; a++) { + water.send(new WashingMessage(this, WATER_FILL)); + receive(); + + Thread.sleep(2 * 60000 / Settings.SPEEDUP); + + water.send(new WashingMessage(this, WATER_DRAIN)); + receive(); + } + + // Centrifuge for five minutes + spin.send(new WashingMessage(this, SPIN_FAST)); + receive(); Thread.sleep(5 * 60000 / Settings.SPEEDUP); - // Instruct SpinController to stop spin barrel spin. - // Expect an acknowledgment in response. spin.send(new WashingMessage(this, SPIN_OFF)); receive(); diff --git a/wash/src/wash/program/WashingProgram2.java b/wash/src/wash/program/WashingProgram2.java index e84e596..860801d 100644 --- a/wash/src/wash/program/WashingProgram2.java +++ b/wash/src/wash/program/WashingProgram2.java @@ -40,9 +40,62 @@ public final class WashingProgram2 extends ActorThread { // Lock the hatch io.lock(true); - // Spin for five simulated minutes (one minute == 60000 milliseconds) + // Let water into the machine + water.send(new WashingMessage(this, WATER_FILL)); + receive(); + + // Heat to 40 C + temp.send(new WashingMessage(this, TEMP_SET_40)); + receive(); + + // Keep the temperature for 20 min + Thread.sleep(20 * 60000 / Settings.SPEEDUP); + + // Drain + temp.send(new WashingMessage(this, TEMP_IDLE)); + receive(); + water.send(new WashingMessage(this, WATER_DRAIN)); + receive(); + + // Let water into the machine + water.send(new WashingMessage(this, WATER_FILL)); + receive(); + // Heat to 60 C + temp.send(new WashingMessage(this, TEMP_SET_60)); + receive(); + + // Keep the temperature for 20 min + Thread.sleep(30 * 60000 / Settings.SPEEDUP); + + // Kill the heat + temp.send(new WashingMessage(this, TEMP_IDLE)); + receive(); + + // Rinse 5*2 minutes in cold water + for(int a = 0; a < 5; a++) { + water.send(new WashingMessage(this, WATER_FILL)); + receive(); + + Thread.sleep(2 * 60000 / Settings.SPEEDUP); + + water.send(new WashingMessage(this, WATER_DRAIN)); + receive(); + } + + // Centrifuge for five minutes + spin.send(new WashingMessage(this, SPIN_FAST)); + receive(); Thread.sleep(5 * 60000 / Settings.SPEEDUP); + spin.send(new WashingMessage(this, SPIN_OFF)); + receive(); + + temp.send(new WashingMessage(this, TEMP_IDLE)); + receive(); + + water.send(new WashingMessage(this, WATER_DRAIN)); + receive(); + // Now that the barrel has stopped, it is safe to open the hatch. io.lock(false); System.out.println("WashingProgram2 Finished..."); diff --git a/wash/src/wash/program/WashingProgram3.java b/wash/src/wash/program/WashingProgram3.java index c7b7f26..79ee344 100644 --- a/wash/src/wash/program/WashingProgram3.java +++ b/wash/src/wash/program/WashingProgram3.java @@ -41,17 +41,16 @@ public final class WashingProgram3 extends ActorThread { io.lock(true); // Switch off heating - // temp.send(new WashingMessage(this, TEMP_IDLE)); - // System.out.println(receive()); - // temp.send(new WashingMessage(this, TEMP_SET_40)); - // System.out.println(receive()); + temp.send(new WashingMessage(this, TEMP_IDLE)); + receive(); - temp.send(new WashingMessage(this, WATER_FILL)); - System.out.println(receive()); - temp.send(new WashingMessage(this, WATER_DRAIN)); - System.out.println(receive()); + // Spin off just to be sure + spin.send(new WashingMessage(this, SPIN_OFF)); + receive(); - // Thread.sleep(5 * 60000 / Settings.SPEEDUP); + // Drain water + water.send(new WashingMessage(this, WATER_DRAIN)); + receive(); // Unlock hatch io.lock(false); diff --git a/wash/src/wash/program/WashingProgramStop.java b/wash/src/wash/program/WashingProgramStop.java deleted file mode 100644 index 410d596..0000000 --- a/wash/src/wash/program/WashingProgramStop.java +++ /dev/null @@ -1,80 +0,0 @@ -package wash.program; - -import actor.ActorThread; -import wash.control.WashingMessage; -import wash.io.WashingIO; - -import static wash.control.WashingMessage.Order.*; - -/** - * Program 3 for washing machine. This also serves as an example of how washing - * programs can be structured. - * - * This short program stops all regulation of temperature and water levels, - * stops the barrel from spinning, and drains the machine of water. - * - * It can be used after an emergency stop (program 0) or a power failure. - */ -public final class WashingProgramStop extends ActorThread { - - private WashingIO io; - private ActorThread temp; - private ActorThread water; - private ActorThread spin; - - public WashingProgramStop(WashingIO io, - ActorThread temp, - ActorThread water, - ActorThread spin) - { - this.io = io; - this.temp = temp; - this.water = water; - this.spin = spin; - } - - @Override - public void run() { - try { - System.out.println("WashingProgramStop Starting..."); - - // Switch off heating - temp.send(new WashingMessage(this, TEMP_IDLE)); - - // Wait for temperature controller to acknowledge - WashingMessage ack1 = receive(); - System.out.println("got " + ack1); - - // Drain barrel, which may take some time. To ensure the barrel - // is drained before we continue, an acknowledgment is required. - water.send(new WashingMessage(this, WATER_DRAIN)); - WashingMessage ack2 = receive(); // wait for acknowledgment - System.out.println("got " + ack2); - - // Now that the barrel is drained, we can turn off water regulation. - water.send(new WashingMessage(this, WATER_IDLE)); - WashingMessage ack3 = receive(); // wait for acknowledgment - System.out.println("got " + ack3); - - // Switch off spin. We expect an acknowledgment, to ensure - // the hatch isn't opened while the barrel is spinning. - spin.send(new WashingMessage(this, SPIN_OFF)); - WashingMessage ack4 = receive(); // wait for acknowledgment - System.out.println("got " + ack4); - - // Unlock hatch - io.lock(false); - - System.out.println("WashingProgramStop Finished..."); - } catch (InterruptedException e) { - System.out.println("WashingProgramStop Interrupted..."); - // If we end up here, it means the program was interrupt()'ed: - // set all controllers to idle - - temp.send(new WashingMessage(this, TEMP_IDLE)); - water.send(new WashingMessage(this, WATER_IDLE)); - spin.send(new WashingMessage(this, SPIN_OFF)); - System.out.println("washing stop program terminated"); - } - } -}