From aa91813ba2e6817162741d2f60117c9a5e284b77 Mon Sep 17 00:00:00 2001 From: Naoki Mizuno Date: Sun, 25 Aug 2019 18:52:23 +0900 Subject: [PATCH 1/2] Fix IMU report The order of acceleration and angular velocity fields are fixed so the reported values are correct. The axis orientation is positive X pointing right, positive Y pointing up, and positive Z pointing towards the user. For the angular velocities, the following convention is used for the names (following the right thumb rule): Roll: rotation around X axis Pitch: rotation around Y axis Yaw: rotation around Z axis The code has been tested by checking that the sign of the values are consistent with the axis orientation when translating/rotating the device. References: - https://gamedev.stackexchange.com/a/87178 - http://eleccelerator.com/wiki/index.php?title=DualShock_4#Report_Structure --- ds4drv/device.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ds4drv/device.py b/ds4drv/device.py index dd8265e..232ca7c 100644 --- a/ds4drv/device.py +++ b/ds4drv/device.py @@ -41,12 +41,12 @@ class DS4Report(object): "button_options", "button_trackpad", "button_ps", - "motion_y", - "motion_x", - "motion_z", "orientation_roll", - "orientation_yaw", "orientation_pitch", + "orientation_yaw", + "motion_x", + "motion_y", + "motion_z", "trackpad_touch0_id", "trackpad_touch0_active", "trackpad_touch0_x", @@ -181,13 +181,13 @@ def parse_report(self, buf): # Trackpad and PS buttons (buf[7] & 2) != 0, (buf[7] & 1) != 0, - # Acceleration + # Orientation S16LE.unpack_from(buf, 13)[0], S16LE.unpack_from(buf, 15)[0], S16LE.unpack_from(buf, 17)[0], - # Orientation - -(S16LE.unpack_from(buf, 19)[0]), + # Acceleration + S16LE.unpack_from(buf, 19)[0], S16LE.unpack_from(buf, 21)[0], S16LE.unpack_from(buf, 23)[0], From 7e5f2204ce75debeb7a5c6330c9c291c326af70e Mon Sep 17 00:00:00 2001 From: Naoki Mizuno Date: Sun, 25 Aug 2019 18:59:58 +0900 Subject: [PATCH 2/2] Rename field names to prevent misunderstanding The roll-pitch-yaw convention differs among industries, thus, is better to explicitly state the axis which rotation is considered. The field names also explicitly states that the values are "angular velocity" and "linear acceleration," as opposed to "orientation" and "motion," which are ambiguous (and technically incorrect). --- ds4drv/device.py | 16 ++++++++-------- ds4drv/uinput.py | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ds4drv/device.py b/ds4drv/device.py index 232ca7c..c496b48 100644 --- a/ds4drv/device.py +++ b/ds4drv/device.py @@ -41,12 +41,12 @@ class DS4Report(object): "button_options", "button_trackpad", "button_ps", - "orientation_roll", - "orientation_pitch", - "orientation_yaw", - "motion_x", - "motion_y", - "motion_z", + "ang_vel_x", + "ang_vel_y", + "ang_vel_z", + "lin_acc_x", + "lin_acc_y", + "lin_acc_z", "trackpad_touch0_id", "trackpad_touch0_active", "trackpad_touch0_x", @@ -181,12 +181,12 @@ def parse_report(self, buf): # Trackpad and PS buttons (buf[7] & 2) != 0, (buf[7] & 1) != 0, - # Orientation + # Angular velocity S16LE.unpack_from(buf, 13)[0], S16LE.unpack_from(buf, 15)[0], S16LE.unpack_from(buf, 17)[0], - # Acceleration + # Linear acceleration S16LE.unpack_from(buf, 19)[0], S16LE.unpack_from(buf, 21)[0], S16LE.unpack_from(buf, 23)[0], diff --git a/ds4drv/uinput.py b/ds4drv/uinput.py index 062c231..e73d21f 100644 --- a/ds4drv/uinput.py +++ b/ds4drv/uinput.py @@ -72,12 +72,12 @@ def create_mapping(name, description, bustype=0, vendor=0, product=0, "ABS_RZ": "right_analog_y", "ABS_RX": "l2_analog", "ABS_RY": "r2_analog", - "ABS_THROTTLE": "orientation_roll", - "ABS_RUDDER": "orientation_pitch", - "ABS_WHEEL": "orientation_yaw", - "ABS_DISTANCE": "motion_z", - "ABS_TILT_X": "motion_x", - "ABS_TILT_Y": "motion_y", + "ABS_THROTTLE": "ang_vel_x", + "ABS_RUDDER": "ang_vel_y", + "ABS_WHEEL": "ang_vel_z", + "ABS_DISTANCE": "lin_acc_z", + "ABS_TILT_X": "lin_acc_x", + "ABS_TILT_Y": "lin_acc_y", }, # Axes options {