public boolean pickAndExecuteAnAction() { if (conveyorBroken || sensorBroken) { stopConveyor(); return false; } else if (partGroupCount < partGroupEndOfConveyor) { System.err.println(getName() + " has an unexpected number of sensor events"); System.err.println(getName() + " is now stopping"); Object[] args = new Object[1]; args[0] = myIndex * 2; transducer.fireEvent(TChannel.GUI, TEvent.SENSOR_BROKEN, args); sensorBroken = true; stopConveyor(); return false; } else if (partsLoaded > partGroupEndOfConveyor) { System.err.println("Truck loaded untracked part\n" + getName() + " is now stopping"); Object[] args = new Object[1]; args[0] = myIndex * 2 + 1; transducer.fireEvent(TChannel.GUI, TEvent.SENSOR_BROKEN, args); sensorBroken = true; stopConveyor(); return false; } else if (!parts.isEmpty()) { if (isRunning) { if (followSensorDepressed && myState != MyState.Normal) { stopConveyor(); } } else if (myState == MyState.Normal || !followSensorDepressed) { startConveyor(); } } if (myState == MyState.DoneLoading && !truckBroken) emptyTruck(); return false; }
public PopupAgent( ControlPanel cp, FactoryFrame ff, Integer index, Transducer t, TChannel channelType) // ArrayList<Robot> inputRobots { super("popupAgent"); this.cp = cp; factoryFrame = ff; myIndex = index; glasses = Collections.synchronizedList(new ArrayList<MyGlass>()); nextFamilyAvailable = true; transducer = t; myChannel = channelType; if (myChannel == TChannel.DRILL) expectationTime = 29; else if (myChannel == TChannel.CROSS_SEAMER) expectationTime = 13; else if (myChannel == TChannel.GRINDER) expectationTime = 32; // for(Robot r: inputRobots) // { // robots.add(new MyRobot(r)); // } robots.add(new MyRobot()); robots.add(new MyRobot()); t.register(this, TChannel.CONVEYOR); t.register(this, TChannel.SENSOR); t.register(this, TChannel.POPUP); // need to listen to another work station t.register(this, myChannel); }
// other than transducer, the parameters are pointers to fully functioning // agents. public GuiTestSM( Transducer t, ConveyorFamilyContainer cf5, ConveyorFamilyContainer cf7, ConveyorAgentWithTruck cf14, ConveyorFamilyInLineStation cf11, Bin bin, ConveyorFamilyGroup cf0) { this.t = t; this.cf5 = cf5; this.cf7 = cf7; this.cf14 = cf14; this.cf11 = cf11; this.bin = bin; this.cf0 = cf0; t.register(this, TChannel.CUTTER); t.register(this, TChannel.SENSOR); t.register(this, TChannel.BREAKOUT); t.register(this, TChannel.MANUAL_BREAKOUT); // the following registration events are commented to give control to // the actual agents // t.register(this, TChannel.POPUP); // t.register(this, TChannel.DRILL); // t.register(this, TChannel.UV_LAMP); // t.register(this, TChannel.WASHER); // t.register(this, TChannel.OVEN); // t.register(this, TChannel.PAINTER); // the following registration events are commented to give control to // the actual agents // t.register(this, TChannel.TRUCK);//added by monroe // t.fireEvent(TChannel.BIN, TEvent.BIN_CREATE_PART, null); // bin.msgHereIsNewPart(new Part("1111111111"), 0); }
public ConveyorWorkstationJT(Transducer t, String name, TChannel channel) { super(name); myChannel = channel; this.trans = t; trans.register(this, myChannel); trans.register(this, TChannel.ALL_AGENTS); trans.register(this, TChannel.SENSOR); cWsState = ConvWsState.PENDING; // Set myOperation based on channel if (channel == TChannel.BREAKOUT) myOperation = ComponentOperations.BREAKOUT; else if (channel == TChannel.MANUAL_BREAKOUT) myOperation = ComponentOperations.MANUALBREAKOUT; else if (channel == TChannel.WASHER) myOperation = ComponentOperations.WASHER; else if (channel == TChannel.PAINTER) myOperation = ComponentOperations.PAINT; else if (channel == TChannel.UV_LAMP) myOperation = ComponentOperations.UVLAMP; }
private void emptyTruck() { partsLoaded = 0; myState = MyState.Unloading; cfLead.msgConveyorReady(this); partGroupCount = partGroupEndOfConveyor = 0; transducer.fireEvent(TChannel.TRUCK, TEvent.TRUCK_DO_EMPTY, null); }
private void processGlass() { print("PROCESSING GLASS"); cWsState = ConvWsState.PENDING; // msg GUI to process glass trans.fireEvent(myChannel, TEvent.WORKSTATION_DO_ACTION, null); stateChanged(); }
// Msgs: @Override public void msgHereisGlass(Glass g) // This is where glass is sent in { this.glass = g; status = Status.filled; print("Received glass"); trans.fireEvent(TChannel.CONVEYOR, TEvent.CONVEYOR_DO_START, number); stateChanged(); }
// Methods: public Sensor1Agent(String name, Transducer t, int num) { super(name, t); t.register(this, TChannel.SENSOR); trans = t; status = Status.open; canSend = new Semaphore(0, true); number = new Integer[1]; number[0] = num; }
private void startConveyor() { if (!isRunning) { isRunning = true; startConveyorTimer.restart(); conveyorRestart = true; Object[] args = new Object[1]; args[0] = myIndex; transducer.fireEvent(TChannel.CONVEYOR, TEvent.CONVEYOR_DO_START, args); stateChanged(); } }
private void stopConveyor() { if (isRunning) { isRunning = false; if (!parts.isEmpty()) { readyMessageTimer.stop(); startConveyorTimer.stop(); } Object[] args = new Object[1]; args[0] = myIndex; transducer.fireEvent(TChannel.CONVEYOR, TEvent.CONVEYOR_DO_STOP, args); stateChanged(); } }
private void releaseGlass() { print("handing off processed glass to " + nextConveyor); /** @Brooke prevent a race condition for the washergui overwriting the glassPart */ /*cWsState = ConvWsState.PENDING; readyForGlass = true;*/ nextConveyorReady = false; // msg GUI to release glass trans.fireEvent(myChannel, TEvent.WORKSTATION_RELEASE_GLASS, null); nextConveyor.msgHereIsGlass(glass); /** @Brooke prevent a race condition for the washergui overwriting the glassPart */ this.cWsState = ConvWsState.MOVING_OUT; // glass = null; stateChanged(); }
/** Constructor links this panel to its frame */ public FactoryPanel(FactoryFrame fFrame) { parent = fFrame; // initialize transducer transducer = new Transducer(); transducer.startTransducer(); // use default layout // dPanel = new DisplayPanel(this); // dPanel.setDefaultLayout(); // dPanel.setTimerListeners(); // initialize and run this.initialize(); this.initializeBackEnd(); }
@Override public void eventFired(TChannel channel, TEvent event, Object[] args) { if (channel == TChannel.SENSOR && event == TEvent.SENSOR_GUI_PRESSED) { Integer[] newArgs = new Integer[1]; // added argument 2-5 to ignore the sensors in conveyor families 5-7 // and 14 and give control to the actual agents if (((Integer) args[0] % 2) == 0 && !((Integer) args[0]).equals(cutterConveyorIndex * 2) // && !((Integer) args[0]).equals(automaticBreakoutPreIndex * 2) // && !((Integer) args[0]).equals(automaticBreakoutPostIndex * 2) // && !((Integer) args[0]).equals(manualBreakoutIndex * 2) // && !((Integer) args[0]).equals(secondShuttleIndex * 2) && !((Integer) args[0]).equals(drillConveyorIndex * 2) && !((Integer) args[0]).equals((crossSeamerConveyorIndex) * 2) && !((Integer) args[0]).equals((grinderConveyorIndex) * 2) && !((Integer) args[0]).equals((conveyor14Index) * 2) && !((Integer) args[0]).equals((washerEdward) * 2) && !((Integer) args[0]).equals((simpleEdward) * 2) && !((Integer) args[0]).equals((painterEdward) * 2) && !((Integer) args[0]).equals((uvEdward) * 2) && !((Integer) args[0]).equals((simpleEdward2) * 2) && !((Integer) args[0]).equals((ovenEdward) * 2)) { newArgs[0] = (Integer) args[0] / 2; t.fireEvent(TChannel.CONVEYOR, TEvent.CONVEYOR_DO_START, newArgs); } // commented out by christina because it is no longer needed // this gives conveyor family 5 an actual Part when the last sensor // in the prior conveyor family is pressed else if (((Integer) args[0]).equals(drillConveyorIndex * 2 - 1)) { // testing cf5.msgHereIsNewPart(null, new Part("0000000111")); } /* else if (((Integer) args[0]).equals(uvEdward * 2 - 1)) { // testing cf11.msgHereIsNewPart(null, new Part("0000000000")); } else if (((Integer) args[0]).equals(conveyor14Index * 2 - 1)) { // testing cf14.msgHereIsNewPart(null, new Part("0000000000")); } */ } else if (channel == TChannel.SENSOR && event == TEvent.SENSOR_GUI_RELEASED) { // this loads an additional, specified number of parts into the animation for testing if (((Integer) args[0]).equals(0) && totalParts < 30) { // t.fireEvent(TChannel.BIN, TEvent.BIN_CREATE_PART, null); // bin.msgHereIsNewPart(new Part("1111111111"), 0); totalParts++; } // this sends the previous conveyor a ready message when the following conveyor's // sensor is released /* else if(((Integer) args[0]).equals(washEdward * 2) ) cf7.msgConveyorReady(null); */ if (((Integer) args[0]).equals(2)) cf0.msgConveyorReady(null); } else if (channel == TChannel.CUTTER && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.CUTTER, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.CUTTER && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.CUTTER, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.BREAKOUT && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.BREAKOUT, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.BREAKOUT && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.BREAKOUT, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.MANUAL_BREAKOUT && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.MANUAL_BREAKOUT, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.MANUAL_BREAKOUT && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.MANUAL_BREAKOUT, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.POPUP && event == TEvent.POPUP_GUI_LOAD_FINISHED) { if (offlineDone) t.fireEvent(TChannel.POPUP, TEvent.POPUP_DO_MOVE_DOWN, args); else t.fireEvent(TChannel.POPUP, TEvent.POPUP_DO_MOVE_UP, args); } else if (channel == TChannel.POPUP && event == TEvent.POPUP_GUI_MOVED_UP) { Integer[] newArgs = new Integer[1]; newArgs[0] = 0; t.fireEvent(TChannel.DRILL, TEvent.WORKSTATION_DO_LOAD_GLASS, newArgs); } else if (channel == TChannel.DRILL && event == TEvent.WORKSTATION_LOAD_FINISHED) { t.fireEvent(TChannel.DRILL, TEvent.WORKSTATION_DO_ACTION, args); } else if (channel == TChannel.DRILL && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.DRILL, TEvent.WORKSTATION_RELEASE_GLASS, args); offlineDone = true; } else if (channel == TChannel.POPUP && event == TEvent.POPUP_GUI_MOVED_DOWN) { t.fireEvent(TChannel.POPUP, TEvent.POPUP_RELEASE_GLASS, args); // offlineDone = false; } else if (channel == TChannel.WASHER && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.WASHER, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.WASHER && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.WASHER, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.UV_LAMP && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.UV_LAMP, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.UV_LAMP && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.UV_LAMP, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.PAINTER && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.PAINTER, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.PAINTER && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.PAINTER, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.OVEN && event == TEvent.WORKSTATION_LOAD_FINISHED) { // added by // monroe t.fireEvent(TChannel.OVEN, TEvent.WORKSTATION_DO_ACTION, null); } else if (channel == TChannel.OVEN && event == TEvent.WORKSTATION_GUI_ACTION_FINISHED) { t.fireEvent(TChannel.OVEN, TEvent.WORKSTATION_RELEASE_GLASS, null); } else if (channel == TChannel.TRUCK && event == TEvent.TRUCK_GUI_LOAD_FINISHED) { // added by monroe t.fireEvent(TChannel.TRUCK, TEvent.TRUCK_DO_EMPTY, null); } }