mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-05 08:12:29 -08:00
Spotless
This commit is contained in:
8 files changed
+48
-48
No files matched your search
@@ -28,9 +28,11 @@ object DriverBaseBehaviour : DriverBridgeBehaviour {
|
||||
receiver.inbound.on<DriverBridgeInbound.TrackerPosition> { event ->
|
||||
val trackerId = receiver.context.state.value.trackers[event.id] ?: return@on
|
||||
receiver.appContext.server.getTracker(trackerId)?.let { tracker ->
|
||||
tracker.context.dispatch(TrackerActions.Update {
|
||||
copy(rawRotation = event.rotation, position = event.position)
|
||||
})
|
||||
tracker.context.dispatch(
|
||||
TrackerActions.Update {
|
||||
copy(rawRotation = event.rotation, position = event.position)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ object DriverBaseBehaviour : DriverBridgeBehaviour {
|
||||
sensorType = null,
|
||||
hardwareId = serial,
|
||||
origin = DeviceOrigin.DRIVER,
|
||||
appContext = receiver.appContext
|
||||
appContext = receiver.appContext,
|
||||
)
|
||||
server.context.dispatch(VRServerActions.NewTracker(trackerId, tracker))
|
||||
|
||||
|
||||
@@ -98,13 +98,13 @@ object HIDDeviceInfoBehaviour : HIDReceiverBehaviour {
|
||||
} else {
|
||||
val trackerId = receiver.appContext.server.nextHandle()
|
||||
val newTracker = Tracker.create(
|
||||
scope = receiver.appContext.server.context.scope,
|
||||
id = trackerId,
|
||||
deviceId = deviceState.id,
|
||||
sensorType = packet.imuType,
|
||||
hardwareId = deviceState.address,
|
||||
origin = DeviceOrigin.HID,
|
||||
appContext = receiver.appContext
|
||||
scope = receiver.appContext.server.context.scope,
|
||||
id = trackerId,
|
||||
deviceId = deviceState.id,
|
||||
sensorType = packet.imuType,
|
||||
hardwareId = deviceState.address,
|
||||
origin = DeviceOrigin.HID,
|
||||
appContext = receiver.appContext,
|
||||
)
|
||||
receiver.appContext.server.context.dispatch(VRServerActions.NewTracker(trackerId, newTracker))
|
||||
receiver.context.dispatch(HIDReceiverActions.TrackerRegistered(packet.hidId, trackerId))
|
||||
|
||||
@@ -131,10 +131,9 @@ object TrackerToSkeletonBehaviour : TrackerBehaviour {
|
||||
.onEach { (bodyPart, rotation) ->
|
||||
bodyPart?.let {
|
||||
receiver.appContext.skeleton.context.dispatch(
|
||||
SkeletonActions.SetBoneRotation(it, rotation)
|
||||
SkeletonActions.SetBoneRotation(it, rotation),
|
||||
)
|
||||
}
|
||||
}.launchIn(receiver.context.scope)
|
||||
}.launchIn(receiver.context.scope)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,8 +27,7 @@ fun applyCalibration(
|
||||
headingCorrect: HeadingCorrection = Quaternion.IDENTITY,
|
||||
attitudeAlign: AttitudeAlignment = Quaternion.IDENTITY,
|
||||
headingAlign: HeadingAlignment = Quaternion.IDENTITY,
|
||||
): CalibratedRotation =
|
||||
headingAlign.inv() * headingCorrect * rawRotation * attitudeAlign * headingAlign
|
||||
): CalibratedRotation = headingAlign.inv() * headingCorrect * rawRotation * attitudeAlign * headingAlign
|
||||
|
||||
// We reverse the order of headingAlign and attitudeAlign here since our
|
||||
// attitude alignment is within the raw heading frame of reference, so we must
|
||||
@@ -39,8 +38,7 @@ fun undoCalibration(
|
||||
headingCorrect: HeadingCorrection = Quaternion.IDENTITY,
|
||||
attitudeAlign: AttitudeAlignment = Quaternion.IDENTITY,
|
||||
headingAlign: HeadingAlignment = Quaternion.IDENTITY,
|
||||
): RawRotation =
|
||||
headingCorrect.inv() * headingAlign * calibratedRotation * headingAlign.inv() * attitudeAlign.inv()
|
||||
): RawRotation = headingCorrect.inv() * headingAlign * calibratedRotation * headingAlign.inv() * attitudeAlign.inv()
|
||||
|
||||
// Acceleration needs to be rotated by raw rotation with heading corrected
|
||||
private fun accelerationRotation(
|
||||
@@ -54,29 +52,27 @@ fun applyCalibration(
|
||||
rawRotation: RawRotation,
|
||||
headingCorrect: HeadingCorrection = Quaternion.IDENTITY,
|
||||
headingAlign: HeadingAlignment = Quaternion.IDENTITY,
|
||||
): CalibratedAcceleration =
|
||||
accelerationRotation(rawRotation, headingCorrect, headingAlign).sandwich(
|
||||
rawAcceleration
|
||||
)
|
||||
): CalibratedAcceleration = accelerationRotation(rawRotation, headingCorrect, headingAlign).sandwich(
|
||||
rawAcceleration,
|
||||
)
|
||||
|
||||
fun undoCalibration(
|
||||
calibratedAcceleration: CalibratedAcceleration,
|
||||
rawRotation: RawRotation,
|
||||
headingCorrect: HeadingCorrection = Quaternion.IDENTITY,
|
||||
headingAlign: HeadingAlignment = Quaternion.IDENTITY,
|
||||
): RawAcceleration =
|
||||
accelerationRotation(rawRotation, headingCorrect, headingAlign).inv()
|
||||
.sandwich(calibratedAcceleration)
|
||||
): RawAcceleration = accelerationRotation(rawRotation, headingCorrect, headingAlign).inv()
|
||||
.sandwich(calibratedAcceleration)
|
||||
|
||||
private fun eulerHeading(q: Quaternion): Quaternion =
|
||||
Quaternion.rotationAroundYAxis(q.toEulerAngles(EulerOrder.YZX).y).twinNearest(q)
|
||||
private fun eulerHeading(q: Quaternion): Quaternion = Quaternion.rotationAroundYAxis(q.toEulerAngles(EulerOrder.YZX).y).twinNearest(q)
|
||||
|
||||
fun estimateHeadingCorrect(
|
||||
rawRotation: RawRotation, referenceRotation: Quaternion
|
||||
): HeadingCorrection =
|
||||
eulerHeading(eulerHeading(referenceRotation).inv() * rawRotation).inv()
|
||||
.twinNearest(referenceRotation)
|
||||
rawRotation: RawRotation,
|
||||
referenceRotation: Quaternion,
|
||||
): HeadingCorrection = eulerHeading(eulerHeading(referenceRotation).inv() * rawRotation).inv()
|
||||
.twinNearest(referenceRotation)
|
||||
|
||||
fun estimateAttitudeAlign(
|
||||
rawRotation: RawRotation, headingCorrect: HeadingCorrection
|
||||
rawRotation: RawRotation,
|
||||
headingCorrect: HeadingCorrection,
|
||||
): AttitudeAlignment = (headingCorrect * rawRotation).inv()
|
||||
@@ -96,7 +96,7 @@ typealias VRCOSCBehaviour = Behaviour<VRCOSCState, VRCOSCActions, VRCOSCManager>
|
||||
|
||||
class VRCOSCManager(
|
||||
val context: VRCOSCContext,
|
||||
val oscQueryAddress: String
|
||||
val oscQueryAddress: String,
|
||||
) {
|
||||
val events: EventDispatcher<VRCOSCEvent> = EventDispatcher()
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ class SessionCalibrationTest {
|
||||
quaternionAssertEquals(
|
||||
headingCorrect,
|
||||
estimatedHeadingCorrect.twinNearest(headingCorrect),
|
||||
message = "Estimated heading correction is wrong"
|
||||
message = "Estimated heading correction is wrong",
|
||||
)
|
||||
|
||||
val estimatedAttitudeAlign =
|
||||
@@ -279,7 +279,7 @@ class SessionCalibrationTest {
|
||||
quaternionAssertEquals(
|
||||
attitudeAlign,
|
||||
estimatedAttitudeAlign.twinNearest(attitudeAlign),
|
||||
message = "Estimated attitude alignment is wrong"
|
||||
message = "Estimated attitude alignment is wrong",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
fun main(args: Array<String>) = runBlocking<Unit> {
|
||||
ContextDebug.enabled = System.getProperty("slimevr.debug.context") == "true" ||
|
||||
System.getenv("SLIMEVR_DEBUG_CONTEXT") == "true"
|
||||
ContextDebug.enabled = true
|
||||
|
||||
val configFolder = resolveConfigDirectory() ?: error("Unable to resolve config folder")
|
||||
val storage = DesktopConfigStorage(configFolder.toFile())
|
||||
|
||||
@@ -105,22 +105,26 @@ suspend fun handleDriverConnection(
|
||||
}
|
||||
}
|
||||
msg.tracker_added?.let { ta ->
|
||||
bridge.inbound.emit(DriverBridgeInbound.TrackerAdded(
|
||||
id = ta.tracker_id,
|
||||
name = ta.tracker_name,
|
||||
manufacturer = ta.manufacturer.ifEmpty { "OpenVR" },
|
||||
serial = ta.tracker_serial
|
||||
))
|
||||
bridge.inbound.emit(
|
||||
DriverBridgeInbound.TrackerAdded(
|
||||
id = ta.tracker_id,
|
||||
name = ta.tracker_name,
|
||||
manufacturer = ta.manufacturer.ifEmpty { "OpenVR" },
|
||||
serial = ta.tracker_serial,
|
||||
),
|
||||
)
|
||||
}
|
||||
msg.battery?.let { bat ->
|
||||
bridge.inbound.emit(DriverBridgeInbound.TrackerBattery(id = bat.tracker_id, batteryLevel = bat.battery_level, charging = bat.is_charging))
|
||||
}
|
||||
msg.position?.let { pos ->
|
||||
bridge.inbound.emit(DriverBridgeInbound.TrackerPosition(
|
||||
id = pos.tracker_id,
|
||||
rotation = Quaternion(w = pos.qw, x = pos.qx, y = pos.qy, z = pos.qz),
|
||||
position = if (pos.x != null && pos.y != null && pos.z != null) Vector3(pos.x, pos.y, pos.z) else null,
|
||||
))
|
||||
bridge.inbound.emit(
|
||||
DriverBridgeInbound.TrackerPosition(
|
||||
id = pos.tracker_id,
|
||||
rotation = Quaternion(w = pos.qw, x = pos.qx, y = pos.qy, z = pos.qz),
|
||||
position = if (pos.x != null && pos.y != null && pos.z != null) Vector3(pos.x, pos.y, pos.z) else null,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user