Exemple #1
0
  private void followLine(boolean startChainBridge) {
    this.lineFollowing = new LineFollowing(drive, colorSensor);
    lineFollowing.run(startChainBridge);

    // Start search for barcode.
    if (RACE_MODE && PROGRAM_FINISHED_START_BARCODE) {
      PROGRAM_FINISHED_START_BARCODE = false;
      LCD.clear();
      System.out.println("Mode: Barcode");
      barcode(true);
    } else if (RACE_MODE && PROGRAM_STATUS == PROGRAM_BRIDGE) {
      PROGRAM_CHANGED = false;
      LCD.clear();
      System.out.println("Mode: Bridge");
      bridge();
    }
  }
Exemple #2
0
  /*
   * Initializing the seesaw mode.
   */
  private void seesaw() {
    this.seesaw = new Seesaw(drive, colorSensor);
    seesaw.run();

    // Start search for barcode.
    if (RACE_MODE && PROGRAM_FINISHED_START_BARCODE) {
      PROGRAM_FINISHED_START_BARCODE = false;
      LCD.clear();
      System.out.println("Mode: Barcode");
      barcode(true);
    }
  }
Exemple #3
0
  /*
   * Initializing the roll mode.
   */
  private void rolls() {
    this.rolls = new Rolls(drive, sonicSensor, sonicMotor, colorSensor);
    rolls.run();

    // Start search for barcode.
    if (RACE_MODE && PROGRAM_FINISHED_START_BARCODE) {
      PROGRAM_FINISHED_START_BARCODE = false;
      LCD.clear();
      System.out.println("Mode: Barcode");
      barcode(true);
    }
  }
Exemple #4
0
  /*
   * Initializing the bridge mode.
   */
  private void bridge() {
    this.bridge = new Bridge(drive, sonicMotor, leftMotor, rightMotor, sonicSensor, colorSensor);
    bridge.run();

    // Change bridge -> elevator
    if (RACE_MODE && PROGRAM_CHANGED && PROGRAM_STATUS == PROGRAM_ELEVATOR) {
      PROGRAM_CHANGED = false;
      LCD.clear();
      System.out.println("Mode: Elevator");
      elevator();
    }
  }
Exemple #5
0
  /*
   * Initializing the final spurt.
   */
  private void finalSpurt() {
    FinalSpurt finalSpurt =
        new FinalSpurt(
            drive, sonicSensor, touchLeftSensor, touchRightSensor, sonicMotor, colorSensor);
    finalSpurt.run();

    // Change final spurt -> final boss
    if (RACE_MODE && PROGRAM_CHANGED && PROGRAM_STATUS == PROGRAM_FINAL_BOSS) {
      PROGRAM_CHANGED = false;
      LCD.clear();
      System.out.println("Mode: Final Boss");
      finalBoss();
    }
  }
Exemple #6
0
  /*
   * Initializing the elevator mode.
   */
  private void elevator() {
    this.elevator =
        new Elevator(
            drive, colorSensor, touchLeftSensor, touchRightSensor, sonicSensor, sonicMotor);
    elevator.run();

    // Start search for barcode.
    if (RACE_MODE && PROGRAM_FINISHED_START_BARCODE) {
      PROGRAM_FINISHED_START_BARCODE = false;
      LCD.clear();
      System.out.println("Mode: Barcode");
      barcode(true);
    }
  }
Exemple #7
0
  /*
   * Start program to read a barcode. If a valid barcode could be found the
   * next program will be loaded.
   */
  private void barcode(boolean moveRobot) {
    this.barcode = new Barcode(drive, colorSensor, moveRobot);
    barcode.run();

    if (barcode != null) {
      int foundBarcode = barcode.getBarcode();
      LCD.clear();
      // System.out.println("Barcode: " + foundBarcode);

      if (foundBarcode != -1) {
        // Change the current program if a valid barcode has been found
        changeProgram(foundBarcode);
      }
    }
  }
  private void elevatorCollision() {
    LCD.clear();
    LCD.drawString("Collision: " + collision, 0, 4);
    Delay.msDelay(3000);
    float[] dist = new float[sonicSensor.getDistanceMode().sampleSize()];
    sonicSensor.getDistanceMode().fetchSample(dist, 0);

    if ((dist[0] - DISTANCE_TO_WALL) > 0.005) {
      drive.turnRight(5, false);
    } else {
      drive.turnLeft(5, false);
    }
    if (collision == "Wall") {
      drive.stop();
    } else if (collision == "Left Wall") {
      drive.turnRight(5, false);
    } else if (collision == "Right Wall") {
      drive.moveDistance(drive.maxSpeed(), -2);
      drive.turnLeft(20, false);
    }
  }
