mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
No more T-pose (down)
To be superseded by https://github.com/SlimeVR/SlimeVR-Server/issues/1944 math was wrong anyways
This commit is contained in:
1 parent
5e8cbb2a0b
commit
52fb3f8fc4
14 files changed
+47
-128
No files matched your search
@@ -16,7 +16,7 @@ import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.MountingMethod
|
||||
import solarxr_protocol.rpc.ArmsResetMode
|
||||
import solarxr_protocol.rpc.ArmsMountingResetMode
|
||||
import solarxr_protocol.rpc.FilteringType
|
||||
import solarxr_protocol.rpc.KeybindId
|
||||
import solarxr_protocol.rpc.RoutingOutput
|
||||
@@ -95,7 +95,7 @@ data class ResetsConfig(
|
||||
/** Always reset mounting for feet */
|
||||
val resetMountingFeet: Boolean = false,
|
||||
/** Reset mode used for the arms */
|
||||
val armsResetMode: ArmsResetMode = ArmsResetMode.BACK,
|
||||
val armsMountingResetMode: ArmsMountingResetMode = ArmsMountingResetMode.BACK,
|
||||
/** Yaw reset smoothing time in seconds */
|
||||
val yawResetSmoothTime: Float = 0.0f,
|
||||
/** Save automatic mounting reset calibration */
|
||||
|
||||
@@ -33,7 +33,7 @@ import kotlinx.coroutines.withContext
|
||||
import solarxr_protocol.data_feed.server.ResetAvailability
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.MountingMethod
|
||||
import solarxr_protocol.rpc.ArmsResetMode
|
||||
import solarxr_protocol.rpc.ArmsMountingResetMode
|
||||
import solarxr_protocol.rpc.CountdownDetail
|
||||
import solarxr_protocol.rpc.ResetDetail
|
||||
import solarxr_protocol.rpc.ResetLifecycle
|
||||
@@ -225,23 +225,19 @@ class ResetsManager(
|
||||
AppLogger.resets.info("Clear Mounting Reset from $resetSourceName")
|
||||
}
|
||||
|
||||
private fun getYawOffset(bodyPart: BodyPart?, armsResetMode: ArmsResetMode) = when (bodyPart) {
|
||||
private fun getYawOffset(bodyPart: BodyPart?, armsResetMode: ArmsMountingResetMode) = when (bodyPart) {
|
||||
// Going forward
|
||||
in ResetBodyParts.UPPER_LEGS -> 0f
|
||||
|
||||
in ResetBodyParts.LOWER_ARMS if armsResetMode == ArmsResetMode.BACK -> 0f
|
||||
in ResetBodyParts.LOWER_ARMS if armsResetMode == ArmsMountingResetMode.BACK -> 0f
|
||||
|
||||
in ResetBodyParts.ARMS if armsResetMode == ArmsResetMode.FORWARD -> 0f
|
||||
in ResetBodyParts.ARMS if armsResetMode == ArmsMountingResetMode.FORWARD -> 0f
|
||||
|
||||
// Going left/
|
||||
in ResetBodyParts.LEFT_ARM if armsResetMode == ArmsResetMode.T_POSE_UP -> -FastMath.HALF_PI
|
||||
|
||||
in ResetBodyParts.RIGHT_ARM if armsResetMode == ArmsResetMode.T_POSE_DOWN -> -FastMath.HALF_PI
|
||||
in ResetBodyParts.LEFT_ARM if armsResetMode == ArmsMountingResetMode.SIDE -> -FastMath.HALF_PI
|
||||
|
||||
// Going right
|
||||
in ResetBodyParts.LEFT_ARM if armsResetMode == ArmsResetMode.T_POSE_DOWN -> FastMath.HALF_PI
|
||||
|
||||
in ResetBodyParts.RIGHT_ARM if armsResetMode == ArmsResetMode.T_POSE_UP -> FastMath.HALF_PI
|
||||
in ResetBodyParts.RIGHT_ARM if armsResetMode == ArmsMountingResetMode.SIDE -> FastMath.HALF_PI
|
||||
|
||||
// Going back
|
||||
else -> FastMath.PI
|
||||
@@ -250,7 +246,7 @@ class ResetsManager(
|
||||
private fun getResetAction(referenceRotation: Quaternion?, resetType: ResetType, bodyPart: BodyPart?, resetsConfig: ResetsConfig) = when (resetType) {
|
||||
ResetType.YAW -> TrackerActions.YawReset(referenceRotation, resetsConfig.yawResetSmoothTime.toDouble().seconds)
|
||||
ResetType.FULL -> TrackerActions.FullReset(referenceRotation, resetsConfig.resetReliableReferenceAttitude)
|
||||
ResetType.MOUNTING -> TrackerActions.PoseMountingReset(referenceRotation, getYawOffset(bodyPart, resetsConfig.armsResetMode))
|
||||
ResetType.MOUNTING -> TrackerActions.PoseMountingReset(referenceRotation, getYawOffset(bodyPart, resetsConfig.armsMountingResetMode))
|
||||
}
|
||||
|
||||
// By priority, higher value = higher priority. 0 for others.
|
||||
|
||||
@@ -19,7 +19,7 @@ class ResetsBehaviour(
|
||||
receiver.sendRpc(
|
||||
ResetsSettingsResponse(
|
||||
resetMountingFeet = config.resetMountingFeet,
|
||||
armsResetMode = config.armsResetMode,
|
||||
armsMountingResetMode = config.armsMountingResetMode,
|
||||
yawResetSmoothTime = config.yawResetSmoothTime,
|
||||
saveMountingReset = config.saveMountingReset,
|
||||
resetReliableReferenceAttitude = config.resetReliableReferenceAttitude,
|
||||
@@ -35,7 +35,7 @@ class ResetsBehaviour(
|
||||
copy(
|
||||
resetsConfig = ResetsConfig(
|
||||
resetMountingFeet = req.resetMountingFeet,
|
||||
armsResetMode = req.armsResetMode,
|
||||
armsMountingResetMode = req.armsMountingResetMode,
|
||||
yawResetSmoothTime = req.yawResetSmoothTime,
|
||||
saveMountingReset = req.saveMountingReset,
|
||||
resetReliableReferenceAttitude = req.resetReliableReferenceAttitude,
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package dev.slimevr.tracker.behaviours
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.resets.ResetBodyParts
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.tracker.TrackerBehaviour
|
||||
import io.github.axisangles.ktmath.EulerAngles
|
||||
import io.github.axisangles.ktmath.EulerOrder
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.ArmsResetMode
|
||||
|
||||
/**
|
||||
* Sets the orientation the tracker should match after a Full Reset.
|
||||
* Used for T-Pose down.
|
||||
*/
|
||||
class TrackerRestOrientationBehaviour(
|
||||
private val settings: Settings,
|
||||
) : TrackerBehaviour {
|
||||
override fun observe(receiver: Tracker) {
|
||||
val armsResetModeFlow = settings.context.state.map { it.data.resetsConfig.armsResetMode }
|
||||
val bodyPartFlow = receiver.context.state.map { it.bodyPart }.distinctUntilChanged()
|
||||
|
||||
combine(armsResetModeFlow, bodyPartFlow) { armsResetMode, bodyPart ->
|
||||
getRestOrientation(bodyPart, armsResetMode)
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.onEach { restOrientation ->
|
||||
receiver.context.dispatch(TrackerActions.SetRestOrientation(restOrientation))
|
||||
}
|
||||
.launchIn(receiver.context.scope)
|
||||
}
|
||||
|
||||
private val quarterRollLeft = EulerAngles(EulerOrder.YZX, 0f, 0f, -FastMath.HALF_PI).toQuaternion()
|
||||
private val quarterRollRight = EulerAngles(EulerOrder.YZX, 0f, 0f, FastMath.HALF_PI).toQuaternion()
|
||||
private fun getRestOrientation(bodyPart: BodyPart?, armsResetMode: ArmsResetMode) = if (armsResetMode == ArmsResetMode.T_POSE_DOWN) {
|
||||
when (bodyPart) {
|
||||
in ResetBodyParts.LEFT_ARM -> quarterRollLeft
|
||||
in ResetBodyParts.RIGHT_ARM -> quarterRollRight
|
||||
else -> Quaternion.IDENTITY
|
||||
}
|
||||
} else {
|
||||
Quaternion.IDENTITY
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import dev.slimevr.tracker.behaviours.TrackerAssignmentConflictBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerConfigBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerDefaultMountingOrientationBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerMotionDetectionBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerRestOrientationBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerRotationRefreshBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerStaleCalibrationBehaviour
|
||||
import dev.slimevr.tracker.behaviours.TrackerStayAlignedBehaviour
|
||||
@@ -70,7 +69,6 @@ data class TrackerState(
|
||||
val trackerDataType: TrackerDataType, // TODO
|
||||
val lastMountingMethod: MountingMethod,
|
||||
val mountingOrientation: HeadingAlignment,
|
||||
val restOrientation: RestOrientation,
|
||||
val lastReference: Quaternion?,
|
||||
val sessionCalibration: SessionCalibration,
|
||||
val rawRotation: RawRotation,
|
||||
@@ -113,7 +111,6 @@ sealed interface TrackerActions {
|
||||
data class SetDriverName(val driverName: String?) : TrackerActions
|
||||
data class SetRotation(val rotation: Quaternion? = null, val acceleration: Vector3? = null, val magnetometer: Vector3? = null, val position: Vector3? = null, val increaseTps: Boolean = true) : TrackerActions
|
||||
data class SetMountingOrientation(val mountingOrientation: HeadingAlignment) : TrackerActions
|
||||
data class SetRestOrientation(val restOrientation: Quaternion) : TrackerActions
|
||||
data class FullReset(val referenceRotation: Quaternion?, val resetReliableReferenceAttitude: Boolean = false) : TrackerActions
|
||||
data class YawReset(val referenceRotation: Quaternion?, val smoothTime: Duration = Duration.ZERO) : TrackerActions
|
||||
data class TickYawResetSmoothing(val heading: HeadingCorrection, val done: Boolean) : TrackerActions
|
||||
@@ -186,7 +183,6 @@ class Tracker(
|
||||
TrackerConfigBehaviour(settings, hardwareId),
|
||||
TrackerMotionDetectionBehaviour(),
|
||||
TrackerToSkeletonBehaviour(),
|
||||
TrackerRestOrientationBehaviour(settings),
|
||||
TrackerStayAlignedBehaviour(settings),
|
||||
)
|
||||
val context = Context.create(
|
||||
@@ -217,7 +213,6 @@ class Tracker(
|
||||
trackerDataType = TrackerDataType.ROTATION,
|
||||
lastMountingMethod = MountingMethod.MANUAL,
|
||||
mountingOrientation = Quaternion.IDENTITY,
|
||||
restOrientation = Quaternion.IDENTITY,
|
||||
lastReference = Quaternion.IDENTITY,
|
||||
sessionCalibration = SessionCalibration(),
|
||||
rawRotation = Quaternion.IDENTITY,
|
||||
|
||||
@@ -93,11 +93,6 @@ fun reduce(
|
||||
)
|
||||
}
|
||||
|
||||
is TrackerActions.SetRestOrientation -> state.copy(
|
||||
restOrientation = action.restOrientation,
|
||||
rotationDirty = true,
|
||||
)
|
||||
|
||||
is TrackerActions.FullReset -> {
|
||||
val alignAttitude = !state.isAssignedReliableReference || (action.resetReliableReferenceAttitude && action.referenceRotation == null)
|
||||
val correctHeading = action.referenceRotation != null && !state.isAssignedReliableReference
|
||||
|
||||
@@ -10,7 +10,6 @@ typealias RawAcceleration = Vector3
|
||||
typealias HeadingCorrection = Quaternion
|
||||
typealias AttitudeAlignment = Quaternion
|
||||
typealias HeadingAlignment = Quaternion
|
||||
typealias RestOrientation = Quaternion
|
||||
|
||||
typealias AccelerationRotation = Quaternion
|
||||
|
||||
@@ -28,8 +27,7 @@ fun applyCalibration(
|
||||
headingCorrect: HeadingCorrection = Quaternion.IDENTITY,
|
||||
attitudeAlign: AttitudeAlignment = Quaternion.IDENTITY,
|
||||
headingAlign: HeadingAlignment = Quaternion.IDENTITY,
|
||||
restOrientation: RestOrientation = Quaternion.IDENTITY,
|
||||
): CalibratedRotation = headingAlign.inv() * headingCorrect * rawRotation * attitudeAlign * headingAlign * restOrientation
|
||||
): CalibratedRotation = headingAlign.inv() * headingCorrect * rawRotation * attitudeAlign * headingAlign
|
||||
|
||||
fun applyFullCalibration(
|
||||
rawRotation: CalibratedRotation,
|
||||
@@ -43,7 +41,6 @@ fun applyFullCalibration(
|
||||
headingCorrection,
|
||||
trackerState.sessionCalibration.attitudeAlignment,
|
||||
headingAlignment,
|
||||
trackerState.restOrientation,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user