Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get input from an XBox 360 controller?

I'm writing a program that needs to take input from an XBox 360 controller. The input will then be sent wirelessly to an RC Helicopter that I am building.

So far, I've learned that this can be done using either the XInput library from DirectX, or the Input framework in XNA.

I'm wondering if there are any other options available. The scope of my program is rather small, and having to install a large gaming library like DirectX or XNA seems like excessive. Further, I'd like the program to be cross platform and not Microsoft specific.

Is there a simple lightweight way I can grab the controller input with something like Python?

Edit to answer some comments:

The copter will have 6 total propellers, arranged in 3 co-axial pairs. Basically, it will be very similar to this, only it will cost about $1,000 rather than $15,000. It will use an Arduino for onboard processing, and Zigbee for wireless control.

The 360 controller was selected because it is well designed. It is very ergonomic and has all of the control inputs needed. For those familiar with helicopter controls, the left joystick will control the collective, the right joystick with control the pitch and roll, and the analog triggers will control the yaw. The analog triggers are a big feature for the 360 controller. PS and most others do not have them.

I have a webpage for the project, but it is still pretty sparse. I do plan on documenting the whole design though, so eventually it will be interesting.
http://tricopter.googlecode.com
On a side note, would it kill Google to have a blog feature for googlecode projects?

I would like the 360 controller input program to run in both Linux and Windows if possible. Eventually though, I'd like to hook the controller directly to an embedded microcontroller board (such as Arduino) so that I don't have to go through a computer, but its not a high priority at the moment.

like image 885
bengineerd Avatar asked Mar 31 '09 01:03

bengineerd


People also ask

What is the port under the Xbox controller?

It's a recessed mini-USB port, which connects your wireless controller to the console using a mini-USB cable. Expansion port (9): This is a recessed port on the bottom-side edge of the controller. It's used to connect other accessories, such as an Xbox One Chat Headset.

What is the port on the back of an Xbox 360 controller?

The expansion port on the Xbox 360 wireless controller lets you connect optional accessories, such as the Xbox 360 Headset. Note The expansion port is under the directional pad (D-pad) and the right stick on the controller.


2 Answers

It is not all that difficult. As the earlier guy mentioned, you can use the SDL libraries to read the status of the xbox controller and then you can do whatever you'd like with it.

There is a SDL tutorial: http://sdl.beuc.net/sdl.wiki/Handling_Joysticks which is fairly useful.

Note that an Xbox controller has the following:

  • two joysticks:
    • left joystick is axis 0 & 1;
    • left trigger is axis 2;
    • right joystick is axis 3 & 4;
    • right trigger is axis 5
  • one hat (the D-pad)
  • 11 SDL buttons
    • two of them are joystick center presses
  • two triggers (act as axis, see above)

The upcoming SDL v1.3 also will support force feedback (aka. haptic).

I assume, since this thread is several years old, you have already done something, so this post is primarily to inform future visitors.

like image 153
salimiles Avatar answered Nov 10 '22 09:11

salimiles


PyGame can read joysticks, which is what the X360 controller shows up as on a PC.

like image 40
rmmh Avatar answered Nov 10 '22 10:11

rmmh