Programs
This commit is contained in:
parent
642a658259
commit
71db7d9e8c
5 changed files with 60 additions and 27 deletions
25
wash/src/wash/program/EmptyProgram.java
Normal file
25
wash/src/wash/program/EmptyProgram.java
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package wash.program;
|
||||||
|
|
||||||
|
import actor.ActorThread;
|
||||||
|
import wash.control.WashingMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 EmptyProgram extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
|
public EmptyProgram() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("WARNINIG: Attempting to run empty program");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@ import static wash.control.WashingMessage.Order.*;
|
||||||
*
|
*
|
||||||
* It can be used after an emergency stop (program 0) or a power failure.
|
* It can be used after an emergency stop (program 0) or a power failure.
|
||||||
*/
|
*/
|
||||||
public class WashingProgram1 extends ActorThread<WashingMessage> {
|
public final class WashingProgram1 extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
private WashingIO io;
|
private WashingIO io;
|
||||||
private ActorThread<WashingMessage> temp;
|
private ActorThread<WashingMessage> temp;
|
||||||
|
@ -36,40 +36,44 @@ public class WashingProgram1 extends ActorThread<WashingMessage> {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
System.out.println("washing program 1 started.");
|
|
||||||
// Lock the hatch
|
// Lock the hatch
|
||||||
io.lock(true);
|
io.lock(true);
|
||||||
|
|
||||||
|
water.send(new WashingMessage(this, WATER_FILL));
|
||||||
|
receive();
|
||||||
|
|
||||||
// Instruct SpinController to rotate barrel slowly, back and forth
|
// Instruct SpinController to rotate barrel slowly, back and forth
|
||||||
// Expect an acknowledgment in response.
|
// Expect an acknowledgment in response.
|
||||||
System.out.println("setting SPIN_SLOW...");
|
|
||||||
spin.send(new WashingMessage(this, SPIN_SLOW));
|
spin.send(new WashingMessage(this, SPIN_SLOW));
|
||||||
WashingMessage ack1 = receive();
|
receive();
|
||||||
System.out.println("washing program 1 got " + ack1);
|
|
||||||
|
|
||||||
// Spin for five simulated minutes (one minute == 60000 milliseconds)
|
// Spin for five simulated minutes (one minute == 60000 milliseconds)
|
||||||
Thread.sleep(5 * 60000 / Settings.SPEEDUP);
|
Thread.sleep(5 * 60000 / Settings.SPEEDUP);
|
||||||
|
|
||||||
// Instruct SpinController to stop spin barrel spin.
|
// Instruct SpinController to stop spin barrel spin.
|
||||||
// Expect an acknowledgment in response.
|
// Expect an acknowledgment in response.
|
||||||
System.out.println("setting SPIN_OFF...");
|
|
||||||
spin.send(new WashingMessage(this, SPIN_OFF));
|
spin.send(new WashingMessage(this, SPIN_OFF));
|
||||||
WashingMessage ack2 = receive();
|
receive();
|
||||||
System.out.println("washing program 1 got " + ack2);
|
|
||||||
|
|
||||||
// usleep(1000);
|
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.
|
// Now that the barrel has stopped, it is safe to open the hatch.
|
||||||
io.lock(false);
|
io.lock(false);
|
||||||
System.out.println("washing program 1 unlocked hatch");
|
|
||||||
|
System.out.println("WashingProgram1 Finished...");
|
||||||
|
this.interrupt();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
System.out.println("WashingProgram1 Interrupted...");
|
||||||
|
|
||||||
// If we end up here, it means the program was interrupt()'ed:
|
// If we end up here, it means the program was interrupt()'ed:
|
||||||
// set all controllers to idle
|
// set all controllers to idle
|
||||||
temp.send(new WashingMessage(this, TEMP_IDLE));
|
temp.send(new WashingMessage(this, TEMP_IDLE));
|
||||||
water.send(new WashingMessage(this, WATER_IDLE));
|
water.send(new WashingMessage(this, WATER_IDLE));
|
||||||
spin.send(new WashingMessage(this, SPIN_OFF));
|
spin.send(new WashingMessage(this, SPIN_OFF));
|
||||||
System.out.println("washing program terminated");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import static wash.control.WashingMessage.Order.*;
|
||||||
*
|
*
|
||||||
* It can be used after an emergency stop (program 0) or a power failure.
|
* It can be used after an emergency stop (program 0) or a power failure.
|
||||||
*/
|
*/
|
||||||
public class WashingProgram2 extends ActorThread<WashingMessage> {
|
public final class WashingProgram2 extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
private WashingIO io;
|
private WashingIO io;
|
||||||
private ActorThread<WashingMessage> temp;
|
private ActorThread<WashingMessage> temp;
|
||||||
|
@ -36,7 +36,7 @@ public class WashingProgram2 extends ActorThread<WashingMessage> {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
System.out.println("Washing program 2 starting.");
|
System.out.println("WashingProgram2 Started...");
|
||||||
// Lock the hatch
|
// Lock the hatch
|
||||||
io.lock(true);
|
io.lock(true);
|
||||||
|
|
||||||
|
@ -45,15 +45,15 @@ public class WashingProgram2 extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
// Now that the barrel has stopped, it is safe to open the hatch.
|
// Now that the barrel has stopped, it is safe to open the hatch.
|
||||||
io.lock(false);
|
io.lock(false);
|
||||||
System.out.println("Washing program 2 finished.");
|
System.out.println("WashingProgram2 Finished...");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
System.out.println("WashingProgram2 Interrupted...");
|
||||||
|
|
||||||
// If we end up here, it means the program was interrupt()'ed:
|
// If we end up here, it means the program was interrupt()'ed:
|
||||||
// set all controllers to idle
|
// set all controllers to idle
|
||||||
temp.send(new WashingMessage(this, TEMP_IDLE));
|
temp.send(new WashingMessage(this, TEMP_IDLE));
|
||||||
water.send(new WashingMessage(this, WATER_IDLE));
|
water.send(new WashingMessage(this, WATER_IDLE));
|
||||||
spin.send(new WashingMessage(this, SPIN_OFF));
|
spin.send(new WashingMessage(this, SPIN_OFF));
|
||||||
System.out.println("washing program terminated");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import static wash.control.WashingMessage.Order.*;
|
||||||
*
|
*
|
||||||
* It can be used after an emergency stop (program 0) or a power failure.
|
* It can be used after an emergency stop (program 0) or a power failure.
|
||||||
*/
|
*/
|
||||||
public class WashingProgram3 extends ActorThread<WashingMessage> {
|
public final class WashingProgram3 extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
private WashingIO io;
|
private WashingIO io;
|
||||||
private ActorThread<WashingMessage> temp;
|
private ActorThread<WashingMessage> temp;
|
||||||
|
@ -36,14 +36,19 @@ public class WashingProgram3 extends ActorThread<WashingMessage> {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
System.out.println("washing program 3 started");
|
System.out.println("WashingProgram3 Started...");
|
||||||
|
|
||||||
io.lock(true);
|
io.lock(true);
|
||||||
|
|
||||||
// Switch off heating
|
// Switch off heating
|
||||||
temp.send(new WashingMessage(this, TEMP_IDLE));
|
// 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, WATER_FILL));
|
||||||
System.out.println(receive());
|
System.out.println(receive());
|
||||||
temp.send(new WashingMessage(this, TEMP_SET_40));
|
temp.send(new WashingMessage(this, WATER_DRAIN));
|
||||||
System.out.println(receive());
|
System.out.println(receive());
|
||||||
|
|
||||||
// Thread.sleep(5 * 60000 / Settings.SPEEDUP);
|
// Thread.sleep(5 * 60000 / Settings.SPEEDUP);
|
||||||
|
@ -51,16 +56,15 @@ public class WashingProgram3 extends ActorThread<WashingMessage> {
|
||||||
// Unlock hatch
|
// Unlock hatch
|
||||||
io.lock(false);
|
io.lock(false);
|
||||||
|
|
||||||
System.out.println("Washing program 3 finished");
|
System.out.println("WashingProgram3 Finished...");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
System.out.println("WashingProgram3 Interrupted...");
|
||||||
// If we end up here, it means the program was interrupt()'ed:
|
// If we end up here, it means the program was interrupt()'ed:
|
||||||
// set all controllers to idle
|
// set all controllers to idle
|
||||||
|
|
||||||
temp.send(new WashingMessage(this, TEMP_IDLE));
|
temp.send(new WashingMessage(this, TEMP_IDLE));
|
||||||
water.send(new WashingMessage(this, WATER_IDLE));
|
water.send(new WashingMessage(this, WATER_IDLE));
|
||||||
spin.send(new WashingMessage(this, SPIN_OFF));
|
spin.send(new WashingMessage(this, SPIN_OFF));
|
||||||
System.out.println("washing program 3 terminated");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,14 @@ import static wash.control.WashingMessage.Order.*;
|
||||||
*
|
*
|
||||||
* It can be used after an emergency stop (program 0) or a power failure.
|
* It can be used after an emergency stop (program 0) or a power failure.
|
||||||
*/
|
*/
|
||||||
public class WashingProgramN extends ActorThread<WashingMessage> {
|
public final class WashingProgramStop extends ActorThread<WashingMessage> {
|
||||||
|
|
||||||
private WashingIO io;
|
private WashingIO io;
|
||||||
private ActorThread<WashingMessage> temp;
|
private ActorThread<WashingMessage> temp;
|
||||||
private ActorThread<WashingMessage> water;
|
private ActorThread<WashingMessage> water;
|
||||||
private ActorThread<WashingMessage> spin;
|
private ActorThread<WashingMessage> spin;
|
||||||
|
|
||||||
public WashingProgramN(WashingIO io,
|
public WashingProgramStop(WashingIO io,
|
||||||
ActorThread<WashingMessage> temp,
|
ActorThread<WashingMessage> temp,
|
||||||
ActorThread<WashingMessage> water,
|
ActorThread<WashingMessage> water,
|
||||||
ActorThread<WashingMessage> spin)
|
ActorThread<WashingMessage> spin)
|
||||||
|
@ -36,7 +36,7 @@ public class WashingProgramN extends ActorThread<WashingMessage> {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
System.out.println("User pressed stop button");
|
System.out.println("WashingProgramStop Starting...");
|
||||||
|
|
||||||
// Switch off heating
|
// Switch off heating
|
||||||
temp.send(new WashingMessage(this, TEMP_IDLE));
|
temp.send(new WashingMessage(this, TEMP_IDLE));
|
||||||
|
@ -65,9 +65,9 @@ public class WashingProgramN extends ActorThread<WashingMessage> {
|
||||||
// Unlock hatch
|
// Unlock hatch
|
||||||
io.lock(false);
|
io.lock(false);
|
||||||
|
|
||||||
System.out.println("washing stop program finished");
|
System.out.println("WashingProgramStop Finished...");
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
System.out.println("WashingProgramStop Interrupted...");
|
||||||
// If we end up here, it means the program was interrupt()'ed:
|
// If we end up here, it means the program was interrupt()'ed:
|
||||||
// set all controllers to idle
|
// set all controllers to idle
|
||||||
|
|
Loading…
Reference in a new issue