|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
How do you use X-Box 360 controllers in C++?
We want to use either an X-Box controller or a PS3 controller to control out non-drive operations like arm control. The only problem is that we can't find the C++ code for how to use them. Any help would be greatly appreciated.
|
|
#2
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
There have been a lot of threads about that, you should check it out, and team 2202 also made a class for it. Here are a some links to their documentation.
http://coolhub.imsa.edu/cybercollab/...i/Main/Xbox360 http://coolhub.imsa.edu/cybercollab/...4y/view/157916 I have never tried it out, but it seems fun. Tell me how it works out for you, because I want to try it out during off-season. Just google "Xbox controller chief delphi" and you should get a lot of CD threads. Read them over if you would like. ![]() |
|
#3
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
if i was you i would use something else.
|
|
#4
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
We have been using an XBox controller. Any Game Controller that can be recognized by Windows can be used for input. You can use a PS3 controller but you have to download drivers that may or may not work in competition.
First, construct a new Joystick object: Code:
Joystick j1 (1) You can then use the Joystick API to retrieve button and axis states. Some people like using the built in getter methods like j1.getX() but I just like calling j1.GetRawAxis(1). Here's a basic guide to the axises: 1: Left Stick X 2: Left Stick Y 3: Triggers (Pulling the Right Stick returns .5-1, Pulling the left stick is 0-.5, neutral is .5) 4: Right Stick X 5: Right Stick Y You can also run j1.GetRawButton(int button) which returns bool (true means the button is pressed down). I don't remember off the top of my head what the buttons map to, but in your driver station you can: Click Windows + R > type in joy.cpl > Click on the properties of the Xbox Controller > Watch the numbers light up as you press the buttons. I know pressing A will make "Button 1" light up. This means running j1.GetRawButton(1) will return true when pressed down. |
|
#5
|
|||||
|
|||||
|
Re: How do you use X-Box 360 controllers in C++?
If the Driver Station can be coerced into recognizing something as a USB joystick, it will work in any of the FRC robot programming languages.
|
|
#6
|
||||
|
||||
|
Re: How do you use X-Box 360 controllers in C++?
Any HID (Human Input Device) compliant joysticks can be used. XBox 360 game controllers have two joysticks, a D-pad and a number of buttons. The joystick portion is the same as any other joysticks or game controllers. However, the button mappings are different. Here is the button map I used:
Code:
#define Btn(n) (1 << (n)) // // Logitech Joystick: // UsagePage=0x01, Usage=0x04 // #define Logitech_Trigger Btn(0) #define Logitech_Btn2 Btn(1) #define Logitech_Btn3 Btn(2) #define Logitech_Btn4 Btn(3) #define Logitech_Btn5 Btn(4) #define Logitech_Btn6 Btn(5) #define Logitech_Btn7 Btn(6) #define Logitech_Btn8 Btn(7) #define Logitech_Btn9 Btn(8) #define Logitech_Btn10 Btn(9) #define Logitech_Btn11 Btn(10) #define Logitech_Btn12 Btn(11) // // Microsoft SideWinder Joystick: // UsagePage=0x01, Usage=0x04 // #define SideWinder_Trigger Btn(0) #define SideWinder_Btn2 Btn(1) #define SideWinder_Btn3 Btn(2) #define SideWinder_Btn4 Btn(3) #define SideWinder_BtnA Btn(4) #define SideWinder_BtnB Btn(5) #define SideWinder_BtnC Btn(6) #define SideWinder_BtnD Btn(7) #define SideWinder_Btn9 Btn(8) // // Microsoft Xbox Game Controller: // UsagePage=0x01, Usage=0x05 // #define Xbox_BtnA Btn(0) #define Xbox_BtnB Btn(1) #define Xbox_BtnX Btn(2) #define Xbox_BtnY Btn(3) #define Xbox_LB Btn(4) #define Xbox_RB Btn(5) #define Xbox_Back Btn(6) #define Xbox_Start Btn(7) |
|
#7
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
Quote:
|
|
#8
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
Quote:
I think this is what you want: http://coolhub.imsa.edu/cybercollab/...ming-documents |
|
#9
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
Any one know what the custom math file is...anyone....?
|
|
#10
|
||||
|
||||
|
Re: How do you use X-Box 360 controllers in C++?
I scanned through the code in the Xbox360 class and didn't really find any reason for needing any custom math. The only methods that need some math are to return the joystick values in polar coordinates instead of the cartesian coordinates (i.e. returning magnitude/angle instead of returning X and Y). There are two things you can do:
Code:
#define MAGNITUDE(x,y) sqrt(pow(x, 2) + pow(y, 2)) #define RADIANS_TO_DEGREES(n) ((n)*180.0/PI) // Forward is 0-radian #define DIR_RADIANS(x,y) ((((x) == 0.0) && ((y) == 0.0))? 0.0: atan2(x, y)) #define DIR_DEGREES(x,y) RADIANS_TO_DEGREES(DIR_RADIANS(x, y)) Last edited by mikets : 07-02-2011 at 13:10. |
|
#11
|
|||
|
|||
|
Re: How do you use X-Box 360 controllers in C++?
Last edited by tomy : 07-02-2011 at 13:27. Reason: *locater -> located (grammar) |
|
#12
|
||||
|
||||
|
Re: How do you use X-Box 360 controllers in C++?
i have a pnp-ready xbox class with a dead-zone if anyone wants it
|
|
#13
|
||||
|
||||
|
Re: How do you use X-Box 360 controllers in C++?
that pnp-class would be a awesome
thank you everyone for responding ![]() |
|
#14
|
||||
|
||||
|
Re: How do you use X-Box 360 controllers in C++?
its in java, but here goes:
Code:
package com.robototes.abomasnow;
import edu.wpi.first.wpilibj.Joystick;
public class Xbox {
Joystick joy;
Xbox(int port) {
joy = new Joystick(port);
}
int a = 1;
int b = 2;
int x = 4;
int y = 3;
int lb = 6;
int rb = 5;
int back = 7;
int start = 8;
double[] getAxes(int x_axis, int y_axis) {
double[] res = new double[2];
res[0] = joy.getRawAxis(x_axis);
res[1] = joy.getRawAxis(y_axis);
return res;
}
double[] getLeftStickAxes() {
return getAxes(1,2);
}
double[] getRightStickAxes() {
return getAxes(4,5);
}
boolean getTrigger() {
return joy.getTrigger();
}
boolean get(int n) {
return joy.getRawButton(n);
}
boolean[] getAll() {
//Warning, this is ugly
boolean[] r = new boolean[8];
r[0] = get(1);
r[1] = get(2);
r[2] = get(3);
r[3] = get(4);
r[4] = get(5);
r[5] = get(6);
r[6] = get(7);
r[7] = get(8);
return r;
}
public Joystick getJoy()
{
return joy;
}
}
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|