Bluetooth Joystick (DS4) with ROS

ROS on a Raspberry Pi is great, but controlling your robot with an actual joystick-style controller is even better. Follows are my notes on connecting a Playstation Dual-Shock 4 (DS4) controller to ROS on Ubuntu with ds4drv.

My robotics platform of the day is a Pololu Romi with Pololu 32u4 motor control and Raspberry Pi Model 3 running Ubuntu 16.04. These instructions assume you have already installed ROS and can control your robot using cmd_vel through the keyboard interface.

My ROS architecture is based upon the Turtlebot 3 adapted to the Romi 32u4 (more details upcoming).

Establish Bluetooth Connection

  1. Install ds4drv and jstest. These are available via apt.
  2. launch ds4drv. I need to launch with sudo. e.g. sudo ds4drv
  3. Hold down the share and ps4 buttons on the DS4 controller to power the DS4 on in bluetooth pairing mode. The light on the far side of the controller will quickly blink white indicate successfully entering pairing mode.
  4. Wait until ds4drv discovers the DS4 controller and successfully forms a bluetooth connection. When successful, the controller light will stop flashing and hold a solid blue.
  5. Read the ds4drv output and note which joystick input. Mine was /dev/input/js0

Test Joystick Connection

Open jstest joystick test connection. e.g. jstest /dev/input/js0

jstest prints out the values for each button and stick. Press buttons and correlate which joystick and button numbers correspond to which joysticks and buttons.

Establish ROS Connection

  1. The following ROS launcher and config file are configured to launch the teleop_twist_joy program.
cat ./launch/romipi_teleop_ds4_joy.launch 
<launch>
  <arg name="joy_config" default="ds4" />
  <arg name="joy_dev" default="/dev/input/js0" />
  <arg name="config_filepath" default="ds4.config.yaml " />
  <node pkg="joy" type="joy_node" name="joy_node">
    <param name="dev" value="$(arg joy_dev)" />
    <param name="deadzone" value="0.3" />
    <param name="autorepeat_rate" value="20" />
  </node>
  <node pkg="teleop_twist_joy" name="teleop_twist_joy" type="teleop_node">
    <rosparam command="load" file="$(arg config_filepath)" />
  </node>
</launch>
cat ds4.config.yaml 
 axis_linear: 1
 scale_linear: 0.7
 scale_linear_turbo: 1.5

axis_angular: 0
 scale_angular: 0.4

enable_button: 5  # L2 shoulder button
enable_turbo_button: 6  # R2 shoulder button
  1. rostopic list
  2. rostopic echo cmd_vel

And that’s all, now you can bringup your robot controller and commence chasing your favorite pet!

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply