Exemple #1
0
  public static void main(String[] args) throws InterruptedException {

    List<Info> devices = Joy.listDevices();

    if (devices.isEmpty()) {
      System.out.println("No devices connected!");
      return;
    }

    for (Info info : devices) {
      System.out.println(info.description());
    }

    Joystick joystick = Joystick.create(devices.get(0));

    while (true) {
      joystick.update();
      System.out.println(joystick);

      Thread.sleep(30);
    }
  }
Exemple #2
0
  public void playGame() {
    Joystick joystick = game.getJoystick();

    do {
      printBoard();

      String line = console.read();
      boolean bomb = false;
      boolean move = false;
      for (Character ch : line.toCharArray()) {
        if (ch == 's' || ch == 'ы') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.down();
          move = true;
        } else if (ch == 'a' || ch == 'ф') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.left();
          move = true;
        } else if (ch == 'd' || ch == 'в') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.right();
          move = true;
        } else if (ch == 'w' || ch == 'ц') {
          if (move) {
            game.tick();
            bomb = false;
          }
          joystick.up();
          move = true;
        } else if (ch == ' ') {
          if (bomb) {
            game.tick();
            move = false;
          }
          joystick.act();
          bomb = true;
        }
      }
      game.tick();
    } while (!game.isGameOver());

    printBoard();
    console.print("Game over!");
  }
  public void operatorControl() {
    while (this.isEnabled()) {
      if (controller.getRawButton(1)) {
        aButtonPressed = true;
      } else if (aButtonPressed) {
        aButtonPressed = false;

        if (!aButtonPressed) {
          in.set(false);
          out.set(false);
        }
      }

      if (controller.getRawButton(2)) {
        bButtonPressed = true;
      } else if (bButtonPressed) {
        bButtonPressed = false;

        if (!bButtonPressed) {
          in.set(false);
          out.set(false);
        }
      }

      if (controller.getRawButton(3)) {
        xButtonPressed = true;
      } else if (xButtonPressed) {
        xButtonPressed = false;

        if (!xButtonPressed) valve.set(Relay.Value.kOff);
      }

      if (controller.getRawButton(4)) {
        yButtonPressed = true;
      } else if (yButtonPressed) {
        yButtonPressed = false;

        valve.set(Relay.Value.kOff);
      }

      if (aButtonPressed) {
        out.set(false);
        in.set(true);
      }

      if (bButtonPressed) {
        in.set(false);
        out.set(true);
      }

      if (xButtonPressed) {
        SmartDashboard.putBoolean("compressorOn", true);
        valve.set(Relay.Value.kOn);
      }

      SmartDashboard.putBoolean("compressorOn", xButtonPressed);
      SmartDashboard.putBoolean("pistonOut", aButtonPressed);
      SmartDashboard.putBoolean("pistonIn", bButtonPressed);

      SmartDashboard.putBoolean("pressure relief", input.get());
      // System.out.println("output " + input.get());

      if (input.get()) {
        System.out.println("INPUT RETURNED TRUE, SETTING VALVE TO OFF");
        valve.set(Relay.Value.kOff);
      }

      Timer.delay(.1);
    }
  }
Exemple #4
0
  public void teleopPeriodic() {
    watchdog.feed(); // feed the watchdog
    // Toggle drive mode
    if (!driveToggle && left.getRawButton(2)) {
      driveMode = (driveMode + 1) % 3;
      driveToggle = true;
    } else if (driveToggle && !left.getRawButton(2)) driveToggle = false;

    // Print drive mode to DS & send values to Jaguars
    switch (driveMode) {
      case 0:
        dsLCD.println(DriverStationLCD.Line.kMain6, 1, "Drive mode: Tank  ");
        red.set(left.getY() + gamePad.getY());
        black.set(-right.getY() - gamePad.getThrottle());
        break;
      case 1:
        dsLCD.println(DriverStationLCD.Line.kMain6, 1, "Drive mode: Arcade");
        red.set(right.getX() - right.getY());
        black.set(right.getX() + right.getY());
        break;
      case 2:
        dsLCD.println(DriverStationLCD.Line.kMain6, 1, "Drive mode: Kaj   ");
        red.set(left.getX() - right.getY());
        black.set(left.getX() + right.getY());
        break;
    } /**/
    dsLCD.println(
        DriverStationLCD.Line.kUser3,
        1,
        "1" + photoreceptorL.get() + "2" + photoreceptorM.get() + "3" + photoreceptorR.get());
    dsLCD.println(DriverStationLCD.Line.kUser4, 1, "Encoder in 4,5: " + leftEncoder.get() + "    ");
    dsLCD.println(
        DriverStationLCD.Line.kUser5, 1, "Encoder in 6,7: " + rightEncoder.get() + "    ");

    dsLCD.updateLCD();
  }