By Luke Amos
One of the most alluring features of Pi Wars in general is the infamous Pi Noon challenge, which involves manoeuvring your robot to try and pop balloons attached to your opponents’ robots while being careful not to let them pop your own. Having been to the competition before I can safely say it is one of the best challenges to watch, although I imagine it would be extremely stressful to participate in. As this is a manual-control task, our team needed a good method of controlling our machine. Being a Sony Soldier in the console wars I was instantly drawn to the PlayStation 4’s Dualshock 4 controller. Although getting it to work with the pi was an utter nightmare.
Fairly obviously the only way to practically connect a DS4 controller to a pi is via bluetooth. Linux users the world over reel at the term bluetooth because, along with printing, this form of wireless connection consistently appears to be nigh-on impossible to use with any linux distro. Nevertheless, I was confident I could bodge hard enough to get things working relatively painlessly. Ahh, the joys of naivety.
After hours of punching at keys, vigorous swearing, driver installations, driver reinstallations and a quiet lie down, the controller was paired with the pi. HUZZAH!
The next task was figuring out the best way to use the controller’s inputs with python. To this day I have no clue if the way I went with is the best because there are so many solutions out there, but in the end I elected to use a nifty little python module called evdev. Essentially this module combs through the input log files created by linux and allows you to find the exact input you want (e.g the triangle button being pushed or a trigger being pressed). In just 50 lines of code I had myself a rudimentary control scheme in place which surprisingly worked flawlessly first time.
At the time of writing we still have a long way to go (particularly with integrating the joysticks), but this appears to be an excellent way of controlling our robot. The DS4 controller offers enough buttons for the various required functions and an ergonomic design that makes it extemely comfortable to use, as any PlayStation gamer will attest to. However, to any readers still searching for their perfect control method I would say that there are plenty of options out there and the DS4 is by no means the definitive controller. No matter which controller you opt to use though, the evdev module probably has you covered.
And if you choose a bluetooth controller, good luck.
The evdev documentation can be found here.