Going online with the gamepad

Hello guys. Last week was a cool one. I’ve been working on the prototype of Pronghorn. Most importantly, I got two L293Ds because the platform was a four-wheel differential drive and one H-Bridge was not working as good as I expected it to. Anyway, this post is about it’s HRI – Human Robot Interface.

I’m not going to post any code in this post, but only pointers to two links that solves two of my problems in the HRI. So, here we go.

Continuing on the stable tradition of AndRo.bot, I hope to continue the embedded HTTP server mechanism on Pronghorn, but because I’m using Python now, instead of Java, I can no longer use nano HTTPD. So I googled around for a bit looking for embedded webservers that runs on Python. I needed it to be cross-platform because I am developing on my laptop running Windows, but would eventually deploy it to a Raspberry Pi, running Raspbian, which is essentially a Debian-based Linux distro.

I found a few at the Python website, but none of them seemed apt for use. So, I decided to build one from scratch using the BaseHTTPServer module, which comes as part of the standard library. There is no big new thing here. The server is similar to the one I built for the Twisted MP3 Player. So check it out, if you want.

But the coolest thing I have done this week is have the gamepad I talked about in here and here talk to the server that I talked about in the last paragraph. Obviously, to do this I had to somehow get the gamepad taking to me in JavaScript. And guess who came to my rescue? HTML5. Yes, that’s right.

Turns out there is a specification, currently in draft, that the W3C is creating to integrate gamepads into browsers. Google and Mozilla already integrated parts of it into their browsers. Internet Explorer doesn’t support it, but nobody cares. You may not know this, but the Hurdles doodle that Google put up during the 2012 Olympics can be played with a gamepad. But being a draft specification, there are several compatibility issues between Chrome and Firefox right now. We can hope that these incompatibilities will fade away gradually as the specification matures. But right now incompatibilities exists, and we have to deal with it.

After brain-storming for several hours, I decided to use a library that would give ,me the values of the buttons and axes in a simple, cross-browser. fashion. There are several libraries out there, but I settled for this library by Priit Kallas, because of it’s simplicity and light-weightiness. The code in the example is intuitive and well documented, so I’ll not get into much details about it. Do check it out and game on…

Advertisements