naoki-mizuno / ds4_driver

DualShock 4 driver for both ROS1 and ROS2
http://wiki.ros.org/ds4_driver
85 stars 53 forks source link
driver ds4-driver dualshock4 imu ros ros2 touchpad velocity-commands

ds4_driver

DualShock 4 driver for ROS.

Features

Installation and Usage

Native

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 naoki-mizuno/ds4drv (devel branch).

$ git clone https://github.com/naoki-mizuno/ds4drv --branch devel
$ cd ds4drv
$ mkdir -p ~/.local/lib/python3.10/site-packages
$ python3 setup.py install --prefix ~/.local
# Note: udev directory is in the ds4drv repo, not ds4_driver (this repo)
$ sudo cp udev/50-ds4drv.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger

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

$ ros2 launch ds4_driver ds4_driver.launch.xml
# Or
$ ros2 run ds4_driver ds4_driver_node.py

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

$ ros2 launch ds4_driver demo.launch.xml
# See the messages that are published
$ ros2 topic echo /status

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.

Docker

A docker image is provided on Docker Hub, as well as a Dockerfile that can be used to build an image.

$ ./run_docker.bash
# Takes you into the container's interactive shell
$ ros2 launch ds4_driver demo.launch.xml

Or if you want to build the image,

docker build ./docker

ds4_driver_node.py

This is the main node that interacts with DualShock 4.

Parameters

Topics

Published

Subscribed

Note: To disable flash, send message with set_led_flash: true and led_flash_off: 0.

Topics (when use_standard_msgs is true)

Published

Subscribed

ds4_twist_node.py

A node to convert joypad inputs to velocity commands is included in this package. This node is something similar to teleop_twist_joy but is specifically for a DualShock 4.

Parameters

Topics

Published

Subscribed

Notes

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}=""

License

MIT

Author

Naoki Mizuno (naoki.mizuno.256@gmail.com)