private void initDevices() { final int devicesCount = JXInputManager.getNumberOfDevices(); if (devicesCount > 0) { this.devices = new Device[devicesCount]; for (int i = 0; i < devicesCount; ++i) { this.devices[i] = new Device(i, JXInputManager.getJXInputDevice(i)); } } else { this.devices = new Device[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; }
public GamePadPilot() { JXInputDevice dev = JXInputManager.getJXInputDevice(0); ax_x = dev.getAxis(0); ax_y = dev.getAxis(1); ax_t = dev.getAxis(2); pid_t = new PIDController(0.15, 0.3, 0); pid_a = new PIDController(0.04, 0, 0.1); pid_e = new PIDController(0.04, 0, 0.1); pid_h = new PIDController(0.3, 0.01, 0.2); }
public void pollDevices() { final boolean upWasPressed = this.upPressed; final boolean downWasPressed = this.downPressed; final boolean leftWasPressed = this.leftPressed; final boolean rightWasPressed = this.rightPressed; JXInputManager.updateFeatures(); if (this.controlsSet) { if (!this.game.input.defUpDown || this.upPressed) { this.game.input.upDown = this.upPressed; } if (!this.game.input.defDownDown || this.downPressed) { this.game.input.downDown = this.downPressed; } this.game.input.leftDown = this.leftPressed; this.game.input.rightDown = this.rightPressed; this.game.input.runDown = this.bPressed; this.game.input.jumpDown = this.aPressed; if (!this.game.input.defStartDown || this.startPressed) { this.game.input.startDown = this.startPressed; } if (!upWasPressed && this.upPressed) { final Input input = this.game.input; this.game.input.getClass(); input.addCheatKey(38); } else if (!downWasPressed && this.downPressed) { final Input input2 = this.game.input; this.game.input.getClass(); input2.addCheatKey(40); } else if (!leftWasPressed && this.leftPressed) { final Input input3 = this.game.input; this.game.input.getClass(); input3.addCheatKey(37); } else if (!rightWasPressed && this.rightPressed) { final Input input4 = this.game.input; this.game.input.getClass(); input4.addCheatKey(39); } } }