PS4 Controller and ROS

It's National Robotics Week! But you should definitely #StayAtHome, so there are no in-person events this week. I already had this (and several other posts) nearly done, so I'm aiming to post something every day this week.

Recently I updated Maxwell to use the PS4 controller. It is not the easiest thing to setup, and I found lots of misinformation out there that either never worked, or no longer works. So here is how I now setup PS4 controllers on Ubuntu Bionic (18.04).

These instructions require no special packages to be installed, we're using the default bluetooth built into the Linux kernel, which should also mean that other bluetooth stuff continues to work (unlike the older ps3_joy ROS package).

To pair the PS4 controller with the robot computer we need to start the controller in "pairing mode". Hold down the SHARE button while pushing the POWER button. Continue to hold both buttons until the LED starts flashing very quickly.

On the computer we will use bluetoothctl to do three things:

Open a terminal on the robot computer and run the following commands that are in RED. Replace the MAC address with the actual device found (I've highlighted in green what the line should look like):

$ sudo bluetoothctl
[NEW] Controller A0:A4:C5:CC:D1:92 velocityXYZ [default]
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller A0:A4:C5:CC:D1:92 Discovering: yes
[NEW] Device A4:AE:11:02:78:BC Wireless Controller
[bluetooth]# trust A4:AE:11:02:78:BC
Changing A4:AE:11:02:78:BC trust succeeded
[bluetooth]# pair A4:AE:11:02:78:BC
Attempting to pair with A4:AE:11:02:78:BC
[CHG] Device A4:AE:11:02:78:BC Connected: yes
[CHG] Device A4:AE:11:02:78:BC UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device A4:AE:11:02:78:BC UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device A4:AE:11:02:78:BC ServicesResolved: yes
[CHG] Device A4:AE:11:02:78:BC Paired: yes
Pairing successful
[bluetooth]# exit
When complete, the PS4 LED should go solid and turn a deeper blue color. You should only have to do this once, and the controller will remain paired until you pair it with another computer.

Once you've got the PS4 controller paired, you'll find out the button mapping is just a little different form the PS3:

Here's the changes I made to Maxwell to update from the PS3 to the PS4 controller. I use a custom node for converting Joy messages into Twist messages. If you're using the popular teleop_twist_joy package, you'll be using enable_button parameter instead of axis_deadman.