Hexy and PS3 controller

New project to control Hexy via a PS3 controller is ready for the prime-time.

Code can be found on GitHub. Requires pygame to be installed. Must make sure that python can see the SixAxis controller, only tested on Ubuntu so far.

Due to the interesting way the SixAxis controller uses the Bluetooth interface, it must be connected to the PC via a USB cable, or you can’t open a serial port to Hexy. I’ll go into some more detail about the connection configuration and how the code works in a post on my blog (with video) in the near future.

If you run PoMoCo_demo.py, the SixAxis code uses the binary communication profile as developed by the quite excellent michal. So if you haven’t updated your Servotor32 on Hexy, it won’t work. The SixAxis.py code in the PoMoCo regular GUI uses the ASCII interface, but this limits the update rate of the servos.

Control is as follows:
[]Left analogue stick: Move Hexy forwards, backwards, left and right[/]
[]Right analogue stick: Rotate Hexy, left/right axis only[/]
[]L2/R2: Turn Hexy’s head[/]
[]L3: (Binary only) If pressed the update rate of the servos is increased fourfold, e.g. sprint feature[/]

Hopefully this should work for other people, please do come back with comments/ questions. Code should be commented.

Enjoy! Rob

Hey nice to see you back doing some fun stuff.

Nice work rpcook.

Can you tell me how your controller works in Ubuntu? When I got my PS3 controller working over bluetooth it ended up working as a mouse and and a joystick at the same time it so got really annoying. When I used the Logitech controller it only worked only as a Joystick.

Hi TooManySecrets, thanks for the note. Fun to be getting back into playing with Hexy again.

Klims, I had the same problem at first too. As mentioned, I did this connection through the USB cable, but I think this fix works for both communication methods.

What you need to do is add/ modify a file that disables the joysticks operating as a pointer. I created a file “/etc/X11/xorg.conf.d/50-joystick.conf” with the following content:

Section "InputClass" Identifier "joystick catchall" MatchIsJoystick "on" MatchDevicePath "/dev/input/event*" Driver "joystick" Option "StartKeysEnabled" "False" #Disable mouse Option "StartMouseEnabled" "False" #support EndSection
Reboot and the joystick should still connect as a joystick (install jstest-gtk to verify it’s still working), but not move the pointer.

Since I dont have PS2 or 3 controller, Is there any way I can control Hexy using my wireless keyboard’s arrow keys and numbers?
Does anyone know how to do it?
I’m still trying to figure out the codes for it.


I’d suggest replacing the pygame.joystick module and calls with pygame.key. Obviously you won’t get analogue speed control from a keyboard input, but I don’t think it should be too hard to port the code.

So there’s no other way to get analogue speed control from a keyboard input? Well if that’s the case I’ll try buying PS3 controller. Is there a specific kind of PS3 controller? Which one and Can I use PS2 by any chance instead? It’s cheaper. Thanks!

I’ve only tested with an official Sony PS3 controller (£35 each), but the pygame interface should support any joystick input. I’d suggest having a go with a cheaper joystick, so long as it has two joysticks, you’ll be able to do the level of analogue control that my code is built around.

How can I use the codes you’ve posted on the Github? Can I just place them all in one folder?

Yep, just download the whole set and run it as you would the regular PoMoCo. One thing to note is that the PoMoCo_Demo interface uses the same offsets config file that PoMoCo uses, so either set them up in the regular GUI, or copy across your config file from another folder.

Hey any way that this can run right on start up of pomoco ?

also i get this while ruining pomoco_demo

Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner self.run() File "PoMoCo\servotorComm.py", line 73, in run if self.ser.readable(): AttributeError: 'NoneType' object has no attribute 'readable'

TooManySecrets, I’m sure that there is a way for this to run on startup. Not sure what it is I’m afriad. Everything’s possible in software!

The exception thrown, I think, is due to the software not connecting to Hexy properly. The timeout on the serial port is set to 0.01s, due to my experimentation with the ultrasonic-distance sensor. Try setting it back to around 2s. It’s line 110 in servotorComm.py.

Good luck!

Ok so now it did connect to the hexy but i have a different problem now :slight_smile:

I dont know if its just me since i cant seam to run yours or klims’s code.

When i press the ps3 controller button it opens a window for the binary but it hangs and after a time it says not responding.

No errors no nothing.

Hmm. That’s a pygame window that’s coming up. Perhaps try to run the example code at the bottom of this page to see if your Python can chat to a joystick without all of the Hexy PoMoCo overhead.

Tried that demo and i get this in a window.

there’s an error in your program:

And then it highlights this code that is in bold

def [b]print[/b](self, screen, textString): textBitmap = self.font.render(textString, True, BLACK) screen.blit(textBitmap, [self.x, self.y]) self.y += self.line_height

Oh yeah, I remember that. It does have an error, seems to be because they’re trying to overload the print function, which Python doesn’t like. To get around this, I changed the name of this function to printF:

def printF(self, screen, textString): textBitmap = self.font.render(textString, True, BLACK) screen.blit(textBitmap, [self.x, self.y]) self.y += self.line_height
Then simply modify all calls to textPrint.print to textPrint.printF. Good luck.

Ok tried that and it works perfectly i just dont understand why yours does not work for me. Its made from the same example.

Trying to get my hexy up and running with the controller, but when I use rpcook’s PoMoCo file, I can’t connect to my hexy via Bluetooth. Using OSX, and it works fine on the ArcBotics OSX version of PoMoCo, and I can get it to work with your version as long as I use USB.

Any suggestions?

Try modifying the timeout in the serial controller as mentioned to TooManySecrets in an earlier comment.

Good luck, R


That got it connected- but it’s weird. When I change the value to 2, any move goes in SUPER slow motion. Can get it to connect with a value as low as .3, but that’s the threshold.