mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
bone acceleration fallback
This commit is contained in:
1 parent
65600a3141
commit
5f3820597e
9 files changed
+69
-28
No files matched your search
@@ -71,8 +71,15 @@ private fun getSourceToFollow(fk: ComputedSkeleton): FollowSource = if (isUserSi
|
||||
FollowSource.COM
|
||||
}
|
||||
|
||||
// Feet are always considered even if inactive
|
||||
private val alwaysActiveBodyParts = arrayOf(BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT, BodyPart.LEFT_LOWER_LEG, BodyPart.RIGHT_LOWER_LEG)
|
||||
// Legs are always used even if inactive
|
||||
private val alwaysActiveBodyParts = arrayOf(
|
||||
BodyPart.LEFT_FOOT,
|
||||
BodyPart.RIGHT_FOOT,
|
||||
BodyPart.LEFT_LOWER_LEG,
|
||||
BodyPart.RIGHT_LOWER_LEG,
|
||||
BodyPart.LEFT_UPPER_LEG,
|
||||
BodyPart.RIGHT_UPPER_LEG,
|
||||
)
|
||||
private fun getActiveBodyParts(inputs: InputSkeleton) = inputs.filter { it.value.isRotationActive }.map { it.key } + alwaysActiveBodyParts
|
||||
|
||||
/** Returns the active bone closest to or furthest inside the ground */
|
||||
@@ -92,8 +99,8 @@ object FootLocalizer {
|
||||
}
|
||||
|
||||
private fun whichPlantedFoot(bodyPart: BodyPart) = when (bodyPart) {
|
||||
BodyPart.LEFT_LOWER_LEG, BodyPart.LEFT_FOOT -> PlantedFoot.LEFT
|
||||
BodyPart.RIGHT_LOWER_LEG, BodyPart.RIGHT_FOOT -> PlantedFoot.RIGHT
|
||||
BodyPart.LEFT_FOOT -> PlantedFoot.LEFT
|
||||
BodyPart.RIGHT_FOOT -> PlantedFoot.RIGHT
|
||||
else -> PlantedFoot.NONE
|
||||
}
|
||||
|
||||
@@ -116,25 +123,24 @@ object FootLocalizer {
|
||||
}
|
||||
|
||||
fun getPlantedFoot(fk: ComputedSkeleton, lastPlantedFoot: PlantedFoot): PlantedFoot {
|
||||
// TODO start with foot, fallback to ankles, else it's nil
|
||||
val leftLowerLeg = fk[BodyPart.LEFT_LOWER_LEG] ?: return PlantedFoot.NONE
|
||||
val rightLowerLeg = fk[BodyPart.RIGHT_LOWER_LEG] ?: return PlantedFoot.NONE
|
||||
val leftFoot = fk[BodyPart.LEFT_FOOT] ?: return PlantedFoot.NONE
|
||||
val rightFoot = fk[BodyPart.RIGHT_FOOT] ?: return PlantedFoot.NONE
|
||||
|
||||
// If foot is locked, use that TODO should maybe not use that and just check y position instead
|
||||
// if (isFootLocked(leftLowerLeg, lastPlantedFoot)) return PlantedFoot.LEFT
|
||||
// if (isFootLocked(rightLowerLeg, lastPlantedFoot)) return PlantedFoot.RIGHT
|
||||
// if (isFootLocked(leftFoot, lastPlantedFoot)) return PlantedFoot.LEFT
|
||||
// if (isFootLocked(rightFoot, lastPlantedFoot)) return PlantedFoot.RIGHT
|
||||
|
||||
// Else, use velocity and accel to pick the foot who moves the least
|
||||
val leftVelocityAccelRatio = velocityAccelRatio(leftLowerLeg)
|
||||
val rightVelocityAccelRatio = velocityAccelRatio(rightLowerLeg)
|
||||
val leftVelocityAccelRatio = velocityAccelRatio(leftFoot)
|
||||
val rightVelocityAccelRatio = velocityAccelRatio(rightFoot)
|
||||
return if (leftVelocityAccelRatio < rightVelocityAccelRatio &&
|
||||
leftVelocityAccelRatio < MAX_FOOT_PERCENTAGE &&
|
||||
leftLowerLeg.acceleration.y < MAX_ACCEL_UP
|
||||
leftFoot.acceleration.y < MAX_ACCEL_UP
|
||||
) {
|
||||
PlantedFoot.LEFT
|
||||
} else if (rightVelocityAccelRatio < leftVelocityAccelRatio &&
|
||||
rightVelocityAccelRatio < MAX_FOOT_PERCENTAGE &&
|
||||
rightLowerLeg.acceleration.y < MAX_ACCEL_UP
|
||||
rightFoot.acceleration.y < MAX_ACCEL_UP
|
||||
) {
|
||||
PlantedFoot.RIGHT
|
||||
} else {
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package dev.slimevr.skeleton.inputprocessors
|
||||
|
||||
import dev.slimevr.skeleton.InputSkeleton
|
||||
import dev.slimevr.skeleton.SkeletonInputProcessor
|
||||
import dev.slimevr.skeleton.forEachBone
|
||||
import dev.slimevr.skeleton.iterateBodyPartHierarchy
|
||||
import io.github.axisangles.ktmath.Vector3
|
||||
import kotlin.collections.set
|
||||
|
||||
/**
|
||||
* Handles replacing accelerations of boneInputs that are not actively receiving any by
|
||||
* falling back to their parent's acceleration.
|
||||
*/
|
||||
class AccelerationFallbackInputProcessor : SkeletonInputProcessor {
|
||||
override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) {
|
||||
mutableInputSkeleton.forEachBone { parentPart, parentBone ->
|
||||
if (!parentBone.isAccelerationActive) return@forEachBone // Parent needs to be active
|
||||
|
||||
val parentAccel = parentBone.acceleration
|
||||
for (childPart in iterateBodyPartHierarchy(parentPart, true)) {
|
||||
val childBone = mutableInputSkeleton[childPart.second] ?: continue
|
||||
if (childBone.isAccelerationActive) continue // Child needs to be inactive
|
||||
|
||||
mutableInputSkeleton[childPart.second] = childBone.copy(acceleration = parentAccel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ class BoneYawFallbackInputProcessor : SkeletonInputProcessor {
|
||||
for (childPart in iterateBodyPartHierarchy(parentPart, true)) {
|
||||
val childBone = mutableInputSkeleton[childPart.second] ?: continue
|
||||
if (childBone.isRotationActive) continue // Child needs to be inactive
|
||||
if (parentYaw == childBone.rotation) continue
|
||||
|
||||
mutableInputSkeleton[childPart.second] = childBone.copy(rotation = parentYaw)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.slimevr.skeleton.computedprocessors.VelocityComputedProcessor
|
||||
import dev.slimevr.skeleton.fkprocessors.FootPlantFkProcessor
|
||||
import dev.slimevr.skeleton.fkprocessors.LocalizerFkProcessor
|
||||
import dev.slimevr.skeleton.fkprocessors.ToeSnapFkProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.AccelerationFallbackInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.BoneDirectLinkInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.BoneYawFallbackInputProcessor
|
||||
import dev.slimevr.skeleton.inputprocessors.ConstraintInputProcessor
|
||||
@@ -177,7 +178,7 @@ fun buildBones(boneInputs: InputSkeleton, changedParts: Set<BodyPart> = headPart
|
||||
}
|
||||
|
||||
sealed interface SkeletonActions {
|
||||
data class SetBonePose(val bodyPart: BodyPart, val trackerOffset: Vector3, val expectedTps: UShort, val rotation: Quaternion, val acceleration: Vector3, val position: Vector3?) : SkeletonActions
|
||||
data class SetBonePose(val bodyPart: BodyPart, val trackerOffset: Vector3, val expectedTps: UShort, val rotation: Quaternion, val acceleration: Vector3?, val position: Vector3?) : SkeletonActions
|
||||
data class DisableBone(val bodyPart: BodyPart) : SkeletonActions
|
||||
data class SetProportions(val lengths: Map<SkeletonBone, Float>) : SkeletonActions
|
||||
data class PauseTracking(val pause: Boolean) : SkeletonActions
|
||||
@@ -274,6 +275,7 @@ class Skeleton(
|
||||
FingerImputeInputProcessor(),
|
||||
ToeActiveLinkInputProcessor(),
|
||||
ConstraintInputProcessor(settings),
|
||||
AccelerationFallbackInputProcessor(),
|
||||
),
|
||||
fkComputedProcessors = listOf(
|
||||
VelocityComputedProcessor(),
|
||||
|
||||
@@ -7,6 +7,9 @@ import solarxr_protocol.datatypes.BodyPart
|
||||
fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when (action) {
|
||||
is SkeletonActions.SetBonePose -> {
|
||||
val bone = state.boneInputs[action.bodyPart] ?: return state
|
||||
// Rotation always non-null and active
|
||||
// Accel always non-null but not always active
|
||||
// Position not always non-null and not always active
|
||||
state.copy(
|
||||
boneInputs = state.boneInputs.mutateCopy {
|
||||
it[action.bodyPart] = bone.copy(
|
||||
@@ -14,8 +17,8 @@ fun reduce(state: SkeletonState, action: SkeletonActions): SkeletonState = when
|
||||
expectedTps = bone.expectedTps,
|
||||
rotation = action.rotation,
|
||||
isRotationActive = true,
|
||||
acceleration = action.acceleration,
|
||||
isAccelerationActive = true,
|
||||
acceleration = action.acceleration ?: Vector3.ZERO,
|
||||
isAccelerationActive = action.acceleration != null,
|
||||
position = action.position,
|
||||
isPositionActive = action.position != null,
|
||||
)
|
||||
|
||||
@@ -81,8 +81,8 @@ private fun createTracker(device: DeviceState, tracker: TrackerState, trackerMas
|
||||
},
|
||||
tps = if (trackerMask.tps) tracker.tps else null,
|
||||
temp = if (trackerMask.temp && tracker.imuTemp != null) tracker.imuTemp else null,
|
||||
rawAcceleration = if (trackerMask.rawAcceleration) tracker.rawAcceleration.toVec3f() else null,
|
||||
linearAcceleration = if (trackerMask.linearAcceleration) tracker.acceleration.toVec3f() else null,
|
||||
rawAcceleration = if (trackerMask.rawAcceleration) tracker.rawAcceleration?.toVec3f() else null,
|
||||
linearAcceleration = if (trackerMask.linearAcceleration) tracker.acceleration?.toVec3f() else null,
|
||||
rotationReferenceAdjusted = if (trackerMask.rotationReferenceAdjusted) tracker.rotation.toQuat() else null,
|
||||
rotationIdentityAdjusted = if (trackerMask.rotationIdentityAdjusted) tracker.rotation.toQuat() else null, // FIXME: uses reference adjusted
|
||||
rawMagneticVector = if (trackerMask.rawMagneticVector && tracker.magStatus == MagnetometerStatus.ENABLED) tracker.rawMagnetometer.toVec3f() else null,
|
||||
|
||||
@@ -108,6 +108,8 @@ class TapDetectionBasicBehaviour : TapDetectionBehaviour {
|
||||
.map { it.rawAcceleration to it.motion }
|
||||
.distinctUntilChanged()
|
||||
.onEach { (rawAcceleration, motionState) ->
|
||||
if (rawAcceleration == null) return@onEach
|
||||
|
||||
// Is this tracker over threshold for false positive prevention?
|
||||
val isOverThreshold = if (rawAcceleration.lenSq() > ALLOWED_BODY_ACCEL_SQUARED) {
|
||||
trackersOverThreshold.add(trackerTapDetectionState.trackerId)
|
||||
|
||||
@@ -75,8 +75,8 @@ data class TrackerState(
|
||||
val rawRotation: RawRotation,
|
||||
val rotation: CalibratedRotation,
|
||||
val rotationDirty: Boolean,
|
||||
val rawAcceleration: RawAcceleration,
|
||||
val acceleration: CalibratedAcceleration,
|
||||
val rawAcceleration: RawAcceleration?,
|
||||
val acceleration: CalibratedAcceleration?,
|
||||
val rawMagnetometer: Vector3,
|
||||
val position: Vector3?,
|
||||
val imuTemp: Float?,
|
||||
@@ -217,8 +217,8 @@ class Tracker(
|
||||
rawRotation = Quaternion.IDENTITY,
|
||||
rotation = Quaternion.IDENTITY,
|
||||
rotationDirty = false,
|
||||
rawAcceleration = Vector3.ZERO,
|
||||
acceleration = Vector3.ZERO,
|
||||
rawAcceleration = null,
|
||||
acceleration = null,
|
||||
rawMagnetometer = Vector3.ZERO,
|
||||
position = null,
|
||||
imuTemp = null,
|
||||
|
||||
@@ -36,11 +36,11 @@ fun reduce(
|
||||
}
|
||||
|
||||
// Other inputs
|
||||
val rawAcceleration: RawAcceleration = action.acceleration ?: state.rawAcceleration
|
||||
val rawAcceleration: RawAcceleration? = action.acceleration ?: state.rawAcceleration
|
||||
val rawMagnetometer = action.magnetometer ?: state.rawMagnetometer
|
||||
val position = action.position ?: state.position
|
||||
|
||||
// Rotation calibration
|
||||
// Rotation calibration: going from raw rotation to rotation since reset
|
||||
val rotation: CalibratedRotation =
|
||||
if (action.rotation != null) {
|
||||
applyFullCalibration(correctedRawRotation, state)
|
||||
@@ -49,10 +49,11 @@ fun reduce(
|
||||
state.rotation
|
||||
}
|
||||
|
||||
// Accel calibration
|
||||
val acceleration: CalibratedAcceleration =
|
||||
// Accel calibration: going from raw, rotation-aligned, accel to world-aligned accel
|
||||
// TODO: double check calibration; doesn't seem right - Erimel
|
||||
val acceleration: CalibratedAcceleration? =
|
||||
if (action.acceleration != null) {
|
||||
applyFullCalibration(rawAcceleration, correctedRawRotation, state)
|
||||
applyFullCalibration(action.acceleration, correctedRawRotation, state)
|
||||
} else {
|
||||
state.acceleration
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user