From e71fa3ed3da15ce194a5f186bde413b6b703e684 Mon Sep 17 00:00:00 2001 From: Erimel Date: Tue, 8 Sep 2026 19:51:30 -0400 Subject: [PATCH] Try to fix centaur bug more --- .../tracker/behaviours/calibration-refresh.kt | 2 +- .../main/java/dev/slimevr/tracker/module.kt | 18 ++++++------- .../main/java/dev/slimevr/tracker/reducer.kt | 27 +++++++++++++------ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/tracker/behaviours/calibration-refresh.kt b/server/core/src/main/java/dev/slimevr/tracker/behaviours/calibration-refresh.kt index fd6a2cdae..7b6438be4 100644 --- a/server/core/src/main/java/dev/slimevr/tracker/behaviours/calibration-refresh.kt +++ b/server/core/src/main/java/dev/slimevr/tracker/behaviours/calibration-refresh.kt @@ -16,7 +16,7 @@ class TrackerCalibrationRefreshBehaviour : TrackerBehaviour { } .onEach { // Make sure to send the raw data to have calibration re-apply - receiver.setRotation(it.rawRotation, it.rawAcceleration, it.rawMagnetometer, newData = false) + receiver.setRotation(it.rawRotation, it.rawAcceleration, it.rawMagnetometer, resetRefresh = true) }.launchIn(receiver.context.scope) } } diff --git a/server/core/src/main/java/dev/slimevr/tracker/module.kt b/server/core/src/main/java/dev/slimevr/tracker/module.kt index 1b0511548..897eceafe 100644 --- a/server/core/src/main/java/dev/slimevr/tracker/module.kt +++ b/server/core/src/main/java/dev/slimevr/tracker/module.kt @@ -105,12 +105,12 @@ sealed interface TrackerActions { level = DeprecationLevel.ERROR, ) constructor( - val rotation: Quaternion? = null, - val acceleration: Vector3? = null, - val magnetometer: Vector3? = null, - val position: Vector3? = null, - val newData: Boolean = true, - val polarityFallbackRotation: Quaternion? = null, + val rotation: Quaternion?, + val acceleration: Vector3?, + val magnetometer: Vector3?, + val position: Vector3?, + val resetRefresh: Boolean, + val polarityFallbackRotation: Quaternion, ) : TrackerActions data class SetMountingOrientation(val mountingOrientation: HeadingAlignment) : TrackerActions data class SetRestOrientation(val restOrientation: Quaternion) : TrackerActions @@ -139,7 +139,7 @@ class Tracker( acceleration: Vector3? = null, magnetometer: Vector3? = null, position: Vector3? = null, - newData: Boolean = true, + resetRefresh: Boolean = false, ) { // TODO if there's still centaur bug, we can use the nearest parent tracker's rotation instead of head. val polarityFallbackRotation = if (context.state.value.bodyPart != BodyPart.HEAD) { @@ -148,7 +148,7 @@ class Tracker( .getFirstActiveFor(BodyPart.HEAD)?.rotation } else { null - } + } ?: Quaternion.IDENTITY context.dispatch( @Suppress("DEPRECATION_ERROR") TrackerActions.SetRotation( @@ -156,7 +156,7 @@ class Tracker( acceleration = acceleration, magnetometer = magnetometer, position = position, - newData = newData, + resetRefresh = resetRefresh, polarityFallbackRotation = polarityFallbackRotation, ), ) diff --git a/server/core/src/main/java/dev/slimevr/tracker/reducer.kt b/server/core/src/main/java/dev/slimevr/tracker/reducer.kt index 06a358931..537e1eb39 100644 --- a/server/core/src/main/java/dev/slimevr/tracker/reducer.kt +++ b/server/core/src/main/java/dev/slimevr/tracker/reducer.kt @@ -1,7 +1,9 @@ package dev.slimevr.tracker import com.jme3.math.FastMath +import dev.slimevr.logging.AppLogger import io.github.axisangles.ktmath.Quaternion +import kotlinx.coroutines.launch import solarxr_protocol.datatypes.BodyPart import solarxr_protocol.datatypes.MountingMethod import kotlin.time.Duration @@ -12,11 +14,14 @@ private fun trackPolarity( newRotation: Quaternion, oldRotation: Quaternion, polarityFallbackRotation: Quaternion? = null, + debugBodyPart: BodyPart? = null, ): Quaternion { val absAngleChange = newRotation.angleToR(oldRotation) if (absAngleChange > UNRELIABLE_ANGLE_CHANGE_THRESHOLD && polarityFallbackRotation != null) { // Rotation rotated too much since last SetRotation; we're not sure which direction the tracker rotated. // Solution: align polarity with another tracker's rotation instead. + // TODO don't forget to remove log + AppLogger.console.warn("$debugBodyPart tracker rotated ${absAngleChange * FastMath.RAD_TO_DEG} in one tick. Assuming shortest rotation to head.") return newRotation.twinNearest(polarityFallbackRotation) } @@ -37,7 +42,7 @@ fun reduce( is TrackerActions.SetDriverName -> state.copy(driverName = action.driverName) is TrackerActions.SetRotation -> { - val accumulatedTicks = if (action.newData && action.rotation != null) (state.accumulatedTicks + 1u).toUShort() else state.accumulatedTicks + val accumulatedTicks = if (!action.resetRefresh && action.rotation != null) (state.accumulatedTicks + 1u).toUShort() else state.accumulatedTicks // Rotation val rawRotation: RawRotation = action.rotation ?: state.rawRotation @@ -55,11 +60,19 @@ fun reduce( // Rotation calibration val rotation: CalibratedRotation = if (action.rotation != null) { - trackPolarity( - applyCalibration(correctedRawRotation, cal.headingCorrection, cal.attitudeAlignment, cal.headingAlignment, state.restOrientation), - state.rotation, - action.polarityFallbackRotation, - ) + val calibratedRotation = applyCalibration(correctedRawRotation, cal.headingCorrection, cal.attitudeAlignment, cal.headingAlignment, state.restOrientation) + if (action.resetRefresh) { + // Assume shortest path <180d + calibratedRotation.twinNearest(action.polarityFallbackRotation) + } else { + // Track polarity to go over >180d + trackPolarity( + calibratedRotation, + state.rotation, + action.polarityFallbackRotation, + state.bodyPart, + ) + } } else { state.rotation } @@ -136,8 +149,6 @@ fun reduce( attitudeAlignment = attitudeAlignment, headingAlignment = headingAlignment, ), - // Reset polarity tracking - rotation = state.rotation.twinNearest(Quaternion.IDENTITY), // Full reset snaps: cancel any in-progress yaw smoothing. yawResetSmoothing = null, )