mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-26 11:56:27 -08:00
Add mounting reset
This commit is contained in:
3 files changed
+83
-2
No files matched your search
@@ -146,6 +146,8 @@ class TrackerBasicBehaviour : TrackerBehaviour {
|
||||
attitudeAlignment = attitudeAlignment,
|
||||
)
|
||||
|
||||
// TODO: Immediately apply calibration on `state.rawRotation` so we don't
|
||||
// need to worry about desync of `state.rotation`
|
||||
state.copy(sessionCalibration = sessionCalibration)
|
||||
}
|
||||
|
||||
@@ -161,12 +163,29 @@ class TrackerBasicBehaviour : TrackerBehaviour {
|
||||
headingCorrection = headingCorrection,
|
||||
)
|
||||
|
||||
// TODO: Apply calibration on `state.rawRotation` -> `state.rotation`
|
||||
state.copy(sessionCalibration = sessionCalibration)
|
||||
}
|
||||
|
||||
is TrackerActions.MountingReset -> {
|
||||
// TODO: Actually add mounting reset
|
||||
state
|
||||
val cal = state.sessionCalibration
|
||||
|
||||
val headingAlignment = estimateHeadingAlign(
|
||||
state.rawRotation,
|
||||
action.referenceRotation,
|
||||
cal?.headingCorrection ?: Quaternion.IDENTITY,
|
||||
cal?.attitudeAlignment ?: Quaternion.IDENTITY,
|
||||
state.mountingOrientation ?: Quaternion.IDENTITY,
|
||||
)
|
||||
|
||||
val sessionCalibration = state.sessionCalibration?.copy(
|
||||
headingAlignment = headingAlignment,
|
||||
) ?: SessionCalibration(
|
||||
headingAlignment = headingAlignment,
|
||||
)
|
||||
|
||||
// TODO: Apply calibration on `state.rawRotation` -> `state.rotation`
|
||||
state.copy(sessionCalibration = sessionCalibration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.slimevr.tracker
|
||||
import io.github.axisangles.ktmath.EulerOrder
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlin.math.atan2
|
||||
|
||||
typealias RawRotation = Quaternion
|
||||
typealias RawAcceleration = Vector3
|
||||
@@ -76,3 +77,22 @@ fun estimateAttitudeAlign(
|
||||
rawRotation: RawRotation,
|
||||
headingCorrect: HeadingCorrection,
|
||||
): AttitudeAlignment = (headingCorrect * rawRotation).inv()
|
||||
|
||||
fun estimateHeadingAlign(
|
||||
rawRotation: RawRotation,
|
||||
referenceRotation: Quaternion,
|
||||
headingCorrect: HeadingCorrection = Quaternion.IDENTITY,
|
||||
attitudeAlign: AttitudeAlignment = Quaternion.IDENTITY,
|
||||
headingAlign: HeadingAlignment = Quaternion.IDENTITY,
|
||||
): HeadingAlignment {
|
||||
val refHeading = eulerHeading(referenceRotation)
|
||||
val rotation = applyCalibration(
|
||||
rawRotation,
|
||||
headingCorrect,
|
||||
attitudeAlign,
|
||||
headingAlign,
|
||||
)
|
||||
val pitchRoll = (refHeading.inv() * rotation).sandwichUnitY()
|
||||
val yawAngle = atan2(pitchRoll.x, pitchRoll.z)
|
||||
return Quaternion.rotationAroundYAxis(yawAngle)
|
||||
}
|
||||
Reference in new issue
Block a user