From aac74cf5a25984fe8d24e8b741e6e7a12ab9f431 Mon Sep 17 00:00:00 2001 From: cuttestkittensrule Date: Tue, 14 Oct 2025 12:35:38 -0700 Subject: [PATCH] Force non-positional control for the MotorSubsystem ControlMode Achieved by throwing an exception if the control mode uses positional control also removes unused ControlMode API --- .../team2813/lib2813/control/ControlMode.java | 20 +++++++++---------- .../lib2813/subsystems/MotorSubsystem.java | 8 ++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/control/ControlMode.java b/lib/src/main/java/com/team2813/lib2813/control/ControlMode.java index 0ae960c7..4bbc194c 100644 --- a/lib/src/main/java/com/team2813/lib2813/control/ControlMode.java +++ b/lib/src/main/java/com/team2813/lib2813/control/ControlMode.java @@ -1,20 +1,18 @@ package com.team2813.lib2813.control; -import com.revrobotics.spark.SparkBase.ControlType; - public enum ControlMode { - DUTY_CYCLE(ControlType.kDutyCycle), - VELOCITY(ControlType.kVelocity), - MOTION_MAGIC(ControlType.kPosition), - VOLTAGE(ControlType.kVoltage); + DUTY_CYCLE(false), + VELOCITY(false), + MOTION_MAGIC(true), + VOLTAGE(false); - private final ControlType sparkMode; + private final boolean isPositionalControl; - ControlMode(ControlType sparkMode) { - this.sparkMode = sparkMode; + ControlMode(boolean isPositionalControl) { + this.isPositionalControl = isPositionalControl; } - public ControlType getSparkMode() { - return sparkMode; + public boolean isPositionalControl() { + return isPositionalControl; } } diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java b/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java index d2e76276..c33a905f 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/MotorSubsystem.java @@ -311,8 +311,16 @@ public MotorSubsystemConfiguration controller(PIDController controller) { * * @param controlMode The mode to use when controlling the motor * @return {@code this} for chaining + * @throws IllegalArgumentException If {@code controlMode} is for positional control */ public MotorSubsystemConfiguration controlMode(ControlMode controlMode) { + if (controlMode.isPositionalControl()) { + throw new IllegalArgumentException( + String.format( + "Control mode %s is for positional control. This is invalid! Please use a different" + + " control mode", + controlMode)); + } this.controlMode = controlMode; return this; }