fix: stop gyro drift via Eden-matched axis defaults + continuous bias calibration - #4
Merged
Merged
Conversation
…ibration Two independent causes of "gyro drifts over time" in emulators: 1. Default axis maps were built for SDL's Steam Triton sensor order, but Eden/Yuzu's Cemuhook UDP client remaps incoming DSU as (pitch, roll, -yaw) / (accel.x, -accel.z, accel.y). The mismatch fed the emulator gyro on the wrong axes/signs, which showed up as continued one-axis drift after motion stopped. Closes #3. AxisMap::DEFAULT now matches Eden's gyro expectation, and a new AxisMap::DEFAULT_ACCEL covers the asymmetric accel remap. Config defaults wire accel to the new constant. 2. Raw IMU has a permanent zero-rate offset (typical 0.1–2 dps); both SDL and evdevhook2 punt this to the consumer, but the emulator integrates it as orientation drift. Adds a continuous bias estimator ported from JibbSmart/GamepadMotionHelpers (AddSampleStillness in GamepadMotion.hpp v9, MIT). Stillness is gated on combined gyro+accel deltas across a growing collection window; once steady the bias is exponential-LERP'd toward the window-mean gyro with confidence-scaled half-time. Owned by OpenSlot, applied after parse_state, reset on slot reopen and on AxisMap change. dt comes from the IMU timestamp clamped to 100 ms. "Recenter viz" now also forces a fresh calibration via a new stats::RECALIBRATE_REQUEST atomic — user puts the controller down, clicks the button, gyro is zeroed. Tests cover the stillness lock, motion-rejection, reset behaviour, and that brief motion after a lock does not re-zero on bad samples. https://claude.ai/code/session_01JQm3i22nVDxVCwvgvLMuex
…ion tests clippy --all-targets flagged three for-i-in-0..3 / 0..N loops in gyro_calibration tests where the index is only used to look up parallel arrays. Rewrite to iter().enumerate() so -D warnings stays green. https://claude.ai/code/session_01JQm3i22nVDxVCwvgvLMuex
Existing users carry the old SDL-ordered axis defaults in their saved config.toml and keep drifting in Eden/Yuzu after the gyro fix. This adds a one-click reset inside the System frame: confirm prompt, then write Config::DEFAULT via the existing update_and_save path and resync every widget. Avoids asking users to hand-delete %APPDATA%\sc2dsu\config.toml.
User-facing: - "Auto-calibrate bias" checkbox in the gyro frame. Default on; off bypasses the calibrator and passes raw gyro through. Toggling resets. - Subscribers row reports "gyro: off / calibrating… / locked N%" so users can tell when it's safe to start. - "Recenter viz" renamed to "Recalibrate"; the button has also reset the bias calibrator since the drift fix, so the old name understated what it did. stats refactor: ServerStats is now split into ServerSection (dsu), MotionSection (dsu) and CalibrationSection (triton). Each writer can only mutate its own section, which structurally removes the silent clobbering the full-replace publish() had between dsu's periodic stats emit and triton's per-sample calibration publish. Dead last_accel bookkeeping in dsu.rs went with the removed code path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes user reports of gyro drifting over time. Two independent causes, both addressed here.
Default axis maps did not match Eden/Yuzu's Cemuhook UDP remap. Closes Default axis maps do not match Eden/Yuzu Cemuhook UDP motion interpretation #3. Eden reads incoming DSU as
(pitch, roll, -yaw)for gyro and(accel.x, -accel.z, accel.y)for accel. Our defaults were built for SDL's Steam Triton sensor order, so the emulator received gyro on mismatched axes/signs — visible as continued one-axis drift after motion stopped.AxisMap::DEFAULTnow matches Eden's gyro expectation, and a newAxisMap::DEFAULT_ACCELcovers the asymmetric accel remap.Config::DEFAULT.accelwires to the new constant.Continuous gyro bias calibration ported from JibbSmart/GamepadMotionHelpers
AddSampleStillnessinGamepadMotion.hppv9 (MIT). SDL's Triton driver and evdevhook2 both punt the zero-rate offset to the consumer; the emulator integrates it as orientation drift. Newsrc/gyro_calibration.rsgates stillness on combined gyro + accel deltas across a growing collection window; once steady, the bias is exponential-LERP'd toward the window-mean gyro with confidence-scaled half-time, so the first lock is instant and later updates are slow (thermal drift). Accel is part of the gate so a slow constant rotation can't masquerade as stillness.Owned by
OpenSlot, applied right afterparse_state.dtcomes fromimu.timestamp_usclamped to 100 ms. Resets on slot reopen and on axis-map config change. Manual recalibration via the existing Recenter viz button (newstats::RECALIBRATE_REQUESTatomic) — set the controller down, click, gyro is zeroed.Existing configs at
%APPDATA%\sc2dsu\config.tomlare not auto-migrated. Anyone who launched a previous version has the old (SDL-ordered) defaults saved as their config and will keep drifting in Eden/Yuzu until they either:%APPDATA%\sc2dsu\config.tomland let the app write the new defaults on next launch, orA clean install picks up the correct defaults automatically. Worth calling out in the release notes for 0.1.4.
Test plan
cargo fmt --check,cargo clippy -- -D warnings,cargo test --locked,cargo build --release --lockedall pass on Windows.