Log in

View Full Version : How to Program an XBOX Controller


LFRobotics
23-04-2014, 18:48
Hey robot peeps - our team is preparing for next years competition and we are completely lost on how to program in an XBOX controller. We drove using tankdrive this year and are using command base java. ANY help will be greatly appreciated.

THANKS!

cgmv123
23-04-2014, 18:51
First, make sure you're using wired XBOX controllers. Wireless controls of any sort are illegal in competition.

Here's the class we use: https://github.com/team1306/BadgerbotsLib/blob/master/src/org/badgerbots/lib/XBoxController.java

Just use XBoxController xcon = new XBoxController(port #); to instantiate it and xcon.getWhatever(); to access it. Joysticks and triggers are returned as doubles and buttons are returned as booleans.

To program TankDrive, you can simply assign the Y-axis of the left joystick to the left motor(s) and the Y-axis of the right joystick to the right motor(s). I recommend cubing the inputs for better control and dealing with the deadband. (You'll want at least a 10 percent deadband.)

Note the comment regarding the triggers. We've never had an issue with it, but it's something to be aware of. (It's also unavoidable, since it has to do with how Windows reads the controller.)