From caf843563658c035df115beee90c8b248b999177 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Fri, 13 Nov 2026 23:59:35 +0100 Subject: [PATCH] Migrate old server configs to rewrite --- server/core/build.gradle.kts | 1 + .../main/java/dev/slimevr/config/devices.kt | 33 +- .../main/java/dev/slimevr/config/legacy.kt | 269 ++++++++++++++++ .../main/java/dev/slimevr/config/module.kt | 8 +- .../src/main/java/dev/slimevr/config/user.kt | 3 + .../dev/slimevr/hid/behaviours/register.kt | 6 +- .../dev/slimevr/solarxr/driver/incoming.kt | 6 +- .../solarxr/rpc/skeleton-proportions.kt | 7 +- .../java/dev/slimevr/tracker/hardware-id.kt | 7 + .../main/java/dev/slimevr/udp/behaviours.kt | 3 +- .../config/DevicesConfigMigrationTest.kt | 45 +++ .../dev/slimevr/config/LegacyConfigTest.kt | 304 ++++++++++++++++++ .../dev/slimevr/solarxr/SettingsResetTest.kt | 6 +- .../java/dev/slimevr/udp/ForgetDeviceTest.kt | 5 +- 14 files changed, 684 insertions(+), 19 deletions(-) create mode 100644 server/core/src/main/java/dev/slimevr/config/legacy.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracker/hardware-id.kt create mode 100644 server/core/src/test/java/dev/slimevr/config/DevicesConfigMigrationTest.kt create mode 100644 server/core/src/test/java/dev/slimevr/config/LegacyConfigTest.kt diff --git a/server/core/build.gradle.kts b/server/core/build.gradle.kts index 2b18488a0..697d94fa6 100644 --- a/server/core/build.gradle.kts +++ b/server/core/build.gradle.kts @@ -52,6 +52,7 @@ kotlin { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.10.0") + implementation("it.krzeminski:snakeyaml-engine-kmp:3.2.1") } } val commonTest = getByName("commonTest") { diff --git a/server/core/src/main/java/dev/slimevr/config/devices.kt b/server/core/src/main/java/dev/slimevr/config/devices.kt index b447e28f5..7b091da12 100644 --- a/server/core/src/main/java/dev/slimevr/config/devices.kt +++ b/server/core/src/main/java/dev/slimevr/config/devices.kt @@ -2,18 +2,22 @@ package dev.slimevr.config import dev.slimevr.context.Behaviour import dev.slimevr.context.Context +import dev.slimevr.tracker.driverTrackerHardwareId +import dev.slimevr.tracker.hidTrackerHardwareId +import dev.slimevr.tracker.udpTrackerHardwareId import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import kotlinx.coroutines.CoroutineScope import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.intOrNull import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import solarxr_protocol.datatypes.BodyPart -private const val DEVICES_CONFIG_VERSION = 1 +private const val DEVICES_CONFIG_VERSION = 2 const val DEVICES_CONFIG_PATH = "devices.json" @Serializable @@ -88,9 +92,32 @@ class DevicesConfig( private fun migrateDevicesConfig(json: JsonObject): JsonObject { val version = json["version"]?.jsonPrimitive?.intOrNull ?: 0 - return when { - else -> json + if (version >= DEVICES_CONFIG_VERSION) return json + val migrated = (version + 1..DEVICES_CONFIG_VERSION).fold(json) { current, to -> migrateDevicesConfigTo(to, current) } + return JsonObject(migrated + ("version" to JsonPrimitive(DEVICES_CONFIG_VERSION))) +} + +/** Brings a devices config up to version [to] from the one before. */ +private fun migrateDevicesConfigTo(to: Int, json: JsonObject): JsonObject = when (to) { + 1 -> json + 2 -> migrateDevicesConfigV2(json) + else -> error("No devices config migration to version $to") +} + +/** Version 1 keyed trackers by their bare hardware id, version 2 prefixes it with the tracker origin. */ +private fun migrateDevicesConfigV2(json: JsonObject): JsonObject { + val udpTrackerId = Regex("((?:[0-9A-F]{2}:){5}[0-9A-F]{2}|\\d{1,3}(?:\\.\\d{1,3}){3}):(\\d{1,9})") + val hidTrackerId = Regex("[0-9A-F]{12}|[0-9A-F]{16}") + + fun prefixed(id: String): String { + if (id.startsWith("vmc:") || id.startsWith("vrcosc:")) return id + udpTrackerId.matchEntire(id)?.let { return udpTrackerHardwareId(it.groupValues[1], it.groupValues[2].toInt()) } + if (hidTrackerId.matches(id)) return hidTrackerHardwareId(id) + return driverTrackerHardwareId(id) } + + val trackers = json["trackers"] as? JsonObject ?: return json + return JsonObject(json + ("trackers" to JsonObject(trackers.mapKeys { (id, _) -> prefixed(id) }))) } private fun parseAndMigrateDevicesConfig(raw: String): DevicesConfigState { diff --git a/server/core/src/main/java/dev/slimevr/config/legacy.kt b/server/core/src/main/java/dev/slimevr/config/legacy.kt new file mode 100644 index 000000000..a6a1d3e23 --- /dev/null +++ b/server/core/src/main/java/dev/slimevr/config/legacy.kt @@ -0,0 +1,269 @@ +package dev.slimevr.config + +import dev.slimevr.logging.AppLogger +import dev.slimevr.tracker.hidTrackerHardwareId +import dev.slimevr.tracker.udpTrackerHardwareId +import io.github.axisangles.ktmath.Quaternion +import it.krzeminski.snakeyaml.engine.kmp.api.Load +import it.krzeminski.snakeyaml.engine.kmp.api.LoadSettings +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.jsonObject +import solarxr_protocol.datatypes.BodyPart +import solarxr_protocol.rpc.ArmsMountingResetMode +import solarxr_protocol.rpc.StayAlignedRelaxedPose + +/** Config file of the previous server, in the same folder as the current config. */ +const val LEGACY_CONFIG_PATH = "vrconfig.yml" +private const val MIN_LEGACY_CONFIG_VERSION = 14 + +private val UDP_TRACKER_NAME = Regex("udp://((?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2})/(\\d{1,9})") +private val HID_TRACKER_NAME = Regex("([0-9A-Fa-f]{12})/0") + +private val LEGACY_POSE_KEYS = listOf( + StayAlignedRelaxedPose.STANDING to "standingRelaxedPose", + StayAlignedRelaxedPose.SITTING to "sittingRelaxedPose", + StayAlignedRelaxedPose.FLAT to "flatRelaxedPose", +) + +data class LegacyConfigMigration( + val settings: SettingsConfigState, + val user: UserConfigData, + val devices: DevicesConfigState, +) + +suspend fun importLegacyConfig(storage: ConfigStorage) { + if (storage.exists(GLOBAL_CONFIG_PATH)) return + val raw = storage.read(LEGACY_CONFIG_PATH) ?: return + + val migration = try { + migrateLegacyConfig(raw) + } catch (e: Exception) { + AppLogger.config.error(e, "Failed to read ${storage.displayPath(LEGACY_CONFIG_PATH)}") + return + } + if (migration == null) { + AppLogger.config.info("Skipped ${storage.displayPath(LEGACY_CONFIG_PATH)}, only version $MIN_LEGACY_CONFIG_VERSION and newer are imported") + return + } + + val defaults = GlobalConfigState() + storage.write( + configPath(SETTINGS_PROFILE_DIR, profileFileName(defaults.selectedSettingsProfile)), + jsonConfig.encodeToString(migration.settings), + overwrite = false, + ) + storage.write( + configPath(USER_PROFILE_DIR, profileFileName(defaults.selectedUserProfile)), + jsonConfig.encodeToString(migration.user), + overwrite = false, + ) + storage.write(DEVICES_CONFIG_PATH, jsonConfig.encodeToString(migration.devices), overwrite = false) + AppLogger.config.info("Imported ${storage.displayPath(LEGACY_CONFIG_PATH)}") +} + +fun migrateLegacyConfig(yaml: String): LegacyConfigMigration? { + // Configs saved before the GUI trimmed the VRM hold its whole glTF JSON, which can go past the 3 MB default + val loadSettings = LoadSettings.builder().setCodePointLimit(Int.MAX_VALUE).build() + val root = Load(loadSettings).loadOne(yaml) as? Map<*, *> ?: return null + val version = intOf(root["modelVersion"]) ?: return null + if (version < MIN_LEGACY_CONFIG_VERSION) return null + + return LegacyConfigMigration( + settings = settingsOf(root), + user = userOf(root), + devices = devicesOf(root), + ) +} + +private fun settingsOf(root: Map<*, *>): SettingsConfigState { + val defaults = SettingsConfigState() + val server = section(root, "server") + val skeleton = section(root, "skeleton") + val toggles = section(skeleton, "toggles") + val values = section(skeleton, "values") + val resets = section(root, "resetsConfig") + val tap = section(root, "tapDetection") + val vmc = section(root, "vmc") + val hid = section(root, "hidConfig") + val stayAligned = section(root, "stayAlignedConfig") + + val defaultToggles = defaults.skeletonConfig.toggles + val defaultRatios = defaults.skeletonConfig.ratios + val defaultResets = defaults.resetsConfig + val defaultTap = defaults.tapDetectionConfig + val defaultVmc = defaults.vmcConfig + + return defaults.copy( + trackersConfig = defaults.trackersConfig.copy( + globalMagEnabled = boolOf(server["useMagnetometerOnAllTrackers"]) ?: defaults.trackersConfig.globalMagEnabled, + ), + hidConfig = defaults.hidConfig.copy( + trackersOverHid = boolOf(hid["trackersOverHID"]) ?: defaults.hidConfig.trackersOverHid, + ), + skeletonConfig = defaults.skeletonConfig.copy( + toggles = defaultToggles.copy( + floorClip = boolOf(toggles["floorClip"]) ?: defaultToggles.floorClip, + skatingCorrection = boolOf(toggles["skatingCorrection"]) ?: defaultToggles.skatingCorrection, + toeSnap = boolOf(toggles["toeSnap"]) ?: defaultToggles.toeSnap, + footPlant = boolOf(toggles["footPlant"]) ?: defaultToggles.footPlant, + mocapMode = boolOf(toggles["selfLocalization"]) ?: defaultToggles.mocapMode, + enforceConstraints = boolOf(toggles["enforceConstraints"]) ?: defaultToggles.enforceConstraints, + ), + ratios = defaultRatios.copy( + interpolateUpperLegsTwistWithLowerLegs = floatOf(values["kneeTrackerAnkleAveraging"]) + ?: defaultRatios.interpolateUpperLegsTwistWithLowerLegs, + ), + ), + resetsConfig = defaultResets.copy( + resetMountingFeet = boolOf(resets["resetMountingFeet"]) ?: defaultResets.resetMountingFeet, + armsMountingResetMode = armsMountingResetModeOf(resets["mode"]) ?: defaultResets.armsMountingResetMode, + yawResetSmoothTime = floatOf(resets["yawResetSmoothTime"]) ?: defaultResets.yawResetSmoothTime, + saveMountingReset = boolOf(resets["saveMountingReset"]) ?: defaultResets.saveMountingReset, + resetHmdAttitude = boolOf(resets["resetHmdPitch"]) ?: defaultResets.resetHmdAttitude, + ), + tapDetectionConfig = defaultTap.copy( + yawResetDelay = floatOf(tap["yawResetDelay"]) ?: defaultTap.yawResetDelay, + fullResetDelay = floatOf(tap["fullResetDelay"]) ?: defaultTap.fullResetDelay, + mountingResetDelay = floatOf(tap["mountingResetDelay"]) ?: defaultTap.mountingResetDelay, + yawResetEnabled = boolOf(tap["yawResetEnabled"]) ?: defaultTap.yawResetEnabled, + fullResetEnabled = boolOf(tap["fullResetEnabled"]) ?: defaultTap.fullResetEnabled, + mountingResetEnabled = boolOf(tap["mountingResetEnabled"]) ?: defaultTap.mountingResetEnabled, + yawResetBodyPart = stringOf(tap["yawResetTracker"])?.let(::bodyPartOf) ?: defaultTap.yawResetBodyPart, + fullResetBodyPart = stringOf(tap["fullResetTracker"])?.let(::bodyPartOf) ?: defaultTap.fullResetBodyPart, + mountingResetBodyPart = stringOf(tap["mountingResetTracker"])?.let(::bodyPartOf) ?: defaultTap.mountingResetBodyPart, + yawResetTaps = intOf(tap["yawResetTaps"]) ?: defaultTap.yawResetTaps, + fullResetTaps = intOf(tap["fullResetTaps"]) ?: defaultTap.fullResetTaps, + mountingResetTaps = intOf(tap["mountingResetTaps"]) ?: defaultTap.mountingResetTaps, + numberTrackersOverThreshold = intOf(tap["numberTrackersOverThreshold"]) ?: defaultTap.numberTrackersOverThreshold, + ), + vmcConfig = defaultVmc.copy( + enabled = boolOf(vmc["enabled"]) ?: defaultVmc.enabled, + portIn = intOf(vmc["portIn"]) ?: defaultVmc.portIn, + portOut = intOf(vmc["portOut"]) ?: defaultVmc.portOut, + address = stringOf(vmc["address"]) ?: defaultVmc.address, + mirrorTracking = boolOf(vmc["mirrorTracking"]) ?: defaultVmc.mirrorTracking, + anchorAtHips = boolOf(vmc["anchorHip"]) ?: defaultVmc.anchorAtHips, + vrmJson = vrmJsonOf(vmc["vrmJson"]) ?: defaultVmc.vrmJson, + ), + stayAlignedConfig = defaults.stayAlignedConfig.copy( + enabled = boolOf(stayAligned["enabled"]) ?: defaults.stayAlignedConfig.enabled, + ), + ) +} + +private fun userOf(root: Map<*, *>): UserConfigData { + val skeleton = section(root, "skeleton") + val stayAligned = section(root, "stayAlignedConfig") + + val poses = LEGACY_POSE_KEYS.mapNotNull { (pose, key) -> + val old = section(stayAligned, key) + if (boolOf(old["enabled"]) != true) return@mapNotNull null + pose to StayAlignedPoseConfig( + recorded = true, + enabled = true, + upperLegAngleInDeg = floatOf(old["upperLegAngleInDeg"]) ?: 0f, + lowerLegAngleInDeg = floatOf(old["lowerLegAngleInDeg"]) ?: 0f, + footAngleInDeg = floatOf(old["footAngleInDeg"]) ?: 0f, + ) + }.toMap() + + val user = UserConfigData(stayAlignedPoses = poses) + val height = (floatOf(skeleton["hmdHeight"]) ?: 0f) - (floatOf(skeleton["floorHeight"]) ?: 0f) + if (height < MIN_USER_HEIGHT) return user + // Proportions are not imported, they are the defaults for the imported height + return withDefaultProportions(user.copy(userHeight = height)) +} + +private fun devicesOf(root: Map<*, *>): DevicesConfigState { + val oldTrackers = section(root, "trackers") + val trackers = oldTrackers.entries.mapNotNull { (name, old) -> + val hardwareId = (name as? String)?.let(::hardwareIdOf) ?: return@mapNotNull null + val config = old as? Map<*, *> ?: return@mapNotNull null + hardwareId to TrackerConfig( + bodyPart = stringOf(config["designation"])?.let { bodyPartOf(it.removePrefix("body:").uppercase()) }, + customName = stringOf(config["customName"])?.takeIf { it.isNotBlank() }, + mountingOrientation = quaternionOf(config["mountingOrientation"]) ?: Quaternion.IDENTITY, + ) + }.toMap() + + val knownDevices = (root["knownDevices"] as? List<*>).orEmpty().mapNotNull { stringOf(it)?.uppercase() }.toSet() + + return DevicesConfigState(allowedUdpDevices = knownDevices, trackers = trackers) +} + +private fun hardwareIdOf(trackerName: String): String? { + UDP_TRACKER_NAME.matchEntire(trackerName)?.let { return udpTrackerHardwareId(it.groupValues[1].uppercase(), it.groupValues[2].toInt()) } + HID_TRACKER_NAME.matchEntire(trackerName)?.let { return hidTrackerHardwareId(it.groupValues[1].uppercase()) } + return null +} + +private fun bodyPartOf(trackerPosition: String): BodyPart? = when (trackerPosition) { + "CHEST" -> BodyPart.UPPER_CHEST + "WAIST" -> BodyPart.LOWER_WAIST + else -> BodyPart.entries.firstOrNull { it != BodyPart.NONE && it.name == trackerPosition } +} + +/** T-pose down does not exist anymore, both T-poses become the side T-pose. */ +private fun armsMountingResetModeOf(value: Any?): ArmsMountingResetMode? = when (stringOf(value)) { + "BACK" -> ArmsMountingResetMode.BACK + "FORWARD" -> ArmsMountingResetMode.FORWARD + "TPOSE_UP", "TPOSE_DOWN" -> ArmsMountingResetMode.SIDE + else -> null +} + +/** Strip older VRM that were too big */ +private fun vrmJsonOf(value: Any?): String? { + val raw = stringOf(value)?.takeIf { it.isNotEmpty() } ?: return null + val gltf = try { + jsonConfig.parseToJsonElement(raw).jsonObject + } catch (_: IllegalArgumentException) { + return null + } + val extensions = gltf["extensions"] as? JsonObject + return buildJsonObject { + if (extensions != null) { + put( + "extensions", + buildJsonObject { + extensions["VRM"]?.let { put("VRM", it) } + extensions["VRMC_vrm"]?.let { put("VRMC_vrm", it) } + }, + ) + } + gltf["extensionsUsed"]?.let { put("extensionsUsed", it) } + gltf["nodes"]?.let { put("nodes", it) } + }.toString() +} + +private fun quaternionOf(value: Any?): Quaternion? { + val map = value as? Map<*, *> ?: return null + return Quaternion( + floatOf(map["w"]) ?: return null, + floatOf(map["x"]) ?: return null, + floatOf(map["y"]) ?: return null, + floatOf(map["z"]) ?: return null, + ) +} + +private fun section(map: Map<*, *>, key: String): Map<*, *> = map[key] as? Map<*, *> ?: emptyMap() + +private fun stringOf(value: Any?): String? = value as? String + +private fun boolOf(value: Any?): Boolean? = when (value) { + is Boolean -> value + is String -> value.toBooleanStrictOrNull() + else -> null +} + +private fun floatOf(value: Any?): Float? = when (value) { + is Number -> value.toFloat() + is String -> value.toFloatOrNull() + else -> null +} + +private fun intOf(value: Any?): Int? = when (value) { + is Number -> value.toInt() + is String -> value.toIntOrNull() + else -> null +} diff --git a/server/core/src/main/java/dev/slimevr/config/module.kt b/server/core/src/main/java/dev/slimevr/config/module.kt index d2c813930..186064b3f 100644 --- a/server/core/src/main/java/dev/slimevr/config/module.kt +++ b/server/core/src/main/java/dev/slimevr/config/module.kt @@ -20,6 +20,7 @@ import solarxr_protocol.rpc.ProfileKind import solarxr_protocol.rpc.ProfileOperationStatus import java.util.UUID +const val GLOBAL_CONFIG_PATH = "global.json" private const val GLOBAL_CONFIG_VERSION = 1 private const val CURRENT_CONSENT_VERSION = 2 @@ -67,7 +68,7 @@ class GlobalConfig( companion object { suspend fun create(scope: CoroutineScope, storage: ConfigStorage): GlobalConfig { - val initialState = loadFileWithBackup(storage, "global.json", GlobalConfigState()) { + val initialState = loadFileWithBackup(storage, GLOBAL_CONFIG_PATH, GlobalConfigState()) { parseAndMigrateGlobalConfig(it) }.let(::withSafeProfileNames) val context = Context.create( @@ -79,12 +80,12 @@ class GlobalConfig( val globalConfig = GlobalConfig(context) globalConfig.startObserving() // Persists defaults filled on load (the generated userId), autosave skips the initial state - storage.write("global.json", jsonConfig.encodeToString(initialState)) + storage.write(GLOBAL_CONFIG_PATH, jsonConfig.encodeToString(initialState)) launchAutosave( scope = scope, state = context.state, storage = storage, - toPath = { "global.json" }, + toPath = { GLOBAL_CONFIG_PATH }, serialize = { jsonConfig.encodeToString(it) }, ) return globalConfig @@ -280,6 +281,7 @@ class AppConfig( companion object { suspend fun create(scope: CoroutineScope, storage: ConfigStorage): AppConfig { + importLegacyConfig(storage) val globalConfig = GlobalConfig.create(scope, storage) val userConfig = UserConfig.create(scope, storage, globalConfig.context.state.value.selectedUserProfile) diff --git a/server/core/src/main/java/dev/slimevr/config/user.kt b/server/core/src/main/java/dev/slimevr/config/user.kt index 160197d93..e7c4cf1d0 100644 --- a/server/core/src/main/java/dev/slimevr/config/user.kt +++ b/server/core/src/main/java/dev/slimevr/config/user.kt @@ -16,6 +16,9 @@ import solarxr_protocol.rpc.StayAlignedRelaxedPose private const val USER_CONFIG_VERSION = 1 private const val DEFAULT_USER_HEIGHT = 1.6f +/** Lowest eye height accepted as the user height. */ +const val MIN_USER_HEIGHT = 0.9f + /** A relaxed pose of the user, used by Stay Aligned to correct moving trackers. */ @Serializable data class StayAlignedPoseConfig( diff --git a/server/core/src/main/java/dev/slimevr/hid/behaviours/register.kt b/server/core/src/main/java/dev/slimevr/hid/behaviours/register.kt index 4b4f01d13..d9934e3de 100644 --- a/server/core/src/main/java/dev/slimevr/hid/behaviours/register.kt +++ b/server/core/src/main/java/dev/slimevr/hid/behaviours/register.kt @@ -7,6 +7,7 @@ import dev.slimevr.hid.HIDReceiverActions import dev.slimevr.logging.AppLogger import dev.slimevr.tracker.Tracker import dev.slimevr.tracker.TrackerActions +import dev.slimevr.tracker.hidTrackerHardwareId import solarxr_protocol.datatypes.DeviceOrigin import solarxr_protocol.datatypes.TrackerStatus import solarxr_protocol.datatypes.hardware_info.ImuType @@ -53,10 +54,11 @@ internal suspend fun registerHidDevice( /** Creates or finds the [Tracker] for an already-registered HID device and links it to [hidId]. */ internal fun ensureHidTracker(receiver: HIDReceiver, hidId: Int, deviceId: Int, imuType: ImuType? = null): Tracker? { val deviceState = receiver.appContext.server.getDevice(deviceId)?.context?.state?.value ?: return null + val hardwareId = hidTrackerHardwareId(deviceState.address) val tracker = receiver.getTracker(hidId) ?: receiver.appContext.server.context.state.value.trackers.values - .find { it.context.state.value.hardwareId == deviceState.address && it.context.state.value.origin == DeviceOrigin.HID } + .find { it.context.state.value.hardwareId == hardwareId && it.context.state.value.origin == DeviceOrigin.HID } ?: run { val trackerId = receiver.appContext.server.nextHandle() val newTracker = Tracker.create( @@ -64,7 +66,7 @@ internal fun ensureHidTracker(receiver: HIDReceiver, hidId: Int, deviceId: Int, id = trackerId, deviceId = deviceState.id, imuType = imuType, - hardwareId = deviceState.address, + hardwareId = hardwareId, origin = DeviceOrigin.HID, appContext = receiver.appContext, ) diff --git a/server/core/src/main/java/dev/slimevr/solarxr/driver/incoming.kt b/server/core/src/main/java/dev/slimevr/solarxr/driver/incoming.kt index 94e4f064b..cda8a82a8 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/driver/incoming.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/driver/incoming.kt @@ -11,6 +11,7 @@ import dev.slimevr.solarxr.toQuaternion import dev.slimevr.solarxr.toVector3 import dev.slimevr.tracker.Tracker import dev.slimevr.tracker.TrackerActions +import dev.slimevr.tracker.driverTrackerHardwareId import dev.slimevr.util.inFloatingSeconds import dev.slimevr.util.timeSource import io.github.axisangles.ktmath.Quaternion @@ -100,9 +101,10 @@ class DriverIncomingTrackersBehaviour( return@onDriverMessage } val hardwareId = req.hardwareIdentifier + val trackerHardwareId = driverTrackerHardwareId(hardwareId) val existing = server.context.state.value.trackers.values - .find { it.context.state.value.hardwareId == hardwareId } + .find { it.context.state.value.hardwareId == trackerHardwareId } if (existing != null) { val trackerState = existing.context.state.value // Tracker is in use by another driver right now @@ -149,7 +151,7 @@ class DriverIncomingTrackersBehaviour( intendedBodyPart = req.bodyPart, intendedBoneOffset = offset?.boneOffset, deviceId = deviceId, - hardwareId = hardwareId, + hardwareId = trackerHardwareId, origin = DeviceOrigin.DRIVER, driverName = driverName, appContext = appContext, diff --git a/server/core/src/main/java/dev/slimevr/solarxr/rpc/skeleton-proportions.kt b/server/core/src/main/java/dev/slimevr/solarxr/rpc/skeleton-proportions.kt index 1dca59799..96aedbe6b 100644 --- a/server/core/src/main/java/dev/slimevr/solarxr/rpc/skeleton-proportions.kt +++ b/server/core/src/main/java/dev/slimevr/solarxr/rpc/skeleton-proportions.kt @@ -1,5 +1,6 @@ package dev.slimevr.solarxr.rpc +import dev.slimevr.config.MIN_USER_HEIGHT import dev.slimevr.config.UserConfig import dev.slimevr.config.UserConfigActions import dev.slimevr.config.withDefaultProportions @@ -29,8 +30,6 @@ import solarxr_protocol.rpc.SkeletonProportionsRequest import solarxr_protocol.rpc.SkeletonProportionsResetAllRequest import solarxr_protocol.rpc.SkeletonProportionsResponse -private const val MIN_HEIGHT = 0.9f - class SkeletonProportionsBehaviour( private val userConfig: UserConfig, private val skeleton: Skeleton, @@ -70,7 +69,7 @@ class SkeletonProportionsBehaviour( val headHeight = req.headHeight ?: return@on val floorHeight = req.floorHeight ?: 0f val height = headHeight - floorHeight - if (height >= MIN_HEIGHT) { + if (height >= MIN_USER_HEIGHT) { userConfig.context.dispatch( UserConfigActions.Update { withUserHeight(this, height) }, ) @@ -80,7 +79,7 @@ class SkeletonProportionsBehaviour( receiver.rpcDispatcher.on { val height = userConfig.context.state.value.data.userHeight - if (height >= MIN_HEIGHT) { + if (height >= MIN_USER_HEIGHT) { userConfig.context.dispatch(UserConfigActions.Update { withDefaultProportions(this) }) } }.launchIn(receiver.context.scope) diff --git a/server/core/src/main/java/dev/slimevr/tracker/hardware-id.kt b/server/core/src/main/java/dev/slimevr/tracker/hardware-id.kt new file mode 100644 index 000000000..31d8994db --- /dev/null +++ b/server/core/src/main/java/dev/slimevr/tracker/hardware-id.kt @@ -0,0 +1,7 @@ +package dev.slimevr.tracker + +fun udpTrackerHardwareId(deviceHardwareId: String, sensorId: Int): String = "udp:$deviceHardwareId:$sensorId" + +fun hidTrackerHardwareId(address: String): String = "hid:$address" + +fun driverTrackerHardwareId(hardwareIdentifier: String): String = "driver:$hardwareIdentifier" diff --git a/server/core/src/main/java/dev/slimevr/udp/behaviours.kt b/server/core/src/main/java/dev/slimevr/udp/behaviours.kt index 30b14373e..8685d2cea 100644 --- a/server/core/src/main/java/dev/slimevr/udp/behaviours.kt +++ b/server/core/src/main/java/dev/slimevr/udp/behaviours.kt @@ -7,6 +7,7 @@ import dev.slimevr.device.DeviceActions import dev.slimevr.logging.AppLogger import dev.slimevr.tracker.Tracker import dev.slimevr.tracker.TrackerActions +import dev.slimevr.tracker.udpTrackerHardwareId import dev.slimevr.util.udpHardwareId import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 @@ -43,7 +44,7 @@ fun getCorrectedAcceleration(acceleration: Vector3, protocolVersion: Int) = if ( internal fun assignTracker(receiver: UDPConnection, device: Device, info: SensorInfo): Tracker { val deviceState = device.context.state.value val deviceHardwareId = deviceState.hardwareId ?: udpHardwareId(deviceState.macAddress, deviceState.address) - val hardwareId = "$deviceHardwareId:${info.sensorId}" + val hardwareId = udpTrackerHardwareId(deviceHardwareId, info.sensorId) val existingTracker = receiver.appContext.server.context.state.value.trackers.values .find { t -> t.context.state.value.deviceId == deviceState.id && t.context.state.value.hardwareId == hardwareId } diff --git a/server/core/src/test/java/dev/slimevr/config/DevicesConfigMigrationTest.kt b/server/core/src/test/java/dev/slimevr/config/DevicesConfigMigrationTest.kt new file mode 100644 index 000000000..272fa0542 --- /dev/null +++ b/server/core/src/test/java/dev/slimevr/config/DevicesConfigMigrationTest.kt @@ -0,0 +1,45 @@ +package dev.slimevr.config + +import kotlinx.coroutines.test.runTest +import solarxr_protocol.datatypes.BodyPart +import kotlin.test.Test +import kotlin.test.assertEquals + +class DevicesConfigMigrationTest { + @Test + fun `version 1 tracker ids get the prefix of their origin`() = runTest { + val storage = MemoryStorage() + storage.files[DEVICES_CONFIG_PATH] = """ + { + "version": 1, + "allowedUdpDevices": ["AA:BB:CC:DD:EE:01"], + "trackers": { + "AA:BB:CC:DD:EE:01:0": { "bodyPart": "HIP" }, + "192.168.1.20:1": { "bodyPart": "LEFT_FOOT" }, + "A1B2C3D4E5F6": { "bodyPart": "RIGHT_FOOT" }, + "0000A1B2C3D4E5F6": { "bodyPart": "LEFT_HAND" }, + "LHR-1A2B3C4D": { "bodyPart": "LOWER_CHEST" }, + "vmc:tracker:abc": { "bodyPart": "HEAD" }, + "vrcosc:vrsystem:head": { "bodyPart": "NECK" } + } + } + """.trimIndent() + + val devices = AppConfig.create(backgroundScope, storage).devices.context.state.value + + assertEquals( + mapOf( + "udp:AA:BB:CC:DD:EE:01:0" to BodyPart.HIP, + "udp:192.168.1.20:1" to BodyPart.LEFT_FOOT, + "hid:A1B2C3D4E5F6" to BodyPart.RIGHT_FOOT, + "hid:0000A1B2C3D4E5F6" to BodyPart.LEFT_HAND, + "driver:LHR-1A2B3C4D" to BodyPart.LOWER_CHEST, + "vmc:tracker:abc" to BodyPart.HEAD, + "vrcosc:vrsystem:head" to BodyPart.NECK, + ), + devices.trackers.mapValues { it.value.bodyPart }, + ) + assertEquals(setOf("AA:BB:CC:DD:EE:01"), devices.allowedUdpDevices) + assertEquals(2, devices.version) + } +} diff --git a/server/core/src/test/java/dev/slimevr/config/LegacyConfigTest.kt b/server/core/src/test/java/dev/slimevr/config/LegacyConfigTest.kt new file mode 100644 index 000000000..a022ae22f --- /dev/null +++ b/server/core/src/test/java/dev/slimevr/config/LegacyConfigTest.kt @@ -0,0 +1,304 @@ +package dev.slimevr.config + +import dev.slimevr.skeleton.computeAllDefaultProportionsByBone +import io.github.axisangles.ktmath.Quaternion +import kotlinx.coroutines.test.runTest +import solarxr_protocol.datatypes.BodyPart +import solarxr_protocol.rpc.ArmsMountingResetMode +import solarxr_protocol.rpc.StayAlignedRelaxedPose +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +private val LEGACY_CONFIG = """ +--- +server: + trackerPort: 6969 + useMagnetometerOnAllTrackers: true +filters: + type: "prediction" + amount: 1.0 +vmc: + enabled: true + portIn: 39541 + portOut: 39538 + address: "192.168.1.20" + anchorHip: false + vrmJson: "{\"nodes\":[]}" + mirrorTracking: true +skeleton: + toggles: + floorClip: false + selfLocalization: true + toeSnap: true + enforceConstraints: false + extendedSpine: false + values: + kneeTrackerAnkleAveraging: 0.6 + kneeAnkleAveraging: 0.2 + offsets: + chestLength: 0.42 + hmdHeight: 1.72 + floorHeight: 0.02 +legTweaks: + correctionStrength: 0.8 +tapDetection: + yawResetDelay: 0.4 + fullResetDelay: 2.0 + mountingResetDelay: 1.0 + yawResetEnabled: false + fullResetEnabled: true + mountingResetEnabled: true + yawResetTracker: "CHEST" + mountingResetTracker: "WAIST" + fullResetTracker: "LEFT_UPPER_LEG" + setupMode: false + yawResetTaps: 4 + fullResetTaps: 3 + mountingResetTaps: 5 + numberTrackersOverThreshold: 2 +resetsConfig: + resetMountingFeet: true + mode: "TPOSE_DOWN" + yawResetSmoothTime: 0.5 + saveMountingReset: true + resetHmdPitch: true + lastMountingMethod: "AUTOMATIC" +stayAlignedConfig: + enabled: true + standingRelaxedPose: + enabled: true + upperLegAngleInDeg: 4.5 + lowerLegAngleInDeg: -2.0 + footAngleInDeg: 10.0 + sittingRelaxedPose: + enabled: false + upperLegAngleInDeg: 0.0 + lowerLegAngleInDeg: 0.0 + footAngleInDeg: 0.0 + flatRelaxedPose: + enabled: false + upperLegAngleInDeg: 0.0 + lowerLegAngleInDeg: 0.0 + footAngleInDeg: 0.0 + setupComplete: true +hidConfig: + trackersOverHID: true +trackers: + udp://AA:BB:CC:DD:EE:01/0: + customName: "Chest" + designation: "body:chest" + hide: false + adjustment: null + mountingOrientation: + x: 0.0 + "y": 1.0 + z: -0.0 + w: -4.371139E-8 + mountingResetOrientation: + x: 0.0 + "y": 0.3 + z: 0.0 + w: 0.95 + allowDriftCompensation: true + shouldHaveMagEnabled: null + udp://AA:BB:CC:DD:EE:01/1: + customName: null + designation: "body:waist" + hide: false + adjustment: null + mountingOrientation: null + mountingResetOrientation: null + allowDriftCompensation: true + shouldHaveMagEnabled: null + udp://AA:BB:CC:DD:EE:02/0: + designation: "body:upper_chest" + "123456ABCDEF/0": + designation: "body:left_foot" + ABCDEF123456/0: + customName: null + designation: null + mountingOrientation: null + HMD: + designation: "body:head" + PICO_CONTROLLER_LEFT: + designation: "body:left_hand" +knownDevices: +- "AA:BB:CC:DD:EE:01" +- "aa:bb:cc:dd:ee:02" +velocityConfig: + sendDerivedVelocity: true +vrcOSC: + enabled: true +overlay: + mirrored: false + visible: false +modelVersion: "15" +""".trimIndent() + +class LegacyConfigTest { + private val migration = assertNotNull(migrateLegacyConfig(LEGACY_CONFIG)) + + @Test + fun `listed settings are imported`() { + val settings = migration.settings + assertTrue(settings.trackersConfig.globalMagEnabled) + assertTrue(settings.hidConfig.trackersOverHid) + assertTrue(settings.stayAlignedConfig.enabled) + + val toggles = settings.skeletonConfig.toggles + assertFalse(toggles.floorClip) + assertTrue(toggles.mocapMode) + assertTrue(toggles.toeSnap) + assertFalse(toggles.enforceConstraints) + assertEquals(SkeletonTogglesConfig().skatingCorrection, toggles.skatingCorrection) + assertEquals(SkeletonTogglesConfig().footPlant, toggles.footPlant) + assertEquals(0.6f, settings.skeletonConfig.ratios.interpolateUpperLegsTwistWithLowerLegs) + + val resets = settings.resetsConfig + assertTrue(resets.resetMountingFeet) + assertEquals(ArmsMountingResetMode.SIDE, resets.armsMountingResetMode) + assertEquals(0.5f, resets.yawResetSmoothTime) + assertTrue(resets.saveMountingReset) + assertTrue(resets.resetHmdAttitude) + + val tap = settings.tapDetectionConfig + assertEquals(0.4f, tap.yawResetDelay) + assertEquals(2.0f, tap.fullResetDelay) + assertEquals(1.0f, tap.mountingResetDelay) + assertFalse(tap.yawResetEnabled) + assertEquals(BodyPart.UPPER_CHEST, tap.yawResetBodyPart) + assertEquals(BodyPart.LOWER_WAIST, tap.mountingResetBodyPart) + assertEquals(BodyPart.LEFT_UPPER_LEG, tap.fullResetBodyPart) + assertEquals(4, tap.yawResetTaps) + assertEquals(5, tap.mountingResetTaps) + assertEquals(2, tap.numberTrackersOverThreshold) + + val vmc = settings.vmcConfig + assertTrue(vmc.enabled) + assertEquals(39541, vmc.portIn) + assertEquals(39538, vmc.portOut) + assertEquals("192.168.1.20", vmc.address) + assertFalse(vmc.anchorAtHips) + assertTrue(vmc.mirrorTracking) + assertEquals("{\"nodes\":[]}", vmc.vrmJson) + } + + @Test + fun `unlisted settings keep the defaults`() { + val defaults = SettingsConfigState() + val settings = migration.settings + assertEquals(defaults.skeletonConfig.ratios.copy(interpolateUpperLegsTwistWithLowerLegs = 0.6f), settings.skeletonConfig.ratios) + assertEquals(defaults.driverConfig, settings.driverConfig) + assertEquals(defaults.vrcOscConfig, settings.vrcOscConfig) + assertEquals(defaults.boneRoutingConfig, settings.boneRoutingConfig) + assertEquals(defaults.trackersConfig.timeoutDelay, settings.trackersConfig.timeoutDelay) + assertEquals(defaults.resetsConfig.mountingMethod, settings.resetsConfig.mountingMethod) + } + + @Test + fun `an uncalibrated height keeps the default user`() { + val yaml = LEGACY_CONFIG.replace("hmdHeight: 1.72", "hmdHeight: -1.0").replace("floorHeight: 0.02", "floorHeight: 0.0") + val user = assertNotNull(migrateLegacyConfig(yaml)).user + assertEquals(UserConfigData().userHeight, user.userHeight) + assertEquals(UserConfigData().proportions, user.proportions) + } + + @Test + fun `a null vrm is not imported`() { + val yaml = LEGACY_CONFIG.replace("vrmJson: \"{\\\"nodes\\\":[]}\"", "vrmJson: null") + assertNull(assertNotNull(migrateLegacyConfig(yaml)).settings.vmcConfig.vrmJson) + } + + @Test + fun `user height is the old hmd height above the floor`() { + // hmdHeight 1.72 minus floorHeight 0.02 in the fixture + assertEquals(1.70f, migration.user.userHeight, 0.0001f) + } + + @Test + fun `proportions are the defaults for the imported height`() { + val proportions = migration.user.proportions + assertEquals(computeAllDefaultProportionsByBone(1.70f), proportions) + assertNotEquals(UserConfigData().proportions, proportions) + } + + @Test + fun `recorded stay aligned poses are imported`() { + val poses = migration.user.stayAlignedPoses + assertEquals(setOf(StayAlignedRelaxedPose.STANDING), poses.keys) + assertEquals(StayAlignedPoseConfig(recorded = true, enabled = true, upperLegAngleInDeg = 4.5f, lowerLegAngleInDeg = -2.0f, footAngleInDeg = 10.0f), poses[StayAlignedRelaxedPose.STANDING]) + } + + @Test + fun `udp and hid trackers map to their hardware ids`() { + val trackers = migration.devices.trackers + assertEquals(setOf("udp:AA:BB:CC:DD:EE:01:0", "udp:AA:BB:CC:DD:EE:01:1", "udp:AA:BB:CC:DD:EE:02:0", "hid:123456ABCDEF", "hid:ABCDEF123456"), trackers.keys) + + val chest = trackers.getValue("udp:AA:BB:CC:DD:EE:01:0") + assertEquals(BodyPart.UPPER_CHEST, chest.bodyPart) + assertEquals("Chest", chest.customName) + assertEquals(Quaternion(-4.371139E-8f, 0f, 1f, 0f), chest.mountingOrientation) + assertNull(chest.mountingResetOrientation) + assertNull(chest.magEnabled) + + assertEquals(BodyPart.LOWER_WAIST, trackers.getValue("udp:AA:BB:CC:DD:EE:01:1").bodyPart) + assertEquals(Quaternion.IDENTITY, trackers.getValue("udp:AA:BB:CC:DD:EE:01:1").mountingOrientation) + assertEquals(BodyPart.UPPER_CHEST, trackers.getValue("udp:AA:BB:CC:DD:EE:02:0").bodyPart) + assertEquals(BodyPart.LEFT_FOOT, trackers.getValue("hid:123456ABCDEF").bodyPart) + assertEquals(TrackerConfig(), trackers.getValue("hid:ABCDEF123456")) + assertEquals(setOf("AA:BB:CC:DD:EE:01", "AA:BB:CC:DD:EE:02"), migration.devices.allowedUdpDevices) + } + + @Test + fun `a whole glTF JSON is trimmed to what the GUI sends`() { + val gltf = """{"asset":{"version":"2.0"},"materials":[{"name":"skin"}],"extensionsUsed":["VRMC_vrm"],"extensions":{"VRMC_vrm":{"specVersion":"1.0","humanoid":{"humanBones":{"hips":{"node":0}}}},"KHR_materials_unlit":{}},"nodes":[{"translation":[0.0,1.0,0.0]}]}""" + val yaml = LEGACY_CONFIG.replace("vrmJson: \"{\\\"nodes\\\":[]}\"", "vrmJson: '$gltf'") + val vrmJson = assertNotNull(assertNotNull(migrateLegacyConfig(yaml)).settings.vmcConfig.vrmJson) + + assertEquals( + """{"extensions":{"VRMC_vrm":{"specVersion":"1.0","humanoid":{"humanBones":{"hips":{"node":0}}}}},"extensionsUsed":["VRMC_vrm"],"nodes":[{"translation":[0.0,1.0,0.0]}]}""", + vrmJson, + ) + } + + @Test + fun `a config larger than 3 MB is still read`() { + val padding = "x".repeat(4 * 1024 * 1024) + val yaml = LEGACY_CONFIG.replace("vrmJson: \"{\\\"nodes\\\":[]}\"", "vrmJson: '{\"nodes\":[],\"padding\":\"$padding\"}'") + assertEquals("{\"nodes\":[]}", assertNotNull(migrateLegacyConfig(yaml)).settings.vmcConfig.vrmJson) + } + + @Test + fun `configs older than version 14 are skipped`() { + assertNull(migrateLegacyConfig(LEGACY_CONFIG.replace("modelVersion: \"15\"", "modelVersion: \"13\""))) + assertNull(migrateLegacyConfig(LEGACY_CONFIG.replace("\nmodelVersion: \"15\"", ""))) + } + + @Test + fun `first start loads the imported config`() = runTest { + val storage = MemoryStorage() + storage.files[LEGACY_CONFIG_PATH] = LEGACY_CONFIG + val config = AppConfig.create(backgroundScope, storage) + + assertEquals(migration.settings, config.settings.context.state.value.data) + assertEquals(migration.user, config.userConfig.context.state.value.data) + assertEquals(migration.devices, config.devices.context.state.value) + assertEquals(LEGACY_CONFIG, storage.files[LEGACY_CONFIG_PATH]) + } + + @Test + fun `an existing config is never overwritten by the import`() = runTest { + val storage = MemoryStorage() + AppConfig.create(backgroundScope, storage) + storage.files[LEGACY_CONFIG_PATH] = LEGACY_CONFIG + val config = AppConfig.create(backgroundScope, storage) + + assertEquals(SettingsConfigState(), config.settings.context.state.value.data) + assertEquals(DevicesConfigState(), config.devices.context.state.value) + } +} diff --git a/server/core/src/test/java/dev/slimevr/solarxr/SettingsResetTest.kt b/server/core/src/test/java/dev/slimevr/solarxr/SettingsResetTest.kt index a53c5641a..74184fa0d 100644 --- a/server/core/src/test/java/dev/slimevr/solarxr/SettingsResetTest.kt +++ b/server/core/src/test/java/dev/slimevr/solarxr/SettingsResetTest.kt @@ -15,6 +15,7 @@ import dev.slimevr.context.Context import dev.slimevr.device.Device import dev.slimevr.solarxr.rpc.SettingsResetBehaviour import dev.slimevr.tracker.TrackerActions +import dev.slimevr.tracker.udpTrackerHardwareId import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestScope @@ -96,10 +97,11 @@ class SettingsResetTest { protocolVersion = 21, ) server.context.dispatch(VRServerActions.NewDevice(device.context.state.value.id, device)) + val hardwareId = udpTrackerHardwareId(mac, 0) val tracker = buildTestTracker(server.context.scope, bridge.appContext, config.settings, server.nextHandle()) - tracker.context.dispatch(TrackerActions.Update { copy(deviceId = device.context.state.value.id, hardwareId = "$mac:0") }) + tracker.context.dispatch(TrackerActions.Update { copy(deviceId = device.context.state.value.id, hardwareId = hardwareId) }) server.context.dispatch(VRServerActions.NewTracker(tracker.context.state.value.id, tracker)) - config.devices.context.dispatch(DevicesConfigActions.UpdateTracker("$mac:0") { copy(customName = "Left foot") }) + config.devices.context.dispatch(DevicesConfigActions.UpdateTracker(hardwareId) { copy(customName = "Left foot") }) config.globalConfig.context.dispatch( GlobalConfigActions.SetErrorReporting( changeConsent(config.globalConfig.context.state.value.errorReporting, ErrorReportingConsent.ALLOWED), diff --git a/server/core/src/test/java/dev/slimevr/udp/ForgetDeviceTest.kt b/server/core/src/test/java/dev/slimevr/udp/ForgetDeviceTest.kt index fc9b5a665..5124adc25 100644 --- a/server/core/src/test/java/dev/slimevr/udp/ForgetDeviceTest.kt +++ b/server/core/src/test/java/dev/slimevr/udp/ForgetDeviceTest.kt @@ -15,6 +15,7 @@ import dev.slimevr.skeleton.Skeleton import dev.slimevr.skeleton.SkeletonActions import dev.slimevr.tracker.Tracker import dev.slimevr.tracker.TrackerActions +import dev.slimevr.tracker.udpTrackerHardwareId import io.github.axisangles.ktmath.Quaternion import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -75,7 +76,7 @@ private fun addTracker( status = status, origin = device.context.state.value.origin, ) - val hardwareId = "$MAC:$sensorId" + val hardwareId = udpTrackerHardwareId(MAC, sensorId) tracker.context.dispatch(TrackerActions.Update { copy(deviceId = device.context.state.value.id, hardwareId = hardwareId) }) appContext.server.context.dispatch(VRServerActions.NewTracker(id, tracker)) appContext.config.devices.context.dispatch(DevicesConfigActions.UpdateTracker(hardwareId) { copy(bodyPart = bodyPart) }) @@ -110,7 +111,7 @@ class ForgetDeviceTest { trackers.forEach { assertFalse(it.context.scope.isActive) } assertTrue(hidDevice.context.scope.isActive) assertFalse(MAC in devices.context.state.value.allowedUdpDevices) - assertEquals(setOf("$MAC:5"), devices.context.state.value.trackers.keys) + assertEquals(setOf(udpTrackerHardwareId(MAC, 5)), devices.context.state.value.trackers.keys) assertEquals(false, appContext.skeleton.context.state.value.boneInputs[BodyPart.UPPER_CHEST]?.isRotationActive) } }