Esempio n. 1
0
 public void msgHereIsGlass(Glass g) // 8 from conveyor
     {
   MyGlass newGlass = new MyGlass(g);
   newGlass.status = GlassStatus.Pending;
   glasses.add(newGlass);
   stateChanged();
 }
Esempio n. 2
0
  public void popupActionPopupReleaseFinished() {
    if (actionStatus == ActionStatus.passGlass) {
      for (MyGlass g : glasses) {
        if (g.status == GlassStatus.WaitingForPass) {

          print("popup" + myIndex + "popup released the glass");
          glasses.remove(g);
          animationStatus = AnimationStatus.Nothing;
          actionStatus = ActionStatus.Nothing;
          nextCF.msgHereIsGlass(g.glass);
          return;
        }
      }
    } else if (actionStatus == ActionStatus.getGlassFromMachine) {
      for (MyGlass g : glasses) {
        if (g.status == GlassStatus.Ready) {
          print("popup" + myIndex + "popup released the glass");
          glasses.remove(g);
          animationStatus = AnimationStatus.Nothing;
          actionStatus = ActionStatus.Nothing;
          robots.get(g.robotIndex).status = RobotStatus.Empty;
          print("" + myIndex + "machine " + g.getRobotIndex() + " is set to empty!~~~~~");
          nextCF.msgHereIsGlass(g.glass);
          conveyor.msgPopupAvailable();
          return;
        }
      }
    }
  }
Esempio n. 3
0
  public void msgGlassReady(
      Integer thisIndex) // 10a from machine, moveup to take the glass if 10b is received labter
      {
    for (MyGlass myGlass : glasses) {
      if (myGlass.status == GlassStatus.Handling && myGlass.robotIndex.equals(thisIndex)) {

        myGlass.status = GlassStatus.Ready;
        break;
      }
    }
    stateChanged();
  }
Esempio n. 4
0
  public void deliverGlass(MyGlass g) {
    System.out.println("deliver the glass is called:" + myIndex + " " + g.getRobotIndex());
    g.status = GlassStatus.Delivering;
    Integer[] popupArgs = new Integer[1];
    popupArgs[0] = myIndex;
    Integer[] conveyorArgs = new Integer[1];
    conveyorArgs[0] = conveyor.getMyIndex();
    Integer[] robotArgs = new Integer[1];
    robotArgs[0] = g.robotIndex;
    // move down, take glass, take it to the next available machine
    transducer.fireEvent(TChannel.POPUP, TEvent.POPUP_DO_MOVE_DOWN, popupArgs);
    animationStatus = AnimationStatus.PopupMovingDown;
    //		try {
    //			animationSem.acquire();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		} // released by POPUP_GUI_MOVED_DOWN
    //		print("popup"+myIndex+" moved down the pop up");
    //		transducer.fireEvent(TChannel.CONVEYOR,TEvent.CONVEYOR_DO_START,conveyorArgs);
    //		try {
    //			animationSem.acquire();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		} // released by POPUP_GUI_LOAD_FINISHED
    //		print("popup"+myIndex+"popup finished loading");
    //		transducer.fireEvent(TChannel.POPUP,TEvent.POPUP_DO_MOVE_UP,popupArgs);

    //		print("popup"+myIndex+"popup moved up");
    //		transducer.fireEvent(myChannel, TEvent.WORKSTATION_DO_LOAD_GLASS,robotArgs);
    //		try {
    //			animationSem.acquire();
    //		} catch (InterruptedException e) {
    //			e.printStackTrace();
    //		} // released by WORKSTATION_LOAD_FINISHED
    //		//TODO
    //		print("workStation"+robotArgs[0]+"load glass finished");
    //		transducer.fireEvent(myChannel, TEvent.WORKSTATION_DO_ACTION,robotArgs);

    // robots.get(g.robotIndex).robot.msgHereIsGlass(g.glass);

    stateChanged();
  }
