/** * Scheduler ** */
  protected boolean pickAndExecuteAnAction() {

    if (badRequests.size() > 0) {
      processNonNorms();
      return true;
    }
    if (requests.size() > 0) {
      verifyParts();
      return true;
    }
    return false;
  }
 /* (GUI NN Panel) Drives the Parts Missing Non-Normative */
 public void msgPartsMissing(int num) // nest num
     {
   print("Received part missing non-normative");
   FactoryState.out.println("Received part missing non-normative");
   badRequests.add(new BadRequest(num, BadRequestState.partsMissing));
   stateChanged();
 }
  private void verifyParts() {

    CheckRequest c = requests.remove(0);
    print("Taking picture of " + c.nest.getName());
    FactoryState.out.println("Taking picture of " + c.nest.getName());

    c.nest.guiNest().camera.DoTakePicture(c.nest);
    try {
      verify.acquire();
    } catch (Exception ex) {
    }

    if (c.state == RequestState.good) {
      c.nest.msgPartsAreGood(c.parts);
    } else if (c.state == RequestState.partsBad) {
      c.nest.msgPartsAreBad();
    } else if (c.state == RequestState.partsUnstable) {
      c.nest.msgPartsAreUnstable();
    } else if (c.state == RequestState.partsMissing) {
      print("Parts missing from " + c.nest.getName());
      FactoryState.out.println("Parts missing from " + c.nest.getName());
    } else if (c.state == RequestState.photobombing) {
      c.nest.msgPartsArePhotobombing();
    } else if (c.state == RequestState.cameraError) {
      c.nest.msgPartsAreCameraError();
    }

    stateChanged();
  }
  public void processNonNorms() {

    BadRequest n = badRequests.remove(0);
    int num = n.num;

    print("Taking picture of " + factoryState.nestList.get(num).getName());
    FactoryState.out.println("Taking picture of " + factoryState.nestList.get(num).getName());

    factoryState.nestList.get(num).guiNest().camera.DoTakePicture(factoryState.nestList.get(num));
    try {
      verify.acquire();
    } catch (Exception ex) {
    }

    if (n.state == BadRequestState.partsMissing) {
      print("Parts missing from " + factoryState.nestList.get(num).getName());
      FactoryState.out.println("Parts missing from " + factoryState.nestList.get(num).getName());
      factoryState.nestList.get(num).msgPartsMissing();
    }

    stateChanged();
  }
 /*  (Nest) Requests to verify parts and take picture when we have unstable parts */
 public void msgVerifyPartsUnstable(List<Part> visionParts, NestAgent nest) {
   requests.add(new CheckRequest(visionParts, nest, RequestState.partsUnstable));
   stateChanged();
 }
 /*  (Nest) Requests to verify parts and take picture when there's a camera error */
 public void msgVerifyPartsCameraError(List<Part> visionParts, NestAgent nest) {
   requests.add(new CheckRequest(visionParts, nest, RequestState.cameraError));
   stateChanged();
 }
 /*  (Nest) Requests to verify parts and take picture when partrobot is photobombing */
 public void msgVerifyPartsPhotobombing(List<Part> visionParts, NestAgent nest) {
   requests.add(new CheckRequest(visionParts, nest, RequestState.photobombing));
   stateChanged();
 }