One of the decisions to make when building a semi-autonomous robot for a competition like Pi Wars is which controller to use. After considering a number of options we decided to use a DualShock4 (DS4) controller. The DualShock4 controller is a high-end controller designed for the PlayStation 4 which thankfully also works really well with the Raspberry Pi.

2016-11-12-001At the time of writing the controller costs a fair amount, selling at £49.99 in high-street retail shops. However, we felt that it would be worth the investment having a state-of-the-art controller for this project and if all goes well, for many similar projects in the future. It looks great, feels fantastic and has lots of sticks and buttons which we will be able to use to control the robot.

The Ds4 controller communicates via bluetooth which means it can talk directly to the bluetooth adapter embedded on the Raspberry Pi. In order to get Raspbian to recognise the controller as an input device you need to install a device driver for linux which can be found at https://github.com/chrippa/ds4drv. Credit to the team that have developed this piece of software for figuring out how this controller works! Once installed and after pairing the DS4 with the Raspberry Pi it is possible to read the device from /dev/input.

2016-11-12-003While experimenting with this setup we discovered that the controller would seem a bit sluggish and occasionally it would hang momentarily. Obviously this would be unacceptable for contolling a robot and it turned out that the problem had something to do with the contention between the bluetooth adapter and the Wifi port on the Raspberry. The Wifi and the bluetooth ports share control logic which means that if one of them is being used then it will affect the performance of the other.

Fortunately there is a solution (or a workaround) to this problem. Sony offer a USB bluetooth adapter for the DS4 and this can be purchased for just under £20. Although this makes a fairly expensive controller solution even more expensive it will make the solution more responsive, robust and simple. Having good controller performance seems critical to the design of the robot so easily justifies the additional cost.

2016-11-12-004With Sony’s Ds4 USB wireless adapter no additional software is required to be installed on the Raspberry Pi. All that is needed is to plug the adapter into a free USB port, then pair it with the controller by first pushing in on the USB stick until it starts flashing, and then pressing and holding two buttons on the DS4. The DS4 controller will now show up as a normal joystick input device in the operating system.

The next step involves writing software to read the controller and we will follow up later with another post with more details on how to do that. In the mean time, feel free to put your own comments or questions in the form below. What are your experiences with performance on the bluetooth ports on the Raspberry Pi? Have you had any experience with integrating the DS4 controller in your own projects?

 

 

PlayStation 4 DS4 for RPi Robot Control