refactor: high-level OOP rewrite of frc.robot subsystems - #42
Draft
YehudaRothstein wants to merge 1 commit into
Draft
refactor: high-level OOP rewrite of frc.robot subsystems#42YehudaRothstein wants to merge 1 commit into
YehudaRothstein wants to merge 1 commit into
Conversation
Elevate the robot package from procedural, leaky subsystems to encapsulated, declarative Java while preserving all empirical tuning values byte-for-byte. New abstractions: - StateMachineSubsystem<S>: generic base owning currentState + setStateCommand, removing the boilerplate copy-pasted across Shooter/Intake/Transport. - FieldZones: single owner of all field-geometry triggers (alliance/neutral zones, delivery side, trench), centralizing logic previously split between Superstructure and Shooter. - RobotStateSelector: declarative Rule(when, then) table replacing the 12 hand-wired trigger->state blocks in Superstructure.initTriggers. Subsystems: - Privatize all motors/mechanisms/encoders; expose intent-level command/Trigger API (coastCommand, manualShoot, isShooterReady, atPositionTrigger). - *States enums carry behavior (isHighGoal/goalAngle/isShooting/linearVelocity) instead of bare public fields. - Fix Shooter's stateful-supplier anti-pattern: setpoints are now plain double fields written each loop, read by stable lambdas (single source of truth). - Extract inline magic numbers into the *Constants files. - Remove dead code (java.sql import, no-op lambda, redundant fields, yoavHatesThisCommandCommand -> manualShoot). Communication: - Superstructure shrinks ~327 -> ~115 lines; no longer reaches into shooter.turretMechanism, drops 18 boolean log-getters (zones self-log). - Transport now gates on the real shooter-ready signal instead of () -> true. Tuning preserved: every gain, conversion factor, interpolation-table entry, current limit, and friction constant keeps its exact value. ./gradlew build passes; behavior must still be re-validated on the robot. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What
A package-wide OOP overhaul of
frc.robot: the subsystems and their coordination layer are rewritten from procedural, internals-leaking code into encapsulated, declarative Java. No tuning values were changed — every gain, conversion factor, interpolation-table entry, current limit, and friction constant is preserved byte-for-byte (they were only moved into the*Constantsfiles).Why
The original subsystems were "too basic": public motors/mechanisms/
currentStatefields,ConditionalCommands pollingcurrentState.equals(IDLE), magic numbers inline in constructors, the same state-machine boilerplate copy-pasted three times, a stateful-supplier anti-pattern inShooter, and weak inter-class wiring (Transporthard-coded to() -> true,Superstructurereaching intoshooter.turretMechanism, 12 hand-wired trigger→state blocks).Key changes
New abstractions
frc/robot/lib/StateMachineSubsystem.java— generic baseStateMachineSubsystem<S extends Enum<S>>owningcurrentState+setStateCommand.frc/robot/lib/FieldZones.java— single owner of all field-geometry triggers (alliance/neutral zones, delivery side, trench).frc/robot/superstructure/RobotStateSelector.java— declarativeRule(when, then)table replacinginitTriggers.Subsystems (
Shooter,Intake,Transport)coastCommand,manualShoot,isShooterReady,atPositionTrigger).*Statesenums now carry behavior (isHighGoal(),goalAngle(),isShooting(),linearVelocity()) instead of bare public fields.Shooter's stateful-supplier anti-pattern: setpoints are plaindoublefields written each loop, read by stable lambdas.java.sqlimport, no-op(at)->at=false, redundantturretToHubVector,yoavHatesThisCommandCommand→manualShoot).Communication
Superstructureshrank ~327 → ~115 lines; dropped 18 boolean log-getters (zones self-log via nestedFieldZones).Transportnow gates on the real shooter-ready signal instead of() -> true(intentional behavior change).Reviewer notes
./gradlew buildpassing. The two intentional flow changes — real transport gating and the declarative selector — need on-robot re-validation (state transitions, shooting, intake pump, delivery aiming) before competition. The selector was checked rule-by-rule against the oldinitTriggersand is logically identical.FieldZoneslives infrc.robot.lib(notsuperstructure) becauseShooterconsumes itsinTrench()trigger, and a subsystem importing the superstructure package would be a layering inversion.FieldZones.🤖 Generated with Claude Code