Skip to content

Fix turret setpoint wraparound for asymmetric operating ranges - #195

Merged
BenGamer3 merged 7 commits into
mainfrom
tuningturret
Aug 5, 2026
Merged

Fix turret setpoint wraparound for asymmetric operating ranges#195
BenGamer3 merged 7 commits into
mainfrom
tuningturret

Conversation

@nlaverdure

Copy link
Copy Markdown
Member

Summary

  • Fixes the turret's closed-loop position wrap/clamp so it works correctly for operating ranges that don't start at 0 deg (e.g. -280 deg to 30 deg). The old inputModulus(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.
  • Extracts the wrap-window center into a CENTER_RAD constant shared between TurretIOSpark and TurretIOSimSpark, and brings the sim IO (previously still on the old [0, 2*pi) wrap) in line with the real one.
  • Removes MECHANISM_OFFSET, a second always-zero rotation offset that duplicated ABS_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.
  • Documents the turret's angle convention, what ABS_ENCODER_OFFSET calibrates 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.
  • Also includes prior commits on this branch: seeding the turret's relative encoder from the absolute encoder on boot, several rounds of soft-limit tuning from bench testing, and a driver-controller-selection cleanup.

Test plan

  • Verified against real robot logs (sessions 91-95): confirmed the pre-fix encoder-seed epoch mismatch caused a ~343 deg runaway sweep, confirmed it's gone after the fix, and confirmed the wrap math holds for the widened -280/30 range with no phantom encoder jumps.
  • Bench-test the current -280 deg to 30 deg range end-to-end once the reported mechanical binding is resolved.
  • Confirm sim (TurretIOSimSpark) still initializes and tracks correctly with the centered wrap window.

🤖 Generated with Claude Code

BenGamer3 and others added 7 commits August 4, 2026 20:00
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
BenGamer3 merged commit 8d106f2 into main Aug 5, 2026
2 checks passed
@BenGamer3
BenGamer3 deleted the tuningturret branch August 5, 2026 01:02
@nlaverdure nlaverdure linked an issue Aug 5, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix turret not being in the correct range of rotation

2 participants