Remove use of mutable measures - #677
Conversation
WPILib 2027 removes the concept of mutable measures, so now is a good time to clean these up.
There was a problem hiding this comment.
Pull request overview
This PR updates SeriouslyCommonLib to stop relying on WPILib “mutable measure” types (e.g., MutAngle, MutableMeasure) in preparation for their removal in WPILib 2027, shifting code to use immutable Measure instances and Units.*.zero() helpers.
Changes:
- Replaced
Mut*measure fields/usages with immutableMeasuretypes (e.g.,Angle,AngularVelocity,Distance,Voltage) across subsystems, mocks, and configs. - Simplified
MeasurePropertyand its subclasses to remove the mutable-measure generic parameter and replace in-place mutation with assignment. - Standardized several “zero” initializations to
Units.*.zero().
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/xbot/common/subsystems/pose/BasePoseSubsystem.java | Replaces MutAngle heading tracking with immutable Angle assignments. |
| src/main/java/xbot/common/properties/MeasureProperty.java | Removes MutableMeasure usage and updates value tracking/log refresh to use immutable measures. |
| src/main/java/xbot/common/properties/TimeProperty.java | Updates property type to match new MeasureProperty generics (no mutable measure type). |
| src/main/java/xbot/common/properties/DistanceProperty.java | Updates property type to match new MeasureProperty generics (no mutable measure type). |
| src/main/java/xbot/common/properties/AngularVelocityProperty.java | Updates property type to match new MeasureProperty generics (no mutable measure type). |
| src/main/java/xbot/common/properties/AngleProperty.java | Updates property type to match new MeasureProperty generics (no mutable measure type). |
| src/main/java/xbot/common/injection/electrical_contract/SparkMaxMotorControllerOutputConfig.java | Switches RPM initialization to RPM.zero(). |
| src/main/java/xbot/common/controls/sensors/wpi_adapters/LaserCANWpiAdapter.java | Switches distance fallback initialization to Meters.zero(). |
| src/main/java/xbot/common/controls/sensors/mock_adapters/MockCANCoder.java | Replaces mutable measure fields with immutable Angle/AngularVelocity assignments. |
| src/main/java/xbot/common/controls/actuators/XCANMotorController.java | Uses Volts.zero() in limit checks for consistency with immutable measures. |
| src/main/java/xbot/common/controls/actuators/mock_adapters/MockCANMotorController.java | Replaces mutable voltage/current/position/velocity state with immutable measure assignments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aschokking
left a comment
There was a problem hiding this comment.
The reason we moved to these was to address memory pressure from creating tons and tons of immutable objects along the way. Do we maybe need to do something like mutable ourselves with internal doubles more? Or maybe the memory pressure won't be a thing on the newer hardware?
WPILib 2027 removes the concept of mutable measures, so now is a good time to clean these up.