Set a trigger to Curvature Drive Quick turn button (Java)

Hi, new to programming and working on creating a curvature drive system. I have the basic parameters and everything working I just dont like where i currently have the quick turn button set (x button) I want to set the quick turn button to the right trigger but the right trigger is an axis and the curvature drive method requires a boolean to be returned. How would I go about doing this, if anyone has example code or can find some it would be greatly appreciated.

You can make the trigger as a button like this. Use the driverstation to figure out which axis the left/right trigger are bound to:

public class XBoxTrigger extends Button {
    Joystick joystick;
    int axis;

    public XBoxTrigger(Joystick joystick, int axis) {
        this.joystick = joystick;
        this.axis = axis;
    }

    public double getTriggerValue() {
        return joystick.getRawAxis(axis);
    }

    @Override
    public boolean get() {
        return joystick.getRawAxis(axis) > 0.15;
    }

}
1 Like

ok, so how would i place that into a curvature drive, and would that go into the OI?
This is my current curvature drive code:
drive.curvatureDrive(move, turn, Robot.oi.stick.getRawButton(RobotMap.joystickPort_QuickTurn));

Your OI would probably look like this:

    Joystick xBoxController = new Joystick(RobotMap.xBoxController);
    public Button xBoxLeftTrigger, xBoxRightTrigger;

    public OI() {
        xBoxLeftTrigger = new XBoxTrigger(xBoxController, 2);
        xBoxRightTrigger = new XBoxTrigger(xBoxController, 3);
    }

And your function call would look like this:

drive.curvatureDrive(move, turn, Robot.oi.xBoxRightTrigger.get());

Edit: If you want it as a toggle, you would need to do something like this:

boolean toggle;

if(Robot.oi.xBoxRightTrigger.get()) {
   toggle = !toggle;
}
drive.curvatureDrive(move, turn, toggle);

The toggle boolean would have to be initialized in the class and not as a part of the loop/function that contains drive.curvatureDrive().

Thank you so much