Beispiel #1
0
  @Override
  public double[] getControls() {
    JXInputManager.updateFeatures();

    double e = -ax_y.getValue();
    if (Math.abs(e) < 0.1) {
      e = 0.0;
    }
    double a = ax_x.getValue();
    if (Math.abs(a) < 0.1) {
      a = 0;
    }
    double t = ax_t.getValue();

    if (Math.abs(t) < 0.2) {
      t = 0.2 * pid_t.update(speed);
    } else {
      t = 0.5 + t * 0.5;
    }
    if (t > 0.1 || altitude > 5) {
      pid_t.setRef(10 * (1 + t));
      t = pid_t.update(speed);
      t = (t + 1) / 2;
    } else {
      t = 0;
    }

    pid_a.setRef(a * 8);
    if (altitude > 5) {
      a = pid_a.update(roll * 180 / Math.PI);
    } else {
      //            pid_a.update(roll * 180 / Math.PI);
    }

    if (altitude > 5) {
      pid_h.setRef(25 + e * 10);
      double h = pid_h.update(altitude);
      pid_e.setRef(-15 * h);
      e = pid_e.update(pitch * 180 / Math.PI);
      // Compensatre for roll
      double r = 4; // r = m*g/2k
      e -= r * roll * roll;
    }

    //        t= -1; // Debug

    //        System.out.println(String.format("roll: %3.2f  A: %2.2f", roll, a));
    //        System.out.println(String.format("speed: %3.2f  T: %2.2f", speed, t));

    double[] result = {e + a, e - a, t};

    //        System.out.println(String.format("t: %1.3f",t));
    //        System.out.println(String.format("e: %1.3f", e));
    //        System.out.println(String.format("h: %1.3f", h));

    return result;
  }
 @Override
 public void changed(final JXInputAxisEvent jxiae) {
   final Axis axis = jxiae.getAxis();
   final boolean neg = axis.getValue() < -0.5;
   final boolean beyondThreshold = Math.abs(axis.getValue()) > 0.5;
   if (Controllers.this.polling && !this.conflicting(axis) && beyondThreshold) {
     if (Controllers.this.pollType == 0) {
       Controllers.this.upA = axis;
       Controllers.this.upAName = axis.getName();
       Controllers.this.upANeg = neg;
       final Game access$400 = Controllers.this.game;
       ++access$400.controllerSelectionIndex;
       Controllers.this.getControl(1);
     } else if (Controllers.this.pollType == 1) {
       Controllers.this.downA = axis;
       Controllers.this.downAName = axis.getName();
       Controllers.this.downANeg = neg;
       final Game access$2 = Controllers.this.game;
       ++access$2.controllerSelectionIndex;
       Controllers.this.getControl(2);
     } else if (Controllers.this.pollType == 2) {
       Controllers.this.leftA = axis;
       Controllers.this.leftAName = axis.getName();
       Controllers.this.leftANeg = neg;
       final Game access$3 = Controllers.this.game;
       ++access$3.controllerSelectionIndex;
       Controllers.this.getControl(3);
     } else if (Controllers.this.pollType == 3) {
       Controllers.this.rightA = axis;
       Controllers.this.rightAName = axis.getName();
       Controllers.this.rightANeg = neg;
       final Game access$4 = Controllers.this.game;
       ++access$4.controllerSelectionIndex;
       Controllers.this.getControl(5);
     }
   }
   if ((Controllers.this.upA != null & axis == Controllers.this.upA)
       && axis.getName().equals(Controllers.this.upAName)) {
     Controllers.this.upPressed = (Controllers.this.upANeg == neg && beyondThreshold);
   }
   if (Controllers.this.downA != null
       && axis == Controllers.this.downA
       && axis.getName().equals(Controllers.this.downAName)) {
     Controllers.this.downPressed = (Controllers.this.downANeg == neg && beyondThreshold);
   }
   if (Controllers.this.leftA != null
       && axis == Controllers.this.leftA
       && axis.getName().equals(Controllers.this.leftAName)) {
     Controllers.this.leftPressed = (Controllers.this.leftANeg == neg && beyondThreshold);
   }
   if (Controllers.this.rightA != null
       && axis == Controllers.this.rightA
       && axis.getName().equals(Controllers.this.rightAName)) {
     Controllers.this.rightPressed = (Controllers.this.rightANeg == neg && beyondThreshold);
   }
 }