Fix turret setpoint wraparound for asymmetric operating ranges - #195
Merged
Conversation
TurretIOSpark computed the modulus center inline; extract it into CENTER_RAD so both it and TurretIOSimSpark derive the wrap window from the same source. TurretIOSimSpark was still using the old hardcoded [0, 2*pi) wrap, which breaks for any operating range that isn't [0, 360) - bring it in line with the real IO's centered window. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Always zero, and layered on top of ABS_ENCODER_OFFSET in a way that was hazardous rather than useful: it cancelled out of every reported position, but shifted the soft limits away from true forward if ever set nonzero, with nothing visible to indicate the mismatch. ABS_ENCODER_OFFSET is the single source of truth for where forward is. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Explain the forward/CCW angle convention, what ABS_ENCODER_OFFSET calibrates and how to redo it, the meaning and constraint on the soft limits, and that CENTER_RAD is derived rather than hand-set. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
BenGamer3
approved these changes
Aug 5, 2026
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
-280 degto30 deg). The oldinputModulus(x, 0, 2*pi)folded any negative setpoint onto the same clamped value, and the one-time relative-encoder seed could land in a different 2*pi epoch than the commanded setpoints, both of which caused the turret to take the long way around (up to a full extra revolution) instead of the short path to target.CENTER_RADconstant shared betweenTurretIOSparkandTurretIOSimSpark, and brings the sim IO (previously still on the old[0, 2*pi)wrap) in line with the real one.MECHANISM_OFFSET, a second always-zero rotation offset that duplicatedABS_ENCODER_OFFSET's job and, if ever set nonzero, would have silently shifted the soft limits away from true forward without affecting reported position - a hazard with no upside.ABS_ENCODER_OFFSETcalibrates and how to redo it, and the constraint the operating range must satisfy, so future reclocking doesn't require re-deriving this from the control math.Test plan
-280/30range with no phantom encoder jumps.-280 degto30 degrange end-to-end once the reported mechanical binding is resolved.TurretIOSimSpark) still initializes and tracks correctly with the centered wrap window.🤖 Generated with Claude Code