How to set an `whenHeld()` method on an x-box controller's `R_2` button

My code does the following to control the commands to execute when certain buttons are pressed:

//Map buttons 3 and 4 on the controller to extend and retract the piston, respectively:
    final JoystickButton extendPistonButton = new JoystickButton(m_driverController, 3);
    final JoystickButton retractPistonButton = new JoystickButton(m_driverController, 4);

    //Define each button's behaviour:
    extendPistonButton.whenHeld(pneumaticsExtendPistonCommand);
    retractPistonButton.whenHeld(pneumaticsRetractPistonCommand);

What number do I need to pass into the JoystickButton() constructor to map it to the Driver’s Station’s Axes 3 button? (pictured below)

The right trigger is an axis, not a button. As such, you can’t make a JoystickButton object out of it. You would have to do something like rebinding to a real button or running the desired code based on the value of the trigger being > 0.

See Creating Your Own Custom Trigger for documentation on how to do this.

1 Like

See https://github.com/FRC2495/FRC2495-2020/blob/master/src/main/java/frc/robot/util/GamepadAxis.java

Huh, the more you know

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.