diff options
| author | 2023-05-08 11:17:27 -0600 | |
|---|---|---|
| committer | 2023-05-08 12:06:38 -0600 | |
| commit | 97bd6d641811cafc3ec99879fa53beda1a2334b5 (patch) | |
| tree | ec3946ddaa935829006ceb2b46995fe493621dba /src/core/hid/motion_input.cpp | |
| parent | Merge pull request #10075 from Kelebek1/silence_nifm_spam (diff) | |
| download | yuzu-97bd6d641811cafc3ec99879fa53beda1a2334b5.tar.gz yuzu-97bd6d641811cafc3ec99879fa53beda1a2334b5.tar.xz yuzu-97bd6d641811cafc3ec99879fa53beda1a2334b5.zip | |
core: hid: Allow to calibrate gyro sensor
Diffstat (limited to 'src/core/hid/motion_input.cpp')
| -rw-r--r-- | src/core/hid/motion_input.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index b60478dbb..f56f2ae1d 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp | |||
| @@ -37,11 +37,17 @@ void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { | |||
| 37 | gyro.y = std::clamp(gyro.y, -GyroMaxValue, GyroMaxValue); | 37 | gyro.y = std::clamp(gyro.y, -GyroMaxValue, GyroMaxValue); |
| 38 | gyro.z = std::clamp(gyro.z, -GyroMaxValue, GyroMaxValue); | 38 | gyro.z = std::clamp(gyro.z, -GyroMaxValue, GyroMaxValue); |
| 39 | 39 | ||
| 40 | // Auto adjust drift to minimize drift | 40 | // Auto adjust gyro_bias to minimize drift |
| 41 | if (!IsMoving(IsAtRestRelaxed)) { | 41 | if (!IsMoving(IsAtRestRelaxed)) { |
| 42 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); | 42 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | // Adjust drift when calibration mode is enabled | ||
| 46 | if (calibration_mode) { | ||
| 47 | gyro_bias = (gyro_bias * 0.99f) + (gyroscope * 0.01f); | ||
| 48 | StopCalibration(); | ||
| 49 | } | ||
| 50 | |||
| 45 | if (gyro.Length() < gyro_threshold * user_gyro_threshold) { | 51 | if (gyro.Length() < gyro_threshold * user_gyro_threshold) { |
| 46 | gyro = {}; | 52 | gyro = {}; |
| 47 | } else { | 53 | } else { |
| @@ -107,6 +113,19 @@ void MotionInput::UpdateRotation(u64 elapsed_time) { | |||
| 107 | rotations += gyro * sample_period; | 113 | rotations += gyro * sample_period; |
| 108 | } | 114 | } |
| 109 | 115 | ||
| 116 | void MotionInput::Calibrate() { | ||
| 117 | calibration_mode = true; | ||
| 118 | calibration_counter = 0; | ||
| 119 | } | ||
| 120 | |||
| 121 | void MotionInput::StopCalibration() { | ||
| 122 | if (calibration_counter++ > CalibrationSamples) { | ||
| 123 | calibration_mode = false; | ||
| 124 | ResetQuaternion(); | ||
| 125 | ResetRotations(); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 110 | // Based on Madgwick's implementation of Mayhony's AHRS algorithm. | 129 | // Based on Madgwick's implementation of Mayhony's AHRS algorithm. |
| 111 | // https://github.com/xioTechnologies/Open-Source-AHRS-With-x-IMU/blob/master/x-IMU%20IMU%20and%20AHRS%20Algorithms/x-IMU%20IMU%20and%20AHRS%20Algorithms/AHRS/MahonyAHRS.cs | 130 | // https://github.com/xioTechnologies/Open-Source-AHRS-With-x-IMU/blob/master/x-IMU%20IMU%20and%20AHRS%20Algorithms/x-IMU%20IMU%20and%20AHRS%20Algorithms/AHRS/MahonyAHRS.cs |
| 112 | void MotionInput::UpdateOrientation(u64 elapsed_time) { | 131 | void MotionInput::UpdateOrientation(u64 elapsed_time) { |