diff --git a/server/core/src/main/java/dev/slimevr/tracker/behaviours/config.kt b/server/core/src/main/java/dev/slimevr/tracker/behaviours/config.kt index ce6995598..5a111651b 100644 --- a/server/core/src/main/java/dev/slimevr/tracker/behaviours/config.kt +++ b/server/core/src/main/java/dev/slimevr/tracker/behaviours/config.kt @@ -56,7 +56,7 @@ class TrackerConfigBehaviour( bodyPart = state.bodyPart, customName = state.customName, mountingOrientation = state.mountingOrientation, - mountingResetOrientation = if (saveMountingReset) state.sessionCalibration.headingAlignment else null, + mountingResetOrientation = if (saveMountingReset && state.lastMountingMethod != MountingMethod.MANUAL) state.sessionCalibration.headingAlignment else null, magEnabled = when (state.magStatus) { MagnetometerStatus.ENABLED -> true MagnetometerStatus.DISABLED -> false diff --git a/server/core/src/main/java/dev/slimevr/udp/behaviours.kt b/server/core/src/main/java/dev/slimevr/udp/behaviours.kt index 90bbdb0ae..711f4e0f9 100644 --- a/server/core/src/main/java/dev/slimevr/udp/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/udp/behaviours.kt @@ -9,6 +9,7 @@ import dev.slimevr.tracker.Tracker import dev.slimevr.tracker.TrackerActions import dev.slimevr.util.udpHardwareId import io.github.axisangles.ktmath.Quaternion +import io.github.axisangles.ktmath.Vector3 import kotlinx.coroutines.delay import kotlinx.coroutines.flow.distinctUntilChangedBy import kotlinx.coroutines.flow.launchIn @@ -24,13 +25,21 @@ import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds /** Convert from IMU axes to OpenGL/SteamVR axes */ -internal val AXES_OFFSET = Quaternion.fromRotationVector(-FastMath.HALF_PI, 0f, 0f) - -// TODO: Only apply this to firmwares <=0.7.3 -private val ACCEL_SENSOR_OFFSET_CORRECTION = Quaternion.rotationAroundZAxis(-FastMath.PI) +internal val AXES_OFFSET = Quaternion.rotationAroundXAxis(-FastMath.HALF_PI) internal const val CONNECTION_TIMEOUT_MS = 5000L +// Old protocol versions before 23 had messed up accel offsets in firmware +private val ACCEL_OFFSET_CORRECTION_22 = Quaternion.rotationAroundZAxis(FastMath.PI) +private val ACCEL_OFFSET_CORRECTION_21 = Quaternion.rotationAroundZAxis(-FastMath.HALF_PI) +fun getCorrectedAcceleration(acceleration: Vector3, protocolVersion: Int) = if (protocolVersion <= 21) { + ACCEL_OFFSET_CORRECTION_21.sandwich(acceleration) + } else if (protocolVersion == 22) { + ACCEL_OFFSET_CORRECTION_22.sandwich(acceleration) + } else { + acceleration + } + internal fun assignTracker(receiver: UDPConnection, device: Device, info: SensorInfo): Pair { val deviceState = device.context.state.value val deviceHardwareId = deviceState.hardwareId ?: udpHardwareId(deviceState.macAddress, deviceState.address) @@ -395,12 +404,14 @@ class SensorRotationBehaviour : UDPConnectionBehaviour { receiver.packetEvents.onPacket { event -> val tracker = receiver.getTracker(event.data.sensorId) ?: return@onPacket - tracker.context.dispatch(TrackerActions.SetRotation(rotation = AXES_OFFSET * event.data.rotation, acceleration = ACCEL_SENSOR_OFFSET_CORRECTION.sandwich(event.data.acceleration))) + val protocolVersion = receiver.getDevice()?.context?.state?.value?.protocolVersion ?: return@onPacket + tracker.context.dispatch(TrackerActions.SetRotation(rotation = AXES_OFFSET * event.data.rotation, acceleration = getCorrectedAcceleration(event.data.acceleration, protocolVersion))) }.launchIn(receiver.context.scope) receiver.packetEvents.onPacket { event -> val tracker = receiver.getTracker(event.data.sensorId) ?: return@onPacket - tracker.context.dispatch(TrackerActions.SetRotation(acceleration = ACCEL_SENSOR_OFFSET_CORRECTION.sandwich(event.data.acceleration))) + val protocolVersion = receiver.getDevice()?.context?.state?.value?.protocolVersion ?: return@onPacket + tracker.context.dispatch(TrackerActions.SetRotation(acceleration = getCorrectedAcceleration(event.data.acceleration, protocolVersion))) }.launchIn(receiver.context.scope) receiver.packetEvents.onPacket { event ->