From d84fc40b23e6769a706e8d302213eb599c6491dc Mon Sep 17 00:00:00 2001 From: sctanf <36978460+sctanf@users.noreply.github.com> Date: Mon, 12 May 2025 11:52:29 -0400 Subject: [PATCH 1/6] TrackersHID keep opening existing devices (#1429) --- .../slimevr/desktop/tracking/trackers/hid/TrackersHID.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt b/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt index 4683aeea5..f1b4dec8f 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt @@ -463,10 +463,14 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) // Work on devicesByHid and add/remove as necessary val removeList: MutableList = devicesByHID.keys.toMutableList() removeList.removeAll(hidDeviceList) - hidDeviceList.removeAll(devicesByHID.keys) // addList for (device in removeList) { removeDevice(device) } + // Quickly reattaching a device may not be detected, so always try to open existing devices + for (device in devicesByHID.keys) { + device.open() + } + hidDeviceList.removeAll(devicesByHID.keys) // addList for (device in hidDeviceList) { checkConfigureDevice(device) } From e74dee189205337fe94a65b505cb26402b0a4fd6 Mon Sep 17 00:00:00 2001 From: sctanf <36978460+sctanf@users.noreply.github.com> Date: Mon, 12 May 2025 11:52:41 -0400 Subject: [PATCH 2/6] TrackersHID report magnetometer packet (#1428) --- .../tracking/trackers/hid/TrackersHID.kt | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt b/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt index f1b4dec8f..90584dba7 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt @@ -217,6 +217,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) var devicesDataReceived = false val q = intArrayOf(0, 0, 0, 0) val a = intArrayOf(0, 0, 0) + val m = intArrayOf(0, 0, 0) for ((hidDevice, deviceList) in devicesByHID) { val dataReceived: ByteArray = try { hidDevice.readAll(0) // multiples 64 bytes @@ -318,7 +319,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) // Q15 as short big endian q[j] = dataReceived[i + 2 + j * 2 + 1].toInt() shl 8 or dataReceived[i + 2 + j * 2].toUByte().toInt() } - for (j in 0..2) { // accel received as fixed 7, in m/s + for (j in 0..2) { // accel received as fixed 7, in m/s^2 // Q7 as short big endian a[j] = dataReceived[i + 10 + j * 2 + 1].toInt() shl 8 or dataReceived[i + 10 + j * 2].toUByte().toInt() } @@ -336,7 +337,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) q[0] = (q_buf and 1023u).toInt() q[1] = (q_buf shr 10 and 2047u).toInt() q[2] = (q_buf shr 21 and 2047u).toInt() - for (j in 0..2) { // accel received as fixed 7, in m/s + for (j in 0..2) { // accel received as fixed 7, in m/s^2 // Q7 as short big endian a[j] = dataReceived[i + 9 + j * 2 + 1].toInt() shl 8 or dataReceived[i + 9 + j * 2].toUByte().toInt() } @@ -349,6 +350,17 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) rssi = dataReceived[i + 15].toUByte().toInt() } + 4 -> { // full precision quat and mag, no extra data + for (j in 0..3) { // quat received as fixed Q15 + // Q15 as short big endian + q[j] = dataReceived[i + 2 + j * 2 + 1].toInt() shl 8 or dataReceived[i + 2 + j * 2].toUByte().toInt() + } + for (j in 0..2) { // mag received as fixed 10, in gauss + // Q10 as short big endian + m[j] = dataReceived[i + 10 + j * 2 + 1].toInt() shl 8 or dataReceived[i + 10 + j * 2].toUByte().toInt() + } + } + else -> { } } @@ -395,7 +407,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) } // Assign rotation and acceleration - if (packetType == 1) { + if (packetType == 1 || packetType == 4) { // The data comes in the same order as in the UDP protocol // x y z w -> w x y z var rot = Quaternion(q[3].toFloat(), q[0].toFloat(), q[1].toFloat(), q[2].toFloat()) @@ -427,6 +439,20 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) val scaleAccel = 1 / (1 shl 7).toFloat() // compile time evaluation var acceleration = Vector3(a[0].toFloat(), a[1].toFloat(), a[2].toFloat()).times(scaleAccel) // no division tracker.setAcceleration(acceleration) + } + if (packetType == 4) { + // Magnetometer is in local device frame + // On flat surface / face up: + // Right side of the device is +X + // Front side (facing up) is +Z + // Mounted on body / standing up: + // Top side of the device is +Y + // Front side (facing out) is +Z + val scaleMag = 1000 / (1 shl 10).toFloat() // compile time evaluation, and change gauss to milligauss + var magnetometer = Vector3(m[0].toFloat(), m[1].toFloat(), m[2].toFloat()).times(scaleMag) // no division + tracker.setMagVector(magnetometer) + } + if (packetType == 1 || packetType == 2 || packetType == 4) { tracker.dataTick() // only data tick if there is rotation data } From ea31d58fb8ed6cc91eb3d9bbdc0577b5a2337190 Mon Sep 17 00:00:00 2001 From: sctanf <36978460+sctanf@users.noreply.github.com> Date: Mon, 12 May 2025 11:52:50 -0400 Subject: [PATCH 3/6] IMUVisualizerWidget accel replace three arrows with one vector (#1430) --- .../widgets/IMUVisualizerWidget.tsx | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/gui/src/components/widgets/IMUVisualizerWidget.tsx b/gui/src/components/widgets/IMUVisualizerWidget.tsx index 5cecbbf9f..6d28df6eb 100644 --- a/gui/src/components/widgets/IMUVisualizerWidget.tsx +++ b/gui/src/components/widgets/IMUVisualizerWidget.tsx @@ -9,7 +9,7 @@ import { PerspectiveCamera, Vector3 } from 'three'; import { Button } from '@/components/commons/Button'; import { QuatObject } from '@/maths/quaternion'; import { useLocalization } from '@fluent/react'; -import { Vector3Object } from '@/maths/vector3'; +import { Vector3Object, Vector3FromVec3fT } from '@/maths/vector3'; import { Gltf } from '@react-three/drei'; import { ErrorBoundary } from 'react-error-boundary'; @@ -56,23 +56,9 @@ function SceneRenderer({ - - From a35d2a77a239e158aa27bad3ac9d13f94ba37a33 Mon Sep 17 00:00:00 2001 From: sctanf <36978460+sctanf@users.noreply.github.com> Date: Mon, 12 May 2025 11:53:02 -0400 Subject: [PATCH 4/6] TrackersHID clearly define acceleration axes (#1431) --- .../slimevr/desktop/tracking/trackers/hid/TrackersHID.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt b/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt index 90584dba7..1332f7485 100644 --- a/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt +++ b/server/desktop/src/main/java/dev/slimevr/desktop/tracking/trackers/hid/TrackersHID.kt @@ -435,7 +435,13 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer) tracker.setRotation(rot) } if (packetType == 1 || packetType == 2) { - // TODO: Acceleration "was" wrong + // Acceleration is in local device frame + // On flat surface / face up: + // Right side of the device is +X + // Front side (facing up) is +Z + // Mounted on body / standing up: + // Top side of the device is +Y + // Front side (facing out) is +Z val scaleAccel = 1 / (1 shl 7).toFloat() // compile time evaluation var acceleration = Vector3(a[0].toFloat(), a[1].toFloat(), a[2].toFloat()).times(scaleAccel) // no division tracker.setAcceleration(acceleration) From 91ce0ed734a84edd0bb91373deb39fb06e7f5c33 Mon Sep 17 00:00:00 2001 From: Aleksandra M Date: Mon, 12 May 2025 18:59:44 +0300 Subject: [PATCH 5/6] Add magnetic field vector (#1416) --- .../widgets/IMUVisualizerWidget.tsx | 31 ++++++++++++++++ gui/src/hooks/datafeed-config.ts | 1 + .../protocol/datafeed/DataFeedBuilder.java | 36 ++++++++++--------- .../dev/slimevr/tracking/trackers/Tracker.kt | 17 +++++++++ solarxr-protocol | 2 +- 5 files changed, 70 insertions(+), 17 deletions(-) diff --git a/gui/src/components/widgets/IMUVisualizerWidget.tsx b/gui/src/components/widgets/IMUVisualizerWidget.tsx index 6d28df6eb..2f40d3591 100644 --- a/gui/src/components/widgets/IMUVisualizerWidget.tsx +++ b/gui/src/components/widgets/IMUVisualizerWidget.tsx @@ -28,12 +28,20 @@ export function TrackerModel({ model }: { model: string }) { function SceneRenderer({ quat, vec, + mag, model, }: { quat: QuatObject; vec: Vector3Object; + mag: Vector3Object; model: string; }) { + const magDir = new Vector3(mag.x, mag.y, mag.z); + const magLen = magDir.length(); + const magMag = Math.sqrt(magLen / 100); // normalize magnituge + if (magLen > 0) + magDir.multiplyScalar(1/ magLen); + return ( + @@ -102,6 +118,9 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) { tracker?.linearAcceleration || tracker?.rawAcceleration || new THREE.Vector3(); + const mag = + tracker?.rawMagneticVector || + new THREE.Vector3(); return (
@@ -143,6 +162,17 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
)} + {tracker.rawMagneticVector && ( +
+ + {l10n.getString('tracker-infos-magnetometer')} + + + {formatVector3(tracker.rawMagneticVector, 1)} + +
+ )} + {!enabled && (