Show EOL distros: 

Package Summary

ROS driver for the DualShock 4 controller

Package Summary

ROS driver for the DualShock 4 controller

Overview

This package provides a driver for the DualShock 4 (PS4) Bluetooth controller. Some of the features of this package are:

  • Access to information such as IMU, battery, and touchpad
  • Access to feedback such as rumble, LED color, and LED flashing
  • Connection via Bluetooth for wireless control

Installation and Usage

Pair and connect to your DualShock 4 by long-pressing the PS button and Share button for up to 10 seconds until the LED starts flashing. Use your system's Bluetooth settings to connect to the device.

This driver depends on ds4drv. Some features of this driver depend on pull requests have not yet been merged upstream. Until they are merged, use the fork (devel branch).

$ git clone https://github.com/naoki-mizuno/ds4drv --branch devel
$ cd ds4drv
$ python2 setup.py install --prefix ~/.local
$ sudo cp udev/50-ds4drv.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger
$ cd ~/catkin_ws/src
$ git clone https://github.com/naoki-mizuno/ds4_driver.git

Compile and source this package just like any other ROS package. To run,

$ roslaunch ds4_driver ds4_driver.launch
# Or
$ rosrun ds4_driver ds4_driver_node.py

Disable touchpad input device

Note: You can skip this section if you use the forked version of ds4drv (i.e. naoki-mizuno/ds4drv) because the following line is included in the udev rules by default.

By default the touchpad of the DualShock 4 is recognized as an input device. Because of this, the mouse moves to the location on screen that corresponds to the location touched, making it very hard to track the mouse cursor (and worse, it automatically clicks at that location). If you want to prevent the touchpad from being recognized as an input device, add the following to the udev rules and run the udevadm commands (you will still be able to use the touchpad from this driver):

SUBSYSTEM=="input", ATTRS{name}=="*Wireless Controller Touchpad", RUN+="/bin/rm %E{DEVNAME}", ENV{ID_INPUT_JOYSTICK}=""

Demonstration

Get a glimpse of some of the features of ds4_driver including touchpad, rumble, and LED control:

$ roslaunch ds4_driver demo.launch

Moving the left/right stick controls the rumble. Sliding left and right on the touchpad while pressing circle, triangle, cross buttons controls the brightness of the red, green, blue LED, respectively (you can tell from the color of the button). Pressing the PS button triggers the flashing of the LED.

Nodes

ds4_driver_node.py

Driver for DualShock 4, which publishes the device's status and applies feedback to the device.

Subscribed Topics

set_feedback (ds4_driver/Feedback)
  • Feedback for the device such as LED color, LED flashing, and rumble.
When using ROS standard messages.
Topics subscribed to only when ~use_standard_msgs is true
set_feedback (sensor_msgs/JoyFeedbackArray)
  • Feedback for the device (only LED color and rumble).

Published Topics

status (ds4_driver/Status)
  • Publishes the current state of the device.
When using ROS standard messages.
Topics published only when ~use_standard_msgs is true
battery (sensor_msgs/BatteryState)
  • Battery information such as percentage left.
joy (sensor_msgs/Joy)
  • Joypad data.
imu (sensor_msgs/Imu)
  • IMU data, where X points to the right, Y points up, and Z points towards the person holding the device.

Parameters

~device_addr (string)
  • Hardware address of the device to be connected to. If unspecified, the first device found will be used.
~backend (string, default: hidraw)
  • Backend to be used to connect to the device via Bluetooth. bluetooth is only for legacy support and should not be used unless necessary. Refer to the docs of ds4drv for details.
~use_standard_msgs (bool, default: false) ~deadzone (float, default: 0.1)
  • Amount by which the joystick has to move before it is considered to be off-center.
~frame_id (string, default: ds4)
  • Frame ID to be used for the messages.
~imu_frame_id (string, default: ds4_imu)
  • Frame ID to be used for the IMU messages.

ds4_twist_node.py

Subscribes to the device status messages and converts them to velocity commands.

Subscribed Topics

status (ds4_driver/Status)
  • Joypad state published from the driver.

Published Topics

cmd_vel (geometry_msgs/Twist)

Parameters

~stamped (bool, default: false) ~inputs (dict)
  • What buttons and axes to use for the value of each velocity vector. Expressions can be used to combine values of multiple keys (see config/twist_6dof.yaml for examples).
~scales (dict, default: 1.0 for all fields)
  • Scaling factor for each velocity vector.

Wiki: ds4_driver (last edited 2020-10-28 19:56:24 by manudiaz96)