Ask Your Question
0

ROS2 node for Sony Playstation 4 Dual Shock 4 (DS4) gamepad

asked 2020-09-22 13:17:16 -0500

bobsaccamano gravatar image

updated 2020-09-22 13:23:56 -0500

Hi,

I'm trying to set up a ROS2 (Dashing) node on Ubuntu 18.04 for publishing the /joy topic from a PS4 gamepad input. I've found various options online and gotten some of them set up partly, however nothing is really working as yet. I'd appreciate some help in this regard.

Here is what I tried:

Option 1: ds4drv with joystick_ros2

ds4drv enables the gamepad to be registered under /dev/input/eventX (or /dev/input/jsY). joystick_ros2 provides a ROS2 node that publishes the /joy topic.

The joystick device is not found:

ros2 run joystick_ros2 joystick_ros2
/opt/ros/dashing/lib/python3.6/site-packages/rclpy/node.py:1053: UserWarning: Pass an explicit 'qos_profile' argument
  warnings.warn("Pass an explicit 'qos_profile' argument")
Joystick not found. Will retry every second.
Joystick not found. Will retry every second.
Joystick not found. Will retry every second.
Joystick not found. Will retry every second.
Joystick not found. Will retry every second.

Option 2: ds4drv with ROS2 joy node

ds4drv --hidraw together with ros2 run joy joy_node finds the joystick:

[INFO] [joy_node]: Opened joystick: /dev/input/js0. deadzone_: 0.050000. (main() at /tmp/binarydeb/ros-dashing-joy-2.3.2/src/joy_node_linux.cpp:286)

The /joy topic is published but does not update according to user inputs (i.e. all 0s)

Is there another way I could get this to work?

Appreciate any pointers here.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-09-22 15:13:01 -0500

ruffsl gravatar image

updated 2020-09-22 15:21:52 -0500

I've had some issues with the stock Linux kernel that ships with Ubuntu 18.04 in the past, specifically its bluetooth device drivers for the PS4 DS4 controller. I don't recall any issues using it via USB, but that's hardly practical when using it to tele operate a mobile robot without a second computer.

For what it's worth, the stock kernel shipped with Ubuntu 20.04 is a lot more stable with the DS4, and joy_node released into foxy seems to work out of the box, both bluetooth and USB:

USB

$ ros2 run joy joy_node 
[INFO] [1600804025.194521913] [joy_node]: Opened joystick: Sony Computer Entertainment Wireless Controller.  deadzone: 0.050000
^C[INFO] [1600804101.562256221] [rclcpp]: signal_handler(signal_value=2)

Bluetooth

$ ros2 run joy joy_node 
[INFO] [1600804160.446296839] [joy_node]: Opened joystick: Wireless Controller.  deadzone: 0.050000
^C[INFO] [1600804280.166092944] [rclcpp]: signal_handler(signal_value=2)

The only caveat is that the stock kernel module for the DS4 with Ubuntu 20.04 doesn't seem to report the:

  • 3 gyro axes
  • 3 accelerometer axes

That said, even using bluetooth can be kind of flaky, with the /dev/input/jsX device unmounting whenever connection is lost, potentially for any program not accounting for hot swappable input devices. An alternative could be to use wireless controller with a simple USB dongle. Some examples:

edit flag offensive delete link more

Comments

Thanks for your reply.

I am using a USB connection at the moment (sufficient for my use-case). I'm not in a position to upgrade the Ubuntu version as I have legacy code that would need to be ported.

The device is correct /dev/input/js0 and it is detected by the joy_node as is visible in the [INFO] print. Could it be an incompatibility between js0 and eventX devices ? ds4drv uses the evdev interface, so the device is visible also as /dev/input/eventX.

bobsaccamano gravatar image bobsaccamano  ( 2020-09-22 15:59:49 -0500 )edit

If your not using the stock kernel module for the DS4, but a user space driver instead, then I would suggest you check the buttons and axis numbers line up as expected from the stock kernel module config. I use jstest-gtk for editing such configs, installable via apt: https://jstest-gtk.gitlab.io

ruffsl gravatar image ruffsl  ( 2020-09-22 16:17:13 -0500 )edit

When I fire up jstest-gtk, none of the controls change as I play with the gamepad. I think the joystick is incorrectly listening to js0 whereas the input device is configured as eventX. Have you got it working with the stock kernel module for DS4 in Ubuntu with ROS2?

bobsaccamano gravatar image bobsaccamano  ( 2020-10-06 08:27:53 -0500 )edit

Yes, it works out of the box for me with ROS2 Foxy and Ubuntu Focal. See the stdout I've already pasted above for reference.

ruffsl gravatar image ruffsl  ( 2020-10-06 11:46:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-09-22 13:17:16 -0500

Seen: 1,034 times

Last updated: Sep 22 '20