Simple library for XBox controllers

I am a member of Team 2081. At the end of last year’s build season, our software mentor had an idea: “Why not make an open source library to handle all of the controller code?” I really liked the idea of writing something that could be used not only by my team, but by other teams who might have use for it.

Over the summer, I did a lot of work with programming in C#, which helped me learn a lot about object-oriented programming. I didn’t think much of it at the time but without that extra learning, I probably wouldn’t have been able to write this.

So, as this build season was getting started, I decided to take a shot at making a controller library. I had started some of the basic stuff in the off season for a competition, but it wasn’t very good so I scraped it. The code itself can be found here.

It’s worth noting that this library was made with using a standard XBox 360 controller in mind, so not all controllers will be compatible. I’m planning on adding something for compatibility in the near future, so watch for that if you’re interested.

Feel free to use this code if you want, after all I made it not just for my team, but for everyone :smiley:

Looks very nice, and man would it have been nice to have in years past.

Coincidentally, WPILib actually just added an XBoxController class that makes it a lot less painless that is very similar to your code. Maybe they were cheating off of you :slight_smile:

My initial implementation of the XboxController class was based on I replaced the base classes with GamepadBase and JoystickBase to deduplicate the implementations of Joystick and XboxController.

I also wrote a button state tracker for Joysticks a few years ago that I submitted this year ( It’s intended to be used with SampleRobot since Command-based robots already have the capability to run commands upon button state edges (see the ButtonScheduler commands). It wasn’t merged in time for 2017 because we had other concerns to focus on for release. It uses raw button numbers, so using it for an XboxController wouldn’t be clean. Perhaps an enum could be used to map the button names (A, B, X, Y) to the raw button number.