Esempio n. 5
0
 public void popupActionWorkStationLoadFinished() {
   if (actionStatus == ActionStatus.deliverGlass) // done with deliverGlass
   {
     synchronized (glasses) {
       for (MyGlass g : glasses) {
         if (g.status == GlassStatus.Delivering) {
           Integer[] robotArgs = new Integer[1];
           robotArgs[0] = g.robotIndex;
           transducer.fireEvent(myChannel, TEvent.WORKSTATION_DO_ACTION, robotArgs);
           robots.get(g.robotIndex).startTime = System.currentTimeMillis();
           g.status = GlassStatus.Handling;
           animationStatus = AnimationStatus.Nothing;
           actionStatus = ActionStatus.Nothing;
           stateChanged();
           break;
         }
       }
     }
   }
 }
Esempio n. 6
0
  public boolean pickAndExecuteAnAction() {

    MyGlass tempG = null;
    MyGlass tempG1 = null;

    synchronized (robots) {
      for (int i = 0; i < robots.size(); i++) {
        if (robots.get(i).startTime != 0) {
          float duration = System.currentTimeMillis() - robots.get(i).startTime;
          System.out.println(
              duration + ":::" + speedDown * expectationTime * factoryFrame.getTimerDelay() * 40);
          if (duration > speedDown * expectationTime * factoryFrame.getTimerDelay() * 40) {
            System.err.println("Detected a broken machine: " + myChannel + " index: " + i);
            cp.getTracePanel()
                .print(
                    "Detected a broken machine: machine channel: "
                        + myChannel
                        + " index: "
                        + i
                        + "\n",
                    this);
            robots.get(i).startTime = 0;
            // System.exit(0);
          }
        }
      }
    }
    if (animationStatus == AnimationStatus.PopupMovedDown) {
      popupActionPopupMovedDown();
      return true;

    } else if (animationStatus == AnimationStatus.PopUpGuiLoadFinished) {
      popupActionPopUpGuiLoadFinished();

      return true;

    } else if (animationStatus == AnimationStatus.PopUpMovedUp) {
      popupActionPopupMovedUp();
      return true;
    } else if (animationStatus == AnimationStatus.WorkStationLoadFinished) {
      popupActionWorkStationLoadFinished();
      return true;
    } else if (animationStatus == AnimationStatus.PopupReleaseFinished) {
      popupActionPopupReleaseFinished();
      return true;
    } else if (nextFamilyAvailable
        && animationStatus == AnimationStatus.Nothing
        && actionStatus == ActionStatus.Nothing) {

      synchronized (glasses) {
        for (MyGlass g : glasses) {
          if (g.status == GlassStatus.WaitingForPass) {
            tempG = g;
            break;
          }
        }
        for (MyGlass g : glasses) {
          if (g.status == GlassStatus.Ready) {
            tempG1 = g;
            break;
          }
        }
      }
      if (tempG != null) {
        actionStatus = ActionStatus.passGlass;
        passGlass(tempG);
        return true;
      } else if (tempG1 != null) {
        actionStatus = ActionStatus.getGlassFromMachine;
        getGlassFromMachine(tempG1);
        return true;
      }

      for (int i = 0; i < robots.size(); i++) {
        if (robots.get(i).status == RobotStatus.Empty) {
          synchronized (glasses) {
            for (MyGlass g :
                glasses) // there exists a MyGlass g in glasses such that g.status =
                         // GlassStatus.Pending
            {
              if (g.status == GlassStatus.Pending) {
                tempG = g;
                break;
              }
            }
          }
          if (tempG != null) {
            tempG.robotIndex = i;
            robots.get(i).status = RobotStatus.Working;
            actionStatus = ActionStatus.deliverGlass;
            deliverGlass(tempG);
            return true;
          }
        }
      }
    }
    for (int i = 0; i < robots.size(); i++) {
      if (robots.get(i).status == RobotStatus.Fixing) {
        fixRobot(i);
        return true;
      }
    }

    return false;
  }
Esempio n. 7
0
 public void msgComeDownAndLetGlassPass(Glass g) {
   MyGlass newGlass = new MyGlass(g);
   newGlass.status = GlassStatus.WaitingForPass;
   glasses.add(newGlass);
   stateChanged();
 }