From aa91813ba2e6817162741d2f60117c9a5e284b77 Mon Sep 17 00:00:00 2001 From: Naoki Mizuno Date: Sun, 25 Aug 2019 18:52:23 +0900 Subject: [PATCH] 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],