Can you start a command from an XBoxController trigger?

We’ve worked from the Binding Commands to Triggers and gotten it to work fine with the button enum. But we’d like to use the triggers and I don’t understand why they’re not part of the enum.

I see there’s a getTriggerAxis() method, where you pass in the Left or Right Hand, but it returns a double - how do you use that double result to start a command? I just need a boolean, on/off, not a range

The triggers on an xbox controller (or similar gamepad device) are analog values like the thumb sticks commonly used for driving. They don’t return a boolean (true/false… pressed/not pressed) value, and instead return a range of possible values.

There are numerous code examples on how to do it posted here by teams, but the most common is to simply check the trigger value against a threshold(i.e. >= 0.5). I believe most teams extend the Button class (just like how JoystickButton does) and add the check there. Then you can use it like any other button. Sorry my advice isn’t more specific, I’m not in front of the code at the moment.

As stated by @Fletch1373 the Triggers on an XBox Controller are Analog, and the traditional way to use those as Trigger/Buttons is to check against a threshold.

If you check under the Creating Your Own Custom Trigger on the page you linked, it shows options for creating your own Trigger/Buttons. I’d personally go with the lambda method. Something like

Button leftTriggerButton = new Button(() -> xboxController.getTriggerAxis(Hand.kLeft) >= 0.5);
1 Like

You could take the class linked here as well

1 Like

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