edu.wpi.first.wpilibj.Joystick Java Examples
The following examples show how to use
edu.wpi.first.wpilibj.Joystick.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubsystemDrive.java From PowerUp-2018 with GNU General Public License v3.0 | 6 votes |
/** * simple rocket league drive code (not actually rocket league) * independent rotation and acceleration */ public void driveRLTank(Joystick joy, double ramp, double inhibitor) { double adder = Xbox.RT(joy) - Xbox.LT(joy); double left = adder + (Xbox.LEFT_X(joy) / 1.333333); double right = adder - (Xbox.LEFT_X(joy) / 1.333333); left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left)); right = (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right)); setRamps(ramp); // if (getYAngle() > Constants.TILT_ANGLE ) { // leftMaster.set(ControlMode.PercentOutput, -1*Constants.RECOVERY_SPEED); // rightMaster.set(ControlMode.PercentOutput, -1*Constants.RECOVERY_SPEED); // } else if (getYAngle() < -1*Constants.TILT_ANGLE){ // leftMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED); // rightMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED); // } else { leftMaster.set(ControlMode.PercentOutput, leftify(left)); rightMaster.set(ControlMode.PercentOutput, rightify(right)); // } }
Example #2
Source File: Hardware.java From strongback-java with MIT License | 6 votes |
/** * Create a Microsoft Xbox360 gamepad controlled by the Driver Station. * * @param port the port on the driver station that the gamepad is plugged into * @return the input device; never null */ public static Gamepad xbox360(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return Gamepad.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV, () -> joystick.getRawAxis(0), () -> joystick.getRawAxis(1) * -1, () -> joystick.getRawAxis(4), () -> joystick.getRawAxis(5) * -1, () -> joystick.getRawAxis(2), () -> joystick.getRawAxis(3), () -> joystick.getRawButton(5), () -> joystick.getRawButton(6), () -> joystick.getRawButton(1), () -> joystick.getRawButton(2), () -> joystick.getRawButton(3), () -> joystick.getRawButton(4), () -> joystick.getRawButton(8), () -> joystick.getRawButton(7), () -> joystick.getRawButton(9), () -> joystick.getRawButton(10)); }
Example #3
Source File: Hardware.java From strongback-java with MIT License | 6 votes |
/** * Create a Logitech F310 gamepad controlled by the Driver Station. * * @param port the port on the driver station that the gamepad is plugged into * @return the input device; never null */ public static Gamepad logitechF310(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return Gamepad.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV, () -> joystick.getRawAxis(0), () -> joystick.getRawAxis(1) * -1, () -> joystick.getRawAxis(4), () -> joystick.getRawAxis(5) * -1, () -> joystick.getRawAxis(2), () -> joystick.getRawAxis(3), () -> joystick.getRawButton(4), () -> joystick.getRawButton(5), () -> joystick.getRawButton(0), () -> joystick.getRawButton(1), () -> joystick.getRawButton(2), () -> joystick.getRawButton(3), () -> joystick.getRawButton(7), () -> joystick.getRawButton(6), () -> joystick.getRawButton(8), () -> joystick.getRawButton(9)); }
Example #4
Source File: Hardware.java From strongback-java with MIT License | 6 votes |
/** * Create a Logitech DualAction gamepad controlled by the Driver Station. * * @param port the port on the driver station that the gamepad is plugged into * @return the input device; never null */ public static Gamepad logitechDualAction(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return Gamepad.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV, () -> joystick.getRawAxis(0), () -> joystick.getRawAxis(1) * -1, () -> joystick.getRawAxis(2), () -> joystick.getRawAxis(3) * -1, () -> joystick.getRawButton(6) ? 1.0 : 0.0, () -> joystick.getRawButton(7) ? 1.0 : 0.0, () -> joystick.getRawButton(4), () -> joystick.getRawButton(5), () -> joystick.getRawButton(1), () -> joystick.getRawButton(2), () -> joystick.getRawButton(0), () -> joystick.getRawButton(3), () -> joystick.getRawButton(9), () -> joystick.getRawButton(8), () -> joystick.getRawButton(10), () -> joystick.getRawButton(11)); }
Example #5
Source File: SubsystemMast.java From PowerUp-2018 with GNU General Public License v3.0 | 6 votes |
/** raise the mast at RT-LR trigger speed */ public void moveBySpeed(Joystick joy, double inhibitor) { double dualAction = Xbox.RT(joy) - Xbox.LT(joy); double screwSpeed = Xbox.LEFT_Y(joy) + dualAction; double pinionSpeed = Xbox.RIGHT_Y(joy) + dualAction; if (!lowerPinionLimit.get() && pinionSpeed > 0) { pinionSpeed = 0; } if (!upperPinionLimit.get() && pinionSpeed < 0) { pinionSpeed = 0; } if (!lowerScrewLimit.get() && screwSpeed > 0) { screwSpeed = 0; } if (!upperScrewLimit.get() && screwSpeed < 0) { screwSpeed = 0; } publishSwitches(); if (!override) { leftPinion.set(ControlMode.PercentOutput, leftPinionate(pinionSpeed)); rightPinion.set(ControlMode.PercentOutput, rightPinionate(pinionSpeed)); screw.set(ControlMode.PercentOutput, inhibitor * screwify(screwSpeed)); } }
Example #6
Source File: SubsystemManipulator.java From PowerUp-2018 with GNU General Public License v3.0 | 6 votes |
/** imitates an engine revving and idling */ public void rev(Joystick joy) { double intensity = Math.abs(Math.sqrt((Math.pow(Xbox.LEFT_X(joy), 2) + Math.pow(Xbox.LEFT_X(joy), 2)))); // intensity is 0.0-1.0, power of trigger int rpm = (int) ((((double) Constants.REDLINE - (double) Constants.IDLE) * intensity) + Constants.IDLE); // rpm is the rpm being imitated int miliseconds = (1 / rpm) * 60000; // length in miliseconds of each rev curve, based on rpm if (!revving) { redlineTime = System.currentTimeMillis(); revving = true; } // reset rev curve if not revving else if (System.currentTimeMillis() - redlineTime >= miliseconds) { revving = false; } // stop revving if time is up double speed = (System.currentTimeMillis() - redlineTime) / (double) miliseconds; // set speed to progress from 0.0-1.0 of the curve speed = speed > 1.0 ? 1.0 : speed; // quick concat the speed under 1.0 speed = generateCurve(speed, 0, .25 * (intensity * .8 + .2), (intensity * .8 + .2)); // find y value on curve, given x and parameters armLeft.set(ControlMode.PercentOutput, leftArmify(speed)); armRight.set(ControlMode.PercentOutput, rightArmify(speed)); }
Example #7
Source File: Hardware.java From strongback-java with MIT License | 5 votes |
/** * Create a Microsoft SideWinder flight stick controlled by the Driver Station. * * @param port the port on the driver station that the flight stick is plugged into * @return the input device; never null */ public static FlightStick microsoftSideWinder(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return FlightStick.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV, () -> joystick.getY() * -1, // pitch is reversed joystick::getTwist, // yaw joystick::getX, // roll joystick::getThrottle, // throttle () -> joystick.getRawButton(1), // trigger () -> joystick.getRawButton(2)); // thumb }
Example #8
Source File: Hardware.java From strongback-java with MIT License | 5 votes |
/** * Create a Logitech Extreme 3D flight stick controlled by the Driver Station. * * @param port the port on the driver station that the flight stick is plugged into * @return the input device; never null */ public static FlightStick logitechExtreme3D(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return FlightStick.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV, joystick::getY, // pitch joystick::getTwist, // yaw joystick::getX, // roll joystick::getThrottle, // flapper thing on bottom () -> joystick.getRawButton(1), // trigger () -> joystick.getRawButton(2)); // thumb }
Example #9
Source File: Hardware.java From strongback-java with MIT License | 5 votes |
/** * Create a Logitech Attack 3 flight stick controlled by the Driver Station. * * @param port the port on the driver station that the flight stick is plugged into * @return the input device; never null */ public static FlightStick logitechAttack3D(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return FlightStick.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV, joystick::getY, // pitch () -> joystick.getTwist() * -1, // yaw is reversed joystick::getX, // roll joystick::getThrottle, // throttle () -> joystick.getRawButton(1), // trigger () -> joystick.getRawButton(2)); // thumb }
Example #10
Source File: SubsystemDrive.java From PowerUp-2018 with GNU General Public License v3.0 | 5 votes |
/** * drive code where rotation is dependent on acceleration * @param radius 0.00-1.00, 1 being zero radius and 0 being driving in a line */ public void driveForza(Joystick joy, double ramp, double radius, double inhibitor) { double left = 0, right = 0; double acceleration = Xbox.RT(joy) - Xbox.LT(joy); setRamps(ramp); // if (getYAngle() > Constants.TILT_ANGLE ) { // leftMaster.set(ControlMode.PercentOutput, -1 * Constants.RECOVERY_SPEED); // rightMaster.set(ControlMode.PercentOutput, -1 * Constants.RECOVERY_SPEED); // } else if (getYAngle() < -1 * Constants.TILT_ANGLE){ // leftMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED); // rightMaster.set(ControlMode.PercentOutput, Constants.RECOVERY_SPEED); // } else { if (!reversing ? Xbox.LEFT_X(joy) < 0 : Xbox.LEFT_X(joy) > 0) { right = acceleration; left = (acceleration * ((2 * (1 - Math.abs(Xbox.LEFT_X(joy)))) - 1)) / radius; } else if (!reversing ? Xbox.LEFT_X(joy) > 0 : Xbox.LEFT_X(joy) < 0) { left = acceleration; right = (acceleration * ((2 * (1 - Math.abs(Xbox.LEFT_X(joy)))) - 1)) / radius; } else { left = acceleration; right = acceleration; } // }][\ left = (left > 1.0 ? 1.0 : (left < -1.0 ? -1.0 : left)); right = (right > 1.0 ? 1.0 : (right < -1.0 ? -1.0 : right)); leftMaster.set(ControlMode.PercentOutput, leftify(left) * inhibitor * (reversing ? -1.0 : 1.0)); rightMaster.set(ControlMode.PercentOutput, rightify(right) * inhibitor * (reversing ? -1.0 : 1.0)); SmartDashboard.putString("Left Master", "Left Master Voltage: " + leftMaster.getBusVoltage()); SmartDashboard.putString("Right Master", "Right Master Voltage: " + rightMaster.getBusVoltage()); }
Example #11
Source File: SubsystemManipulator.java From PowerUp-2018 with GNU General Public License v3.0 | 5 votes |
public void spinByJoystick(Joystick joy) { int speed = 0; speed += joy.getRawButton(Xbox.RB) ? 1d : 0d; speed -= joy.getRawButton(Xbox.LB) ? 1d : 0d; armLeft.set(ControlMode.PercentOutput, leftArmify(speed)); armRight.set(ControlMode.PercentOutput, rightArmify(speed)); }
Example #12
Source File: GamepadDriveControlBoard.java From FRC-2018-Public with MIT License | 4 votes |
private GamepadDriveControlBoard() { mJoystick = new Joystick(Constants.kDriveGamepadPort); }
Example #13
Source File: XboxController.java From FRC-2019-Public with MIT License | 4 votes |
XboxController(int port) { mController = new Joystick(port); }
Example #14
Source File: GamepadButtonControlBoard.java From FRC-2018-Public with MIT License | 4 votes |
private GamepadButtonControlBoard() { mJoystick = new Joystick(Constants.kButtonGamepadPort); }
Example #15
Source File: MainButtonBoard.java From FRC-2018-Public with MIT License | 4 votes |
private MainButtonBoard() { mButtonBoard = new Joystick(2); }
Example #16
Source File: Hardware.java From strongback-java with MIT License | 4 votes |
private static void verifyJoystickConnected(Joystick joystick) { joystick.getButtonCount(); }
Example #17
Source File: MainDriveControlBoard.java From FRC-2018-Public with MIT License | 4 votes |
private MainDriveControlBoard() { mThrottleStick = new Joystick(Constants.kMainThrottleJoystickPort); mTurnStick = new Joystick(Constants.kMainTurnJoystickPort); }
Example #18
Source File: MainDriveControlBoard.java From FRC-2019-Public with MIT License | 4 votes |
private MainDriveControlBoard() { mThrottleStick = new Joystick(Constants.kMainThrottleJoystickPort); mTurnStick = new Joystick(Constants.kMainTurnJoystickPort); }
Example #19
Source File: Hardware.java From strongback-java with MIT License | 2 votes |
/** * Create an generic input device controlled by the Driver Station. * * @param port the port on the driver station that the joystick is plugged into * @return the input device; never null */ public static InputDevice driverStationJoystick(int port) { Joystick joystick = new Joystick(port); verifyJoystickConnected(joystick); return InputDevice.create(joystick::getRawAxis, joystick::getRawButton, joystick::getPOV); }
Example #20
Source File: Xbox.java From PowerUp-2018 with GNU General Public License v3.0 | votes |
public static double LEFT_X(Joystick joy) {return deadzone(joy.getRawAxis(0));}
Example #21
Source File: Xbox.java From PowerUp-2018 with GNU General Public License v3.0 | votes |
public static double RT(Joystick joy) {return joy.getRawAxis(3);}
Example #22
Source File: Xbox.java From PowerUp-2018 with GNU General Public License v3.0 | votes |
public static double LT(Joystick joy) {return joy.getRawAxis(2);}
Example #23
Source File: Xbox.java From PowerUp-2018 with GNU General Public License v3.0 | votes |
public static double RIGHT_Y(Joystick joy) {return deadzone(joy.getRawAxis(5));}
Example #24
Source File: Xbox.java From PowerUp-2018 with GNU General Public License v3.0 | votes |
public static double RIGHT_X(Joystick joy) {return deadzone(joy.getRawAxis(4));}
Example #25
Source File: Xbox.java From PowerUp-2018 with GNU General Public License v3.0 | votes |
public static double LEFT_Y(Joystick joy) {return deadzone(joy.getRawAxis(1));}