Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   How to use Xbox controller with RobotPy? (http://www.chiefdelphi.com/forums/showthread.php?t=133170)

team-4480 19-01-2015 16:40

How to use Xbox controller with RobotPy?
 
Hi! So we have our code working with the Xbox controller's left joystick but that was just using the
Code:

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

Re: How to use Xbox controller with RobotPy?
 
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/sh...highlight=xbox

team-4480 19-01-2015 18:36

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by virtuald (Post 1430702)
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/sh...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

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by team-4480 (Post 1430714)
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...

Code:

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

That might work. It might not.

Nunez4296 19-01-2015 19:17

Re: How to use Xbox controller with RobotPy?
 
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

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by Nunez4296 (Post 1430731)
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

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by virtuald (Post 1430728)
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...

Code:

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

Re: How to use Xbox controller with RobotPy?
 
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

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by virtuald (Post 1431193)
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

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by team-4480 (Post 1431224)
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:

Code:

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

motor.set(joystick.getX())


team-4480 20-01-2015 20:35

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by virtuald (Post 1431272)
I'm not quite sure what you mean. If you want to set a single motor:

Code:

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

Re: How to use Xbox controller with RobotPy?
 
Quote:

Originally Posted by team-4480 (Post 1431273)
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.


All times are GMT -5. The time now is 02:40.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi