Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PS3 controller driver -> uinput-> python? somehow?

Tags:

python

ps3

I'm trying to read from a PS3 controller in python on Ubuntu and I'm not having much luck. I started with the ps3joy driver from Willow Garage (http://www.ros.org/wiki/ps3joy) which supposedly publishes all the important bits of the PS3 controller to something I had never heard of called "uinput". Apparently it's a linux feature that allows userspace drivers to provide system events. ...Why the WG driver requires root access given that it's supposedly a userspace driver is beyond me, but that's not my question.

Anyway, the current state of me trying to get it to work is that I've got the driver working, and I've verified that it responds to button presses on the controller, but I don't know how to pull any of that data out so I can use it.

My first guess was to use pygame to (hopefully) read from /dev/uinput (which I'm pretty sure is where the driver sends the data):

from pygame import joystick
if not joystick.get_init():
  joystick.init()
js = joystick.Joystick(0)  # there is only one joystick... even if the driver isn't running(!)
js.init()
print js.get_numbuttons()  # perhaps coincidentally correctly prints 17 which is the number of buttons on a PS3 controller
for i in range(js.get_numaxes()):
  print js.get_axis(i)   # always prints 0, no matter what I'm doing with the controller

but it didn't work. The most telling part of the problem is that it does the same thing if I don't have the WG driver running at all.

I'm sure this is something easy, that I'm just not reading the right information, but googling has not helped me find what the right information is and I'm getting tired and desperate.

like image 981
teryret Avatar asked May 27 '12 03:05

teryret


2 Answers

You don't need the driver. Assuming the controller exposes itself as a HID, you can use the event subsystem to read controller events directly from the device.

like image 120
Ignacio Vazquez-Abrams Avatar answered Nov 11 '22 13:11

Ignacio Vazquez-Abrams


I know it's too late, but if anyone will ever need the code or is struggling with it, you can use mine. I've wrote a script in python that gets ps3 data from USB and sends it to specific a MAC address via PC's bluetooth (you can use ps3controller.py only for data). This was made for my quadcopter project.

https://github.com/urbanzrim/ps3controller

like image 2
spaceman Avatar answered Nov 11 '22 13:11

spaceman