Example #1
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;
         }
       }
     }
   }
 }
Example #2
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;
  }