fix: clamp per-axis gyro deadzone distance to zero and fix boundary condition#1282
Open
Sohmsss wants to merge 1 commit intoAntiMicroX:masterfrom
Open
fix: clamp per-axis gyro deadzone distance to zero and fix boundary condition#1282Sohmsss wants to merge 1 commit intoAntiMicroX:masterfrom
Sohmsss wants to merge 1 commit intoAntiMicroX:masterfrom
Conversation
…ondition Two bugs caused gyro drift even when a hardware deadzone was configured: 1. calculateX/Y/ZDistanceFromDeadZone() could return negative values when one axis magnitude was smaller than sqrt(dead_zone^2 - other_axes^2). That negative distance was passed to mouse-movement as a speed value, producing spurious movement opposite to the intended direction. Fixed by wrapping the result in std::max(0.0, ...). 2. calculateSensorDirection() used strict less-than (distance < m_dead_zone), so a reading whose 3-D magnitude was exactly equal to the configured deadzone was not treated as centered and could trigger movement. Fixed to use less-than-or-equal (distance <= m_dead_zone). Adds tests/testjoysensordead.cpp covering both regressions.
pktiuk
reviewed
Mar 23, 2026
Member
|
@Sohmsss |
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 gyro drift caused by two bugs in the deadzone math:
calculateX/Y/ZDistanceFromDeadZone()returned negative values when one axis magnitude was smaller thansqrt(dead_zone² - other_axes²). The negative distance was used directly as a mouse-movement speed, producing spurious movement opposite to the intended direction — visible as asymmetric drift (e.g. always drifting right slightly).calculateSensorDirection(): used strictdistance < m_dead_zone, so a reading whose 3-D magnitude was exactly equal to the configured deadzone was not treated as centered. Fixed todistance <= m_dead_zone.Changes
src/joysensor.cppabs(axis) - sqrt(discriminant)instd::max(0.0, ...)for all three axis distance functionssrc/joygyroscopesensor.cppdistance < m_dead_zone→distance <= m_dead_zonetests/testjoysensordead.cpptests/CMakeLists.txtTest plan
TestJoySensorDead::xDistanceNeverNegative— confirms the negative-return bug is fixed (x=0.1, y=0.3, z=0 with 20° deadzone previously returned −0.078)TestJoySensorDead::yDistanceNeverNegative/zDistanceNeverNegative— same for Y and Z axesTestJoySensorDead::xDistanceZeroInsideDeadZone/ Y / Z — all-small vector returns 0TestJoySensorDead::directionCenteredAtDeadZoneBoundary— sensor at exactly the deadzone radius returnsSENSOR_CENTEREDTestJoySensorDead::directionCenteredInsideDeadZone— sensor inside deadzone returnsSENSOR_CENTEREDCloses #1279