From 853d112737bddf8b6d862a902e308b2f44cd0224 Mon Sep 17 00:00:00 2001 From: Jabberrock Date: Mon, 28 Apr 2025 18:09:53 -0700 Subject: [PATCH] Stay Aligned Keeps your trackers aligned by slowly adjusting the yaw of your trackers to correct for drift. Every tick, Stay Aligned adjusts the yaw of one tracker. It looks at the player's current pose, and adjusts the yaw of the tracker by a tiny amount, in the direction which is closest to the relaxed pose that the player set up. Over time, this has the effect of keeping all the trackers in a human-like pose. --- gui/public/i18n/en/translation.ftl | 24 + gui/src/components/commons/NumberSelector.tsx | 2 +- .../components/settings/SettingsSidebar.tsx | 3 + .../settings/pages/GeneralSettings.tsx | 22 +- .../pages/components/StayAlignedSettings.tsx | 153 ++++++ .../components/stay-aligned/RelaxedPose.tsx | 439 ++++++++++++++++++ .../stay-aligned/StayAlignedInfo.tsx | 53 +++ gui/src/components/tracker/TrackersTable.tsx | 13 + .../widgets/IMUVisualizerWidget.tsx | 10 + gui/src/hooks/datafeed-config.ts | 2 + gui/src/maths/angle.ts | 4 + gui/src/maths/quaternion.ts | 3 +- gui/src/store/app-store.ts | 6 + .../dev/slimevr/config/StayAlignedConfig.kt | 49 ++ .../config/StayAlignedRelaxedPoseConfig.kt | 25 + .../main/java/dev/slimevr/config/VRConfig.kt | 2 + .../src/main/java/dev/slimevr/math/Angle.kt | 81 ++++ .../java/dev/slimevr/math/AngleAverage.kt | 38 ++ .../main/java/dev/slimevr/math/AngleErrors.kt | 15 + .../protocol/datafeed/DataFeedBuilder.java | 9 + .../datafeed/DataFeedBuilderKotlin.kt | 42 ++ .../protocol/datafeed/DataFeedHandler.java | 15 +- .../dev/slimevr/protocol/rpc/RPCHandler.kt | 103 ++++ .../rpc/settings/RPCSettingsBuilder.java | 6 +- .../rpc/settings/RPCSettingsBuilderKotlin.kt | 32 ++ .../rpc/settings/RPCSettingsHandler.kt | 27 +- .../processor/skeleton/HumanSkeleton.kt | 13 + .../processor/stayaligned/StayAligned.kt | 58 +++ .../stayaligned/StayAlignedDefaults.kt | 47 ++ .../stayaligned/adjust/AdjustTrackerYaw.kt | 183 ++++++++ .../stayaligned/adjust/CenterErrorVisitor.kt | 92 ++++ .../processor/stayaligned/adjust/CenterYaw.kt | 67 +++ .../stayaligned/adjust/LockedErrorVisitor.kt | 144 ++++++ .../adjust/NeighborErrorVisitor.kt | 164 +++++++ .../stayaligned/adjust/TrackerYaw.kt | 59 +++ .../processor/stayaligned/poses/PlayerPose.kt | 92 ++++ .../stayaligned/poses/RelaxedPose.kt | 111 +++++ .../stayaligned/poses/TrackerPose.kt | 61 +++ .../stayaligned/trackers/RestDetector.kt | 95 ++++ .../processor/stayaligned/trackers/Side.kt | 6 + .../trackers/StayAlignedTrackerState.kt | 43 ++ .../stayaligned/trackers/TrackerSkeleton.kt | 415 +++++++++++++++++ .../stayaligned/trackers/YawErrors.kt | 12 + .../dev/slimevr/tracking/trackers/Tracker.kt | 46 +- .../tracking/trackers/TrackerResetsHandler.kt | 6 + .../io/github/axisangles/ktmath/Quaternion.kt | 66 +++ .../io/github/axisangles/ktmath/Vector3.kt | 3 + .../axisangles/ktmath/QuaternionTest.kt | 18 + solarxr-protocol | 2 +- 49 files changed, 2964 insertions(+), 17 deletions(-) create mode 100644 gui/src/components/settings/pages/components/StayAlignedSettings.tsx create mode 100644 gui/src/components/stay-aligned/RelaxedPose.tsx create mode 100644 gui/src/components/stay-aligned/StayAlignedInfo.tsx create mode 100644 server/core/src/main/java/dev/slimevr/config/StayAlignedConfig.kt create mode 100644 server/core/src/main/java/dev/slimevr/config/StayAlignedRelaxedPoseConfig.kt create mode 100644 server/core/src/main/java/dev/slimevr/math/Angle.kt create mode 100644 server/core/src/main/java/dev/slimevr/math/AngleAverage.kt create mode 100644 server/core/src/main/java/dev/slimevr/math/AngleErrors.kt create mode 100644 server/core/src/main/java/dev/slimevr/protocol/datafeed/DataFeedBuilderKotlin.kt create mode 100644 server/core/src/main/java/dev/slimevr/protocol/rpc/settings/RPCSettingsBuilderKotlin.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/StayAligned.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/StayAlignedDefaults.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/adjust/AdjustTrackerYaw.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/adjust/CenterErrorVisitor.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/adjust/CenterYaw.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/adjust/LockedErrorVisitor.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/adjust/NeighborErrorVisitor.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/adjust/TrackerYaw.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/poses/PlayerPose.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/poses/RelaxedPose.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/poses/TrackerPose.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/trackers/RestDetector.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/trackers/Side.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/trackers/StayAlignedTrackerState.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/trackers/TrackerSkeleton.kt create mode 100644 server/core/src/main/java/dev/slimevr/tracking/processor/stayaligned/trackers/YawErrors.kt diff --git a/gui/public/i18n/en/translation.ftl b/gui/public/i18n/en/translation.ftl index eb41704bc..dd200d8e4 100644 --- a/gui/public/i18n/en/translation.ftl +++ b/gui/public/i18n/en/translation.ftl @@ -293,6 +293,7 @@ widget-imu_visualizer-rotation_raw = Raw rotation widget-imu_visualizer-rotation_preview = Preview rotation widget-imu_visualizer-acceleration = Acceleration widget-imu_visualizer-position = Position +widget-imu_visualizer-stay_aligned = Stay Aligned ## Widget: Skeleton Visualizer widget-skeleton_visualizer-preview = Skeleton preview @@ -317,6 +318,7 @@ tracker-table-column-temperature = Temp. °C tracker-table-column-linear-acceleration = Accel. X/Y/Z tracker-table-column-rotation = Rotation X/Y/Z tracker-table-column-position = Position X/Y/Z +tracker-table-column-stay_aligned = Stay Aligned tracker-table-column-url = URL ## Tracker rotation @@ -447,6 +449,7 @@ mounting_selection_menu-close = Close settings-sidebar-title = Settings settings-sidebar-general = General settings-sidebar-tracker_mechanics = Tracker mechanics +settings-sidebar-stay_aligned = Stay Aligned settings-sidebar-fk_settings = Tracking settings settings-sidebar-gesture_control = Gesture control settings-sidebar-interface = Interface @@ -539,6 +542,27 @@ settings-general-tracker_mechanics-use_mag_on_all_trackers-description = Can be disabled per tracker in the tracker's settings. Please don't shutdown any of the trackers while toggling this! settings-general-tracker_mechanics-use_mag_on_all_trackers-label = Use magnetometer on trackers +settings-stay_aligned = Stay Aligned +settings-stay_aligned-description = Stay Aligned reduces drift by gradually adjusting your trackers to match your most common poses. +settings-stay_aligned-warnings-drift_compensation = ⚠ Please turn off Drift Compensation! Drift Compensation will conflict with Stay Aligned. +settings-stay_aligned-enabled-label = Enabled +settings-stay_aligned-extra_yaw_correction-label = Extra correction for low quality IMUs (e.g. BMI160, MPU60XX) +settings-stay_aligned-hide_yaw_correction-label = Hide correction (for comparison) +settings-stay_aligned-general-label = General +settings-stay_aligned-relaxed_poses-label = Relaxed Poses +settings-stay_aligned-relaxed_poses-standing = Standing +settings-stay_aligned-relaxed_poses-sitting = Sitting in chair +settings-stay_aligned-relaxed_poses-flat = Sitting on floor +settings-stay_aligned-relaxed_poses-current_angles = Current angles +settings-stay_aligned-relaxed_poses-upper_leg_angle = Thigh +settings-stay_aligned-relaxed_poses-lower_leg_angle = Ankle +settings-stay_aligned-relaxed_poses-foot_angle = Foot +settings-stay_aligned-relaxed_poses-detect_pose = Detect pose +settings-stay_aligned-relaxed_poses-reset_pose = Reset pose +settings-stay_aligned-relaxed_poses-outwards = {$angle} outwards +settings-stay_aligned-relaxed_poses-inwards = {$angle} inwards +settings-stay_aligned-relaxed_poses-disabled = Not enabled + ## FK/Tracking settings settings-general-fk_settings = Tracking settings diff --git a/gui/src/components/commons/NumberSelector.tsx b/gui/src/components/commons/NumberSelector.tsx index a21d35634..5e2eb022d 100644 --- a/gui/src/components/commons/NumberSelector.tsx +++ b/gui/src/components/commons/NumberSelector.tsx @@ -83,7 +83,7 @@ export function NumberSelector({ - -
+
{valueLabelFormat ? valueLabelFormat(value) : value}
diff --git a/gui/src/components/settings/SettingsSidebar.tsx b/gui/src/components/settings/SettingsSidebar.tsx index 97325b062..ffb09640a 100644 --- a/gui/src/components/settings/SettingsSidebar.tsx +++ b/gui/src/components/settings/SettingsSidebar.tsx @@ -57,6 +57,9 @@ export function SettingsSidebar() { SteamVR + + {l10n.getString('settings-sidebar-stay_aligned')} + {l10n.getString('settings-sidebar-tracker_mechanics')} diff --git a/gui/src/components/settings/pages/GeneralSettings.tsx b/gui/src/components/settings/pages/GeneralSettings.tsx index 5b0bb6e32..267b9c7da 100644 --- a/gui/src/components/settings/pages/GeneralSettings.tsx +++ b/gui/src/components/settings/pages/GeneralSettings.tsx @@ -33,8 +33,15 @@ import { import { HandsWarningModal } from '@/components/settings/HandsWarningModal'; import { MagnetometerToggleSetting } from './MagnetometerToggleSetting'; import { DriftCompensationModal } from '@/components/settings/DriftCompensationModal'; +import { + defaultStayAlignedSettings, + StayAlignedSettings, + StayAlignedSettingsForm, + serializeStayAlignedSettings, + deserializeStayAlignedSettings, +} from './components/StayAlignedSettings'; -interface SettingsForm { +export type SettingsForm = { trackers: { waist: boolean; chest: boolean; @@ -103,7 +110,8 @@ interface SettingsForm { saveMountingReset: boolean; resetHmdPitch: boolean; }; -} + stayAligned: StayAlignedSettingsForm; +}; const defaultValues: SettingsForm = { trackers: { @@ -169,6 +177,7 @@ const defaultValues: SettingsForm = { saveMountingReset: false, resetHmdPitch: false, }, + stayAligned: defaultStayAlignedSettings, }; export function GeneralSettings() { @@ -297,6 +306,8 @@ export function GeneralSettings() { driftCompensation.maxResets = values.driftCompensation.maxResets; settings.driftCompensation = driftCompensation; + settings.stayAligned = serializeStayAlignedSettings(values.stayAligned); + if (values.resetsSettings) { const resetsSettings = new ResetsSettingsT(); resetsSettings.resetMountingFeet = @@ -420,6 +431,12 @@ export function GeneralSettings() { formData.resetsSettings = settings.resetsSettings; } + if (settings.stayAligned) { + formData.stayAligned = deserializeStayAlignedSettings( + settings.stayAligned + ); + } + reset({ ...getValues(), ...formData }); }); @@ -612,6 +629,7 @@ export function GeneralSettings() {
+ } id="mechanics"> <> diff --git a/gui/src/components/settings/pages/components/StayAlignedSettings.tsx b/gui/src/components/settings/pages/components/StayAlignedSettings.tsx new file mode 100644 index 000000000..516671c54 --- /dev/null +++ b/gui/src/components/settings/pages/components/StayAlignedSettings.tsx @@ -0,0 +1,153 @@ +import { Control } from 'react-hook-form'; +import { StayAlignedSettingsT } from 'solarxr-protocol'; +import { SettingsForm } from '@/components/settings/pages/GeneralSettings'; +import { Button } from '@/components/commons/Button'; +import { CheckBox } from '@/components/commons/Checkbox'; +import { WrenchIcon } from '@/components/commons/icon/WrenchIcons'; +import { Typography } from '@/components/commons/Typography'; +import { SettingsPagePaneLayout } from '@/components/settings/SettingsPageLayout'; +import { useLocalization } from '@fluent/react'; +import { useConfig } from '@/hooks/config'; +import { + RelaxedPosesSettings, + RelaxedPosesSummary, +} from '@/components/stay-aligned/RelaxedPose'; + +export type StayAlignedSettingsForm = { + enabled: boolean; + extraYawCorrection: boolean; + hideYawCorrection: boolean; + standingEnabled: boolean; + standingUpperLegAngle: number; + standingLowerLegAngle: number; + standingFootAngle: number; + sittingEnabled: boolean; + sittingUpperLegAngle: number; + sittingLowerLegAngle: number; + sittingFootAngle: number; + flatEnabled: boolean; + flatUpperLegAngle: number; + flatLowerLegAngle: number; + flatFootAngle: number; +}; + +export const defaultStayAlignedSettings: StayAlignedSettingsForm = { + enabled: false, + extraYawCorrection: false, + hideYawCorrection: false, + standingEnabled: false, + standingUpperLegAngle: 0.0, + standingLowerLegAngle: 0.0, + standingFootAngle: 0.0, + sittingEnabled: false, + sittingUpperLegAngle: 0.0, + sittingLowerLegAngle: 0.0, + sittingFootAngle: 0.0, + flatEnabled: false, + flatUpperLegAngle: 0.0, + flatLowerLegAngle: 0.0, + flatFootAngle: 0.0, +}; + +export function serializeStayAlignedSettings( + settings: StayAlignedSettingsForm +): StayAlignedSettingsT { + const serialized = new StayAlignedSettingsT(); + serialized.enabled = settings.enabled; + serialized.extraYawCorrection = settings.extraYawCorrection; + serialized.hideYawCorrection = settings.hideYawCorrection; + serialized.standingEnabled = settings.standingEnabled; + serialized.standingUpperLegAngle = settings.standingUpperLegAngle; + serialized.standingLowerLegAngle = settings.standingLowerLegAngle; + serialized.standingFootAngle = settings.standingFootAngle; + serialized.sittingEnabled = settings.sittingEnabled; + serialized.sittingUpperLegAngle = settings.sittingUpperLegAngle; + serialized.sittingLowerLegAngle = settings.sittingLowerLegAngle; + serialized.sittingFootAngle = settings.sittingFootAngle; + serialized.flatEnabled = settings.flatEnabled; + serialized.flatUpperLegAngle = settings.flatUpperLegAngle; + serialized.flatLowerLegAngle = settings.flatLowerLegAngle; + serialized.flatFootAngle = settings.flatFootAngle; + return serialized; +} + +export function deserializeStayAlignedSettings( + serialized: StayAlignedSettingsT +): StayAlignedSettingsForm { + return serialized; +} + +export function StayAlignedSettings({ + values, + control, +}: { + values: SettingsForm; + control: Control; +}) { + const { l10n } = useLocalization(); + const { config } = useConfig(); + + return ( + } id="stayaligned"> + + {l10n.getString('settings-stay_aligned')} + +
+ + {l10n.getString('settings-stay_aligned-description')} + +
+
+ + {l10n.getString('settings-stay_aligned-general-label')} + + {values.stayAligned.enabled && values.driftCompensation.enabled && ( +
+ {l10n.getString( + 'settings-stay_aligned-warnings-drift_compensation' + )} +
+ )} +
+ + + +
+
+
+ + {l10n.getString('settings-stay_aligned-relaxed_poses-label')} + +
+ {config?.debug ? ( + + ) : ( + + )} +
+
+
+ ); +} diff --git a/gui/src/components/stay-aligned/RelaxedPose.tsx b/gui/src/components/stay-aligned/RelaxedPose.tsx new file mode 100644 index 000000000..71750934d --- /dev/null +++ b/gui/src/components/stay-aligned/RelaxedPose.tsx @@ -0,0 +1,439 @@ +import { useLocaleConfig } from '@/i18n/config'; +import { ReactLocalization, useLocalization } from '@fluent/react'; +import { + DetectStayAlignedRelaxedPoseRequestT, + RpcMessage, + StayAlignedPoseT, + StayAlignedRelaxedPose, +} from 'solarxr-protocol'; +import { Typography } from '@/components/commons/Typography'; +import { SettingsForm } from '@/components/settings/pages/GeneralSettings'; +import { Control } from 'react-hook-form'; +import { NumberSelector } from '@/components/commons/NumberSelector'; +import { useWebsocketAPI } from '@/hooks/websocket-api'; +import { MouseEventHandler } from 'react'; +import { Button } from '@/components/commons/Button'; +import { CheckBox } from '@/components/commons/Checkbox'; +import { useAtomValue } from 'jotai'; +import { stayAlignedPoseAtom } from '@/store/app-store'; + +/** + * Creates a pose angle formatter that formats an positive angle as "$angle + * outwards" and a negative angle as "$angle inwards". Useful for describing + * leg angles in relaxed poses. + */ +function PoseAngleFormat(l10n: ReactLocalization, currentLocales: string[]) { + const degreeFormat = new Intl.NumberFormat(currentLocales, { + style: 'unit', + unit: 'degree', + maximumFractionDigits: 0, + }); + + return { + format: (angle: number) => { + angle = Math.round(angle); + const angleStr = degreeFormat.format(Math.abs(angle)); + if (angle >= 1) { + return l10n.getString('settings-stay_aligned-relaxed_poses-outwards', { + angle: angleStr, + }); + } else if (angle <= -1) { + return l10n.getString('settings-stay_aligned-relaxed_poses-inwards', { + angle: angleStr, + }); + } else { + return angleStr; + } + }, + }; +} + +function relaxedPoseKey(pose: StayAlignedRelaxedPose) { + switch (pose) { + case StayAlignedRelaxedPose.STANDING: + return 'settings-stay_aligned-relaxed_poses-standing'; + case StayAlignedRelaxedPose.SITTING: + return 'settings-stay_aligned-relaxed_poses-sitting'; + case StayAlignedRelaxedPose.FLAT: + return 'settings-stay_aligned-relaxed_poses-flat'; + } +} + +/** + * Read-only view of a relaxed pose. + */ +export function RelaxedPose({ + pose, + enabled, + upperLegAngleInDeg, + lowerLegAngleInDeg, + footAngleInDeg, +}: { + pose: StayAlignedRelaxedPose; + enabled: boolean; + upperLegAngleInDeg: number; + lowerLegAngleInDeg: number; + footAngleInDeg: number; +}) { + const { l10n } = useLocalization(); + const { currentLocales } = useLocaleConfig(); + const angleFormat = PoseAngleFormat(l10n, currentLocales); + + if (enabled) { + return ( +
+ + {l10n.getString(relaxedPoseKey(pose))} + + + {l10n.getString( + 'settings-stay_aligned-relaxed_poses-upper_leg_angle' + )} + : {angleFormat.format(upperLegAngleInDeg)} + + + {l10n.getString( + 'settings-stay_aligned-relaxed_poses-lower_leg_angle' + )} + : {angleFormat.format(lowerLegAngleInDeg)} + + + {l10n.getString('settings-stay_aligned-relaxed_poses-foot_angle')}:{' '} + {angleFormat.format(footAngleInDeg)} + +
+ ); + } else { + return ( +
+ + {l10n.getString(relaxedPoseKey(pose))} + + + {l10n.getString('settings-stay_aligned-relaxed_poses-disabled')} + +
+ ); + } +} + +/** + * Read-only view of the current pose's relaxed angles. + */ +export function CurrentRelaxedPose() { + const { l10n } = useLocalization(); + const { currentLocales } = useLocaleConfig(); + const angleFormat = PoseAngleFormat(l10n, currentLocales); + + const stayAlignedPose = + useAtomValue(stayAlignedPoseAtom) || new StayAlignedPoseT(0.0, 0.0, 0.0); + + return ( +
+ + {l10n.getString('settings-stay_aligned-relaxed_poses-current_angles')} + + + {l10n.getString('settings-stay_aligned-relaxed_poses-upper_leg_angle')}:{' '} + {angleFormat.format(stayAlignedPose.upperLegAngleInDeg)} + + + {l10n.getString('settings-stay_aligned-relaxed_poses-lower_leg_angle')}:{' '} + {angleFormat.format(stayAlignedPose.lowerLegAngleInDeg)} + + + {l10n.getString('settings-stay_aligned-relaxed_poses-foot_angle')}:{' '} + {angleFormat.format(stayAlignedPose.footAngleInDeg)} + +
+ ); +} + +/** + * Read-only view of all the relaxed poses, and the current pose's angles. + */ +export function RelaxedPosesSummary({ values }: { values: SettingsForm }) { + return ( +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ ); +} + +/** + * Tells the server to set a relaxed pose to the current pose's angles. + */ +export function DetectRelaxedPoseButton({ + pose, + onClick, +}: { + pose: StayAlignedRelaxedPose; + onClick?: MouseEventHandler; +}) { + const { sendRPCPacket } = useWebsocketAPI(); + const { l10n } = useLocalization(); + + return ( + + ); +} + +/** + * Tells the server to reset the angles in a relaxed pose. + */ +export function ResetRelaxedPoseButton({ + pose, + onClick, + children, +}: { + pose: StayAlignedRelaxedPose; + onClick?: MouseEventHandler; +} & React.PropsWithChildren) { + const { sendRPCPacket } = useWebsocketAPI(); + const { l10n } = useLocalization(); + + return ( + + ); +} + +/** + * Control to edit the angles of a pose. + */ +function RelaxedPoseControl({ + pose, + enabledKey, + upperLegSettingsKey, + lowerLegSettingsKey, + footSettingsKey, + control, +}: { + pose: StayAlignedRelaxedPose; + enabledKey: string; + upperLegSettingsKey: string; + lowerLegSettingsKey: string; + footSettingsKey: string; + control: Control; +}) { + const { l10n } = useLocalization(); + const { currentLocales } = useLocaleConfig(); + const angleFormat = PoseAngleFormat(l10n, currentLocales); + + return ( +
+ + {l10n.getString(relaxedPoseKey(pose))} + + + `${l10n.getString( + 'settings-stay_aligned-relaxed_poses-upper_leg_angle' + )}: ${angleFormat.format(value)}` + } + min={-90.0} + max={90.0} + step={1.0} + /> + + `${l10n.getString( + 'settings-stay_aligned-relaxed_poses-lower_leg_angle' + )}: ${angleFormat.format(value)}` + } + min={-90.0} + max={90.0} + step={1.0} + /> + + `${l10n.getString( + 'settings-stay_aligned-relaxed_poses-foot_angle' + )}: ${angleFormat.format(value)}` + } + min={-90.0} + max={90.0} + step={1.0} + /> + + + +
+ ); +} + +/** + * Control that displays the current pose's relaxed angles, in a similar layout + * to . + */ +function CurrentRelaxedPoseControl({ + control, +}: { + control: Control; +}) { + const { l10n } = useLocalization(); + const { currentLocales } = useLocaleConfig(); + const angleFormat = PoseAngleFormat(l10n, currentLocales); + + const stayAlignedPose = + useAtomValue(stayAlignedPoseAtom) || new StayAlignedPoseT(0.0, 0.0, 0.0); + + return ( +
+ + {l10n.getString('settings-stay_aligned-relaxed_poses-current_angles')} + + + `${l10n.getString( + 'settings-stay_aligned-relaxed_poses-upper_leg_angle' + )}: ${angleFormat.format(stayAlignedPose.upperLegAngleInDeg || 0.0)}` + } + min={-90.0} + max={90.0} + step={1.0} + /> + + `${l10n.getString( + 'settings-stay_aligned-relaxed_poses-lower_leg_angle' + )}: ${angleFormat.format(stayAlignedPose.lowerLegAngleInDeg || 0.0)}` + } + min={-90.0} + max={90.0} + step={1.0} + /> + + `${l10n.getString( + 'settings-stay_aligned-relaxed_poses-foot_angle' + )}: ${angleFormat.format(stayAlignedPose.footAngleInDeg || 0.0)}` + } + min={-90.0} + max={90.0} + step={1.0} + /> +
+ ); +} + +/** + * Control to edit the angles of all the relaxed poses. + */ +export function RelaxedPosesSettings({ + control, +}: { + control: Control; +}) { + return ( +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ ); +} diff --git a/gui/src/components/stay-aligned/StayAlignedInfo.tsx b/gui/src/components/stay-aligned/StayAlignedInfo.tsx new file mode 100644 index 000000000..447fe1f39 --- /dev/null +++ b/gui/src/components/stay-aligned/StayAlignedInfo.tsx @@ -0,0 +1,53 @@ +import { Typography } from '@/components/commons/Typography'; +import { useLocaleConfig } from '@/i18n/config'; +import { angleIsNearZero } from '@/maths/angle'; +import { TrackerDataT } from 'solarxr-protocol'; + +export function StayAlignedInfo({ + color, + tracker, +}: { + color: 'primary' | 'secondary'; + tracker: TrackerDataT; +}) { + const { currentLocales } = useLocaleConfig(); + const degreeFormat = new Intl.NumberFormat(currentLocales, { + style: 'unit', + unit: 'degree', + minimumFractionDigits: 1, + maximumFractionDigits: 1, + }); + const errorFormat = new Intl.NumberFormat(currentLocales, { + minimumFractionDigits: 1, + maximumFractionDigits: 1, + }); + + const stayAligned = tracker.stayAligned; + if (!stayAligned) { + return <>; + } + + const locked = stayAligned.locked ? '🔒' : ''; + + const delta = `Δ=${degreeFormat.format(stayAligned.yawCorrectionInDeg)}`; + + const errors = []; + const maxErrorToShow = 0.1; + if (!angleIsNearZero(stayAligned.lockedErrorInDeg, maxErrorToShow)) { + errors.push(`L=${errorFormat.format(stayAligned.lockedErrorInDeg)}`); + } + if (!angleIsNearZero(stayAligned.centerErrorInDeg, maxErrorToShow)) { + errors.push(`C=${errorFormat.format(stayAligned.centerErrorInDeg)}`); + } + if (!angleIsNearZero(stayAligned.neighborErrorInDeg, maxErrorToShow)) { + errors.push(`N=${errorFormat.format(stayAligned.neighborErrorInDeg)}`); + } + + const error = errors.length > 0 ? `(${errors.join(', ')})` : ''; + + return ( + + {locked} {delta} {error} + + ); +} diff --git a/gui/src/components/tracker/TrackersTable.tsx b/gui/src/components/tracker/TrackersTable.tsx index 8ac6c382a..78064204b 100644 --- a/gui/src/components/tracker/TrackersTable.tsx +++ b/gui/src/components/tracker/TrackersTable.tsx @@ -17,6 +17,7 @@ import { TrackerStatus } from './TrackerStatus'; import { TrackerWifi } from './TrackerWifi'; import { trackerStatusRelated, useStatusContext } from '@/hooks/status-system'; import { FlatDeviceTracker } from '@/store/app-store'; +import { StayAlignedInfo } from '@/components/stay-aligned/StayAlignedInfo'; enum DisplayColumn { NAME, @@ -28,6 +29,7 @@ enum DisplayColumn { TEMPERATURE, LINEAR_ACCELERATION, POSITION, + STAY_ALIGNED, URL, } @@ -41,6 +43,7 @@ const displayColumns: { [k: string]: boolean } = { [DisplayColumn.TEMPERATURE]: true, [DisplayColumn.LINEAR_ACCELERATION]: true, [DisplayColumn.POSITION]: true, + [DisplayColumn.STAY_ALIGNED]: true, [DisplayColumn.URL]: true, }; @@ -196,6 +199,7 @@ export function TrackersTable({ displayColumns[DisplayColumn.TEMPERATURE] = hasTemperature || false; displayColumns[DisplayColumn.POSITION] = moreInfo || false; displayColumns[DisplayColumn.LINEAR_ACCELERATION] = moreInfo || false; + displayColumns[DisplayColumn.STAY_ALIGNED] = moreInfo || false; displayColumns[DisplayColumn.URL] = moreInfo || false; const displayColumnsKeys = Object.keys(displayColumns).filter( (k) => displayColumns[k] @@ -362,6 +366,15 @@ export function TrackersTable({ ), })} + {column({ + id: DisplayColumn.STAY_ALIGNED, + label: l10n.getString('tracker-table-column-stay_aligned'), + labelClassName: 'w-36', + row: ({ tracker }) => ( + + ), + })} + {column({ id: DisplayColumn.URL, label: l10n.getString('tracker-table-column-url'), diff --git a/gui/src/components/widgets/IMUVisualizerWidget.tsx b/gui/src/components/widgets/IMUVisualizerWidget.tsx index fc55815b6..b753da8f6 100644 --- a/gui/src/components/widgets/IMUVisualizerWidget.tsx +++ b/gui/src/components/widgets/IMUVisualizerWidget.tsx @@ -12,6 +12,7 @@ import { useLocalization } from '@fluent/react'; import { Vector3Object, Vector3FromVec3fT } from '@/maths/vector3'; import { Gltf } from '@react-three/drei'; import { ErrorBoundary } from 'react-error-boundary'; +import { StayAlignedInfo } from '@/components/stay-aligned/StayAlignedInfo'; const groundColor = '#4444aa'; @@ -168,6 +169,15 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
)} + {!!tracker.stayAligned && ( +
+ + {l10n.getString('widget-imu_visualizer-stay_aligned')} + + +
+ )} + {!enabled && (