View Full Version : Xbox Controller Tank Drive
tuXguy15
11-03-2013, 17:53
Hello. My team would like to use a tank drive system to drive our robot. I know how to do it with two joysticks but not 1 joystick that is an xbox controller. Can anyone help? Thanks!
Instantiate the controller as a joystick.
The different physical stick on the controller are different axis to the code. You'll have to hack a bit/google to figure it out, I can't remember off the top of my head. The triggers are also another axis, with one pulling it negative, and the other pulling it positive.
I hope this helps.
JefferMC
12-03-2013, 10:46
As tp said, you can treat the XBox controller as a very strange joystick that has 6 different axes:
1 Left Joystick X
2 Left Joystick Y
3 Triggers
4 Right Joystick X
5 Right Joystick Y
6 DPAD X (never used this)
So, do joystick.GetRawAxis(2) for the left tank drive and joystick.GetRawAxis(5) for the right. You may need to change the signs of the input to get what you want.
Here is our XBOX Class (https://github.com/frc3946/UltimateAscent/blob/master/src/org/usfirst/frc3946/UltimateAscent/XboxController.java)
Here is our TankDrive Command (https://github.com/frc3946/UltimateAscent/blob/master/src/org/usfirst/frc3946/UltimateAscent/commands/TankDrive.java)
We init an XboxController object in the OI, and I have everything mapped out in the class for the axis. Makes it very simple to call from commands.
ekapalka
12-03-2013, 13:59
Go to run on your computer (if you're using Windows) and search for / run "joy.cpl" (without quotes). Then go to properties (I think) and it should show you everything you could ever need to know about mapping the controller.
tuXguy15
12-03-2013, 18:10
Ok thanks guys ill try that
AlexBrinister
14-03-2013, 21:36
We used one too! You can look at this (https://github.com/Nashoba-Robotics/Nashoba-Robotics2013-SimpleRobot/blob/alex/Pads.hpp) code. It's in C++ but the WPI syntax should be similar.
Alex Brinister
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.