/**
   * This method checks both elevators to determine if one is on the floor where this passenger is
   * attempting to board.
   *
   * <p>It returns a reference to the elevator or a null if no elevator is available.
   *
   * @return available elevator or a null if no elevator is available.
   */
  private static Elevator findElevator(Passenger passenger) {
    Elevator foundElevator = null;

    if (elevator1.isElevatorHere(passenger)) {
      foundElevator = elevator1;
    } else if (elevator2.isElevatorHere(passenger)) {
      foundElevator = elevator2;
    }

    return foundElevator;
  } //  end findElevator
  /**
   * This method performs reporting at the end of the workday. It indicates that the elevators have
   * stopped service and reports passenger counts.
   */
  private static void endOfDay() {

    System.out.println();
    System.out.println("End of workday. Elevators stopping service.");
    System.out.println(
        "Stopping elevator 1 with "
            + elevator1.getTotalPassengers()
            + " onboard."); // changed method from getPassengerCount() to getTotalPassengers()
                            // edited by MAGNUM
    System.out.println(
        "Stopping elevator 2 with "
            + elevator2.getTotalPassengers()
            + " onboard."); // changed method from getPassengerCount() to getTotalPassengers()
                            // edited by MAGNUM
  } //  end endOfDay
 /** This function is called periodically during operator control */
 public void teleopPeriodic() {
   Scheduler.getInstance().run();
   drivetrain.smartDashboardPush();
   purpleSensor.smartDashboardPush();
   gripper.smartDashboardPush();
   elevator.smartDashboardPush();
 }
  public void disabledPeriodic() {
    Scheduler.getInstance().run();
    purpleSensor.smartDashboardPush();
    drivetrain.smartDashboardPush();
    gripper.smartDashboardPush();
    elevator.smartDashboardPush();

    if (drivetrain.getResetButton() && !drivetrain.isResetDisabled()) {
      drivetrain.resetEncoders();
      purpleSensor.zeroHeading();
    }
  }
  /**
   * Feature #7
   *
   * @param fromFloor
   * @param toFloor
   * @return
   */
  public boolean receiveRequest(int fromFloor, int toFloor) {

    boolean requestFilled = false;
    // check to see if any of the elevators are on the "fromFloor".  If so, then it will fill the
    // request;
    for (Elevator currentElevator : elevatorList) {
      int closestDistance = 1000;
      Elevator closestElevator = null;
      if (currentElevator.inService && currentElevator.currentFloor == fromFloor) {
        try {
          currentElevator.gotoFloor(toFloor);
        } catch (InvalidFloorRequest invalidFloorRequest) {
          invalidFloorRequest.printStackTrace();
        }
        requestFilled = true;
        break;
      } else {
        // go through each elevator and see how far away it is.  Choose the closest
        if (currentElevator.distanceFromFloor(fromFloor) < closestDistance) {
          closestDistance = currentElevator.distanceFromFloor(fromFloor);
          closestElevator = currentElevator;
        }
      }
      if (closestElevator != null) {
        requestFilled = true;
        try {
          closestElevator.gotoFloor(fromFloor);
        } catch (InvalidFloorRequest invalidFloorRequest) {
          invalidFloorRequest.printStackTrace();
        }
      }
    }
    return requestFilled;
  }
  public void printSensorStates() {
    gather.StopFront();
    gather.StopBack();
    elevator.Stop();
    if (frontGather.isTriggered()) {
      System.out.println("Front Gatherer");
    }
    if (backGather.isTriggered()) {
      System.out.println("Back Gatherer");
    }

    for (int i = 0; i < elevatorSensors.length; i++) {

      if (elevatorSensors[i].isTriggered()) {
        System.out.println("Elevator: " + (i + 1));
      } else if (!frontGather.isTriggered()
          && !backGather.isTriggered()
          && !elevatorSensors[i].isTriggered()) {
        System.out.println("Nuffin");
      }
    }
  }
  public void MoveState() {
    switch (moveState) {
      default:
        System.out.println("default state.. WTF???");
        gather.StopFront();
        gather.StopBack();
        elevator.Stop();
        break;
      case 0:
        System.out.println("Start Your Engine");
        gather.FrontForward();
        gather.BackForward();
        moveState = 1;
        break;
      case 1:
        System.out.println("Load Ball 1");
        if (frontGather.isTriggered() || backGather.isTriggered()) {
          moveState = 2;
        }
        break;
      case 2:
        System.out.println("Move 1 to point 1");
        elevator.MoveUp(.35);
        if (elevatorSensors[0].isTriggered()) {
          elevator.Stop();
          moveState = 12;
        }
        break;
      case 12:
        System.out.println("State 12");
        if (!frontGather.isTriggered() && !backGather.isTriggered()) {
          moveState = 3;
        }
        break;
      case 3:
        System.out.println("Load Ball 2, adjust to point 2");
        if (frontGather.isTriggered() || backGather.isTriggered()) {
          elevator.MoveUp(.35);
          moveState = 4;
        }
        break;
      case 4:
        System.out.println("State 4");
        if (elevatorSensors[1].isTriggered()) {
          elevator.Stop();

          moveState = 14;
        }
        break;
      case 14:
        System.out.println("State 14");
        if (!frontGather.isTriggered() && !backGather.isTriggered()) {
          moveState = 5;
        }
        break;
      case 5:
        System.out.println("State 5");
        if (frontGather.isTriggered() || backGather.isTriggered()) {
          elevator.MoveUp(.4);
          moveState = 15;
        }
        break;
      case 15:
        System.out.println("State 15");
        if (!frontGather.isTriggered() && !backGather.isTriggered()) {
          moveState = 6;
        }
        break;
      case 6:
        System.out.println("State 6");
        if (elevatorSensors[2].isTriggered()) {
          elevator.Stop();
          moveState = 7;
        }
        break;
      case 7:
        System.out.println("END STATE");
        gather.StopFront();
        gather.StopBack();
        elevator.Stop();
        break;
    }
  }
 public void turnOff() {
   gather.StopFront();
   gather.StopBack();
   elevator.Stop();
 }
 public void startUp() {
   gather.FrontForward();
   gather.BackForward();
   elevator.MoveUp();
 }
 public Moving(Elevator elevator) {
   this.elevator = elevator;
   elevator.setOpenDoor(false);
 }
 /** This method tells both elevators that one time unit has passed. */
 private static void recordTick() {
   //  tell each elevator that one unit of time has passed
   System.out.println("Tick.");
   elevator1.tick();
   elevator2.tick();
 } //  end recordTick
  /**
   * Read and process each item in the simulation file. It reads each input item in the file. If a
   * PASSENGER entry, a passenger object is created, and the elevators are checked to see if one is
   * available to service this passenger. If so, the passenger is logically added to the elevator.
   * If an elevator is not available, the passenger must take the stairs.
   *
   * <p>If the input item is a TICK, it indicates that one time unit has passed. At EOF, the method
   * is invoked to shut the elevators down and perform the end of day processing.
   *
   * <p>If an error is detected at any time, this method returns the proper boolean to the calling
   * method.
   *
   * @return True or False to indicate an error
   */
  private static boolean processSimulationFile() {

    // local constants used by this method

    final String PASSENGER = "passenger";
    final String TICK = "tick";
    final String SIMULATION_END = "done";

    boolean done = false; // set when done
    boolean error = false; // set if error detected
    boolean addedOK = false; // set if no elevator is available
    Passenger newPass = null; // new passenger object
    Elevator availableEl = null; // elevator object

    // Read next token from file and process

    try {
      while (!done && !error && in.nextToken() != in.TT_EOF) {

        if (in.sval.equals(PASSENGER)) {
          //  if a new passenger, create a new object, look
          //  for an elevator and add to elevator.  If elevator
          //  is not available, passenger takes the stairs.

          newPass = newPassenger();
          availableEl = findElevator(newPass);
          if (availableEl == null) takingStairs(newPass);
          else {
            System.out.print(
                "Passenger: "
                    + newPass.getName()
                    + " arrives on floor "
                    + newPass.getFloor()
                    + ".");
            addedOK = availableEl.addPassenger(newPass);
            if (!addedOK) {
              error = true;
            }
          }
        } else if (in.sval.equals(TICK)) {
          // token read from file is a time indicator
          recordTick();

        } else if (in.sval.equals(SIMULATION_END)) {
          // end of file == end of workday
          done = true;
        } else {
          error = true;
        }
      } // end while

      if (in.nextToken() == in.TT_EOF) {
        //  perform end of day reporting
        endOfDay();
      }

      // catch for file exception
    } catch (IOException e) {
      error = true;
    } // end try

    return error;
  } //  end processSimulationFile
Exemple #13
0
 public void log() {
   pdp.log();
   drivetrain.log();
   elevator.log();
   toteContact.log();
 }