Robot Arm with PS3 sixaxis controller - Tutorial

Update: demo video now up!
Here is the tutorial in using the PS3 sixaxis controller with the OWI/Maplin robotic arm. It's less impressive than the voice control, however it's still useful in some ways as the sixaxis controller is an excellent controller.
As before, you will need:
- OWI/Maplin Robot arm with USB interface
- pygame and pyusb Python module
- linux computer with working bluetooth (bluez)
- falkTX's qtSixA program
Install qtsixa on Ubuntu using the following commands:
sudo add-apt-repository ppa:falk-t-j/qtsixa
sudo apt-get update
sudo apt-get install qtsixaIf you're using a Raspberry Pi, you need to download the source and compile it manually from here (SourceForge).
Connect your PS3 controller using a mini USB cable and start qtsixa. Pair it to the computer. Disconnect the PS3 controller. In a command prompt, type:
sixad --startOpen another terminal window, and this time, run the python program below:
python robotarm_sixaxis.pyTutorial still in progress...
UPDATE: I don't like delaying releasing the source too much (those who do, you know who you are), so I'm posting the source code now even if I don't have enough time to write the tutorial yet. I'll try to find some time to write it, but if you have any questions before then, feel free to ask me through the comments!
#!/usr/bin/env python # robotarm_sixaxis.py by aonsquared import pygame import usb.core import time pygame.init() j = pygame.joystick.Joystick(0) j.init() print 'Initialized Joystick : %s' % j.get_name() dev = usb.core.find(idVendor=0x1267, idProduct=0x0000) #exit if device not found if dev is None: raise ValueError('Can\'t find robot arm!') #this arm should just have one configuration... dev.set_configuration() threshold = 0.60 def setcommand(axis_val): if axis_val > threshold: return 1 elif axis_val < -threshold: return 2 elif abs(axis_val) < threshold: return 0 def buildcommand(shoulc,basec,elbowc,wristc,gripc,lightc): byte1 = shoulc + elbowc + wristc + gripc comm_bytes = (byte1, basec, lightc) return comm_bytes try: command = (0,0,0) lighton = False lc = 0 while True: pygame.event.pump() shoulder = j.get_axis(1) base = j.get_axis(0) elbow = j.get_axis(3) wristup = j.get_axis(12) wristdown = j.get_axis(13) grip_open = j.get_axis(17) grip_close = j.get_axis(18) light_command = j.get_axis(16) if (light_command > 0.8) and (lighton == False): lighton = True lc = 1 elif (light_command > 0.8) and (lighton == True): lighton = False lc = 0 if abs(grip_open)> threshold: grip_command = 1 elif abs(grip_close)> threshold: grip_command = 2 else: grip_command = 0 ############################################# if abs(wristup) > threshold: wrist_command = 1*4 elif abs(wristdown) > threshold: wrist_command = 2*4 else: wrist_command = 0 shoulder_command = setcommand(shoulder)*64 base_command = setcommand(base) elbow_command = setcommand(elbow)*16 newcommand = buildcommand(shoulder_command,base_command, elbow_command, wrist_command, grip_command,lc) if newcommand != command: dev.ctrl_transfer(0x40, 6, 0x100, 0, newcommand, 1000) command = newcommand except KeyboardInterrupt: j.quit()







Comments
pyusb
Hey, how can I get information to install pyusb to my computer, I simply can't do that. Thx a lot, man!
Windows 7
Will windows 7 work too?