Exemple #9
0
  /** Initializes the main menu that enables the user to select a certain obstacle mode. */
  public GUI() {

    LCD.clear(); // Make sure display is clear before the menu is displayed

    // Stop current obstacle program if the left button is pressed
    Button.LEFT.addKeyListener(
        new KeyListener() {
          @Override
          public void keyPressed(Key k) {
            endAllPrograms();
          }

          @Override
          public void keyReleased(Key k) {}
        });

    // Stop program when the escape button is pressed on the ev3 brick
    Button.ESCAPE.addKeyListener(
        new KeyListener() {
          @Override
          public void keyPressed(Key k) {
            drive.stop();

            endAllPrograms();

            // Start the GUI again => main menu should be shown
            // when the obstacle program has been interrupted
            startGUI();
          }

          @Override
          public void keyReleased(Key k) {}
        });

    startGUI();
  }
Exemple #10
0
 private void displayMessage(String message) {
   LCD.drawString(message, xPosition, yPosition);
   Delay.msDelay(waitTime);
   LCD.clear();
 }
Exemple #11
0
  /*
   * Helper method to initialize the GUI/creating the main menu.
   */
  private void startGUI() {
    // Creating the menu to select certain robot states/obstacles.
    while (true) {

      // The elements of the menu to display on the ev3 brick
      String[] viewItems = {
        "Labyrinth",
        "Linie folgen",
        "Bruecke",
        "Haengebruecke",
        "Rollen",
        "Wippe",
        "Aufzug",
        "Endspurt",
        "Endgegner",
        "Exit",
        "Barcode"
      };

      TextMenu menu = new TextMenu(viewItems, 1);
      // LCD.clear();
      int selection = menu.select();

      /*
       * Menu selection. Selection number is the index of the element in
       * the viewItems array.
       */
      if (selection == -1) {
        // ESCAPE button pressed. End loop
        break;
      } else if (selection == 0) {
        // Maze
        LCD.clear();
        LCD.drawString("Mode: Labyrinth", 0, 0);
        PROGRAM_STATUS = PROGRAM_MAZE;
        maze();
      } else if (selection == 1) {
        // Follow line
        LCD.clear();
        LCD.drawString("Mode: Linie folgen", 0, 0);
        PROGRAM_STATUS = PROGRAM_FOLLOW_LINE;
        followLine(false);
      } else if (selection == 2) {
        // Bridge
        LCD.clear();
        LCD.drawString("Mode: Bruecke", 0, 0);
        PROGRAM_STATUS = PROGRAM_BRIDGE;
        bridge();
      } else if (selection == 3) {
        // Chain bridge
        LCD.clear();
        LCD.drawString("Mode: Haengebruecke", 0, 0);
        PROGRAM_STATUS = PROGRAM_CHAIN_BRDIGE;
        chainBridge();
      } else if (selection == 4) {
        // Rolls
        LCD.clear();
        LCD.drawString("Mode: Rollen", 0, 0);
        PROGRAM_STATUS = PROGRAM_ROLLS;
        rolls();
      } else if (selection == 5) {
        // Seesaw
        LCD.clear();
        LCD.drawString("Mode: Wippe", 0, 0);
        PROGRAM_STATUS = PROGRAM_SEESAW;
        // seesaw();
        followLine(false);
      } else if (selection == 6) {
        // Elevator
        LCD.clear();
        LCD.drawString("Mode: Aufzug", 0, 0);
        PROGRAM_STATUS = PROGRAM_ELEVATOR;
        elevator();
      } else if (selection == 7) {
        // Final spurt
        LCD.clear();
        LCD.drawString("Mode: Endspurt", 0, 0);
        PROGRAM_STATUS = PROGRAM_FINAL_SPURT;
        finalSpurt();
      } else if (selection == 8) {
        // Final boss
        LCD.clear();
        LCD.drawString("Mode: Endgegner", 0, 0);
        PROGRAM_STATUS = PROGRAM_FINAL_BOSS;
        finalBoss();
      } else if (selection == 9) {
        // Terminate whole program on ev3 brick
        LCD.clear();
        PROGRAM_STATUS = PROGRAM_EXIT;
        System.exit(0);
      } else if (selection == 10) {
        // Barcode
        LCD.clear();
        LCD.drawString("Mode: Barcode", 0, 0);
        PROGRAM_STATUS = PROGRAM_BARCODE;
        barcode(true);
      }

      PROGRAM_STATUS = -1;
    }
  }