mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-25 19:41:20 -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)
|
||||
}
|
||||
@@ -274,6 +274,7 @@ class SessionCalibrationTest {
|
||||
message = "Estimated heading correction is wrong",
|
||||
)
|
||||
|
||||
// TODO: See if we can avoid using twinNearest
|
||||
val estimatedAttitudeAlign =
|
||||
estimateAttitudeAlign(rawRotation, estimatedHeadingCorrect)
|
||||
quaternionAssertEquals(
|
||||
@@ -283,6 +284,47 @@ class SessionCalibrationTest {
|
||||
)
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
fun estimateHeadingAlignTests(): List<DynamicTest> {
|
||||
val frontRot = Quaternion(0.707f, 0.707f, 0f, 0f)
|
||||
return heading.flatMap { hA ->
|
||||
heading.map { ref ->
|
||||
DynamicTest.dynamicTest(
|
||||
"( hA: $hA, ref: $ref )",
|
||||
) {
|
||||
testEstimateHeadingAlign(
|
||||
ref * frontRot,
|
||||
hA,
|
||||
ref
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testEstimateHeadingAlign(
|
||||
calibratedRotation: CalibratedRotation,
|
||||
headingAlign: HeadingAlignment,
|
||||
reference: Quaternion,
|
||||
) {
|
||||
// Only undo heading
|
||||
val rawRotation = undoCalibration(
|
||||
calibratedRotation,
|
||||
headingAlign = headingAlign,
|
||||
)
|
||||
|
||||
// TODO: See if we can avoid using twinNearest
|
||||
val estimateHeadingAlign = estimateHeadingAlign(
|
||||
rawRotation,
|
||||
reference,
|
||||
)
|
||||
quaternionAssertEquals(
|
||||
headingAlign,
|
||||
estimateHeadingAlign.twinNearest(headingAlign),
|
||||
message = "Estimated heading alignment is wrong",
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// 5 steps
|
||||
val step = (-180..180 step 72).map { it.toFloat() }
|
||||
|
||||
Reference in new issue
Block a user