lobobellos / robot_code_2022

robot code for the 2022 season
Other
2 stars 0 forks source link

xbox 360 support #1

Open watmay1 opened 2 years ago

watmay1 commented 2 years ago

many people on the team want xbox 360 support and ive thought about it and forward and back and side to side (when we fix the mecanum wheels) and have rotation on the analog triggers. we could then map things like the intake and shooter and climber to face buttons (a b x y)

watmay1 commented 2 years ago

import edu.wpi.first.wpilibj.XboxController;

public class XboxController { // XboxController Port (You can see the port of the controller in FRC Driver Station) private final int controllerPort = 0; // An XboxController at that port private final XboxController controller = new XboxController(controllerPort);

// Controller Joysticks. X axis is horizontal value of joystick, y axis is vertical.
// Fully left on the X axis gives a value of -1, fully right gives a value of 1.
// Fully down on the Y axis gives a value of -1, fully up gives a value of 1.
private double leftYAxisValue, leftXAxisValue, rightYAxisValue, rightXAxisValue;
// Controller Triggers. 0 is completely released, 1 is completely pressed, 0.5 is half pressed etc.
private double leftTriggerValue, rightTriggerValue;
// Controller Buttons and Bumpers
private boolean rightBumperPressed, leftBumperPressed;
private boolean aButtonPressed, bButtonPressed, yButtonPressed, xButtonPressed;
// Controller DPad Angle (It's dumb and gives you the "angle" of the DPad. For example, 90 degrees is right, 180 down, 270 left, 0 up)
private int dpadAngle;

public XboxController() {
    // Joystick Axis
    leftYAxisValue = controller.getLeftY();
    leftXAxisValue = controller.getLeftX();
    rightYAxisValue = controller.getRightY();
    rightXAxisValue = controller.getRightX();

    // Trigger Axis
    leftTriggerValue = controller.getLeftTriggerAxis();
    rightTriggerValue = controller.getRightTriggerAxis();

    // Bumper Buttons
    rightBumperPressed = controller.getRightBumper();
    leftBumperPressed = controller.getLeftBumper();

    // Some other buttons
    aButtonPressed = controller.getAButton();
    bButtonPressed = controller.getBButton();
    xButtonPressed = controller.getXButton();
    yButtonPressed = controller.getYButton();

    // Dpad
    dpadAngle = controller.getPOV();
}

}

watmay1 commented 2 years ago

just some starter code

bakedPotatoLord commented 1 year ago

This sounds like a great idea!

You should get started on it.

watmay1 commented 1 year ago

alrightie just point me to where the current code handling the joystick input is

bakedPotatoLord commented 1 year ago

its in https://github.com/lobobellos/robot_code_2022/blob/main/src/main/java/frc/robot/RobotContainer.java I've made a branch for this pull request.