Log in

View Full Version : How to use Xbox controller with RobotPy?


team-4480
19-01-2015, 16:40
Hi! So we have our code working with the Xbox controller's left joystick but that was just using the self.stick=wpilib.Joystick(0) and we can't figure out how to use the right joystick with it. Any help would be greatly appreciated!

virtuald
19-01-2015, 18:20
Recommend you search the forums, as your problem is a WPILib problem, and not necessarily specific to RobotPy.

Here's one that looks useful: http://www.chiefdelphi.com/forums/showthread.php?t=133019&highlight=xbox

team-4480
19-01-2015, 18:36
Recommend you search the forums, as your problem is a WPILib problem, and not necessarily specific to RobotPy.

Here's one that looks useful: http://www.chiefdelphi.com/forums/showthread.php?t=133019&highlight=xbox

After so more research, it seems like I have to make a AxisType Class and then put in what each axis is? Thanks for the response!

virtuald
19-01-2015, 19:11
After so more research, it seems like I have to make a AxisType Class and then put in what each axis is? Thanks for the response!

Yeah, the docs aren't super clear on that, I'll need to update. When AxisType is specified, what it really means is pass in one of the constants that is defined in the class, or you can also just pass in a number. So something like...


joystick = wpilib.Joystick(0)
rightX = joystick.getAxis(4)
rightY = joystick.getAxis(5)


That might work. It might not.

Nunez4296
19-01-2015, 19:17
From the looks of it, your code is only written for one axis, axis 0. That is most likely the reason why only the left side is working. Go to the driver station with your controller plugged in and then to the USB panel. There you will find the connected joystick and all the buttons. Any button you press or joystick you move will show you the associated button value that you should implement into the code. remember that these are all array values, so you start with axis 0 and button 0.

team-4480
19-01-2015, 20:30
From the looks of it, your code is only written for one axis, axis 0. That is most likely the reason why only the left side is working. Go to the driver station with your controller plugged in and then to the USB panel. There you will find the connected joystick and all the buttons. Any button you press or joystick you move will show you the associated button value that you should implement into the code. remember that these are all array values, so you start with axis 0 and button 0.

Thanks to both of you for the help and I will try it tomorrow!

team-4480
20-01-2015, 17:33
Yeah, the docs aren't super clear on that, I'll need to update. When AxisType is specified, what it really means is pass in one of the constants that is defined in the class, or you can also just pass in a number. So something like...


joystick = wpilib.Joystick(0)
rightX = joystick.getAxis(4)
rightY = joystick.getAxis(5)


That might work. It might not.

The joystick didn't work sadly. Is that the best way to do it or is there other ways? Thanks!

virtuald
20-01-2015, 18:22
I would see what code people are using in other languages, and translate it to python. It's definitely a WPILib related issue, so presumably someone else has had the problem too and fixed it.

I don't have an XBox, so I can't test it personally.

team-4480
20-01-2015, 19:20
I would see what code people are using in other languages, and translate it to python. It's definitely a WPILib related issue, so presumably someone else has had the problem too and fixed it.

I don't have an XBox, so I can't test it personally.
Just a quick side question, how can you use one motor and one axis for aracadeDrive? I tried just using the ".set()" but that didn't work. Thanks again for all your help!

virtuald
20-01-2015, 20:22
Just a quick side question, how can you use one motor and one axis for aracadeDrive? I tried just using the ".set()" but that didn't work. Thanks again for all your help!

I'm not quite sure what you mean. If you want to set a single motor:


joystick = wpilib.Joystick(0)
motor = wpilib.Talon(2)

motor.set(joystick.getX())

team-4480
20-01-2015, 20:35
I'm not quite sure what you mean. If you want to set a single motor:


joystick = wpilib.Joystick(0)
motor = wpilib.Talon(2)

motor.set(joystick.getX())


Do the motor.set and things like that have to be in the Teleop function to work properly? Thanks!

virtuald
20-01-2015, 20:47
Do the motor.set and things like that have to be in the Teleop function to work properly? Thanks!

The roboRIO will disable motors when the robot is not enabled, so I would not recommend setting the motors outside of teleop/autonomous modes.