From bfb23ab1734c06d7e02930ff55954b814cc8cc6a Mon Sep 17 00:00:00 2001 From: codingduck106 <65737878+codingduck106@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:19:25 -0700 Subject: [PATCH 1/4] Create generic ElevatorBase class for elevator control This class serves as a generic configurable elevator base, allowing for specific implementations by extending it. --- .../lib2813/subsystems/ElevatorBase.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java new file mode 100644 index 00000000..f195f53b --- /dev/null +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java @@ -0,0 +1,103 @@ +package com.team2813.lib2813.subsystems; + +import static edu.wpi.first.units.Units.Radians; + +import java.util.function.Supplier; + +import com.ctre.phoenix6.signals.NeutralModeValue; +import com.team2813.lib2813.control.ControlMode; +import com.team2813.lib2813.control.InvertType; +import com.team2813.lib2813.control.motors.TalonFXWrapper; +import com.team2813.lib2813.subsystems.ElevatorBase; + +import edu.wpi.first.math.MathUtil; +import edu.wpi.first.math.controller.PIDController; +import edu.wpi.first.networktables.BooleanPublisher; +import edu.wpi.first.networktables.DoublePublisher; +import edu.wpi.first.networktables.NetworkTable; +import edu.wpi.first.networktables.NetworkTableInstance; +import edu.wpi.first.units.measure.Angle; +import edu.wpi.first.units.measure.Current; + +/** + * Generic configurable elevator base class. + * Extend this to create specific elevator implementations + * (set motor IDs, PID values, enum positions, etc.). + * + * Author: Team 2813 + */ +public abstract class ElevatorBase extends MotorSubsystem { + + /** Defines an elevator position with a unit-safe angle */ + public interface PositionBase extends Supplier{ + Angle get(); + } + + protected final TalonFXWrapper motor; + protected final PIDController pid; + + protected final BooleanPublisher atPos; + protected final DoublePublisher pos; + + /** + * @param motor the TalonFXWrapper to control this elevator + * @param pid PID controller for closed-loop position control + * @param gearRatio mechanism gear ratio (rotations -> mechanism movement) + * @param ntInstance NetworkTables instance for telemetry + */ + protected ElevatorBase( + TalonFXWrapper motor, + PIDController pid, + NetworkTableInstance ntInstance, + double acceptableError + ) { + super(new MotorSubsystemConfiguration(motor) + .controlMode(ControlMode.VOLTAGE) + .acceptableError(acceptableError) + .rotationUnit(Radians) + .controller(pid)); + this.motor = motor; + this.pid = pid; + NetworkTable nt = ntInstance.getTable("Elevator"); + atPos = nt.getBooleanTopic("at position").publish(); + pos = nt.getDoubleTopic("position").publish(); + } + + /** Override this in child to return applied current */ + @Override + public Current getAppliedCurrent() { + // TODO stub method + return null; + } + + /** Clamp/control how output is sent to the motor + * + * @param output - the output sent to the motor + * @param setpoint - the PID setpoint of the motor + */ + @Override + protected void useOutput(double output, double setpoint) { + // Default clamp [-6,6], can override in child if needed + super.useOutput(MathUtil.clamp(output, -6, 6), setpoint); + } + + /** Telemetry updates */ + @Override + public void periodic() { + super.periodic(); + atPos.set(atPosition()); + pos.set(getMeasurement()); + } + + /** Utility method for making a default-configured motor + * + * @param masterID - the CAN ID of the master motor + * @param followerID - the CAN ID of the follower motor + */ + protected static TalonFXWrapper makeMotor(int masterID, int followerID) { + TalonFXWrapper wrapper = new TalonFXWrapper(masterID, InvertType.CLOCKWISE); + wrapper.setNeutralMode(NeutralModeValue.Brake); + wrapper.addFollower(followerID, InvertType.FOLLOW_MASTER); + return wrapper; + } +} From 12bf9c2ae156d0a6bea26e543e9aedfd6f39c0a8 Mon Sep 17 00:00:00 2001 From: codingduck106 <65737878+codingduck106@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:27:10 -0700 Subject: [PATCH 2/4] Remove getAppliedCurrent method from ElevatorBase Removed the stub method for getAppliedCurrent in ElevatorBase, because it doesn't need to be overriden apparently. --- .../java/com/team2813/lib2813/subsystems/ElevatorBase.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java index f195f53b..993d0773 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java @@ -63,13 +63,6 @@ protected ElevatorBase( pos = nt.getDoubleTopic("position").publish(); } - /** Override this in child to return applied current */ - @Override - public Current getAppliedCurrent() { - // TODO stub method - return null; - } - /** Clamp/control how output is sent to the motor * * @param output - the output sent to the motor From 90e8adb9fbb0fb2ed0f70a31d8fee56858bf8dd2 Mon Sep 17 00:00:00 2001 From: codingman106 Date: Fri, 17 Oct 2025 23:34:39 -0700 Subject: [PATCH 3/4] removed unused imports, removed use of deprecated methods --- .../com/team2813/lib2813/subsystems/ElevatorBase.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java index 993d0773..06d4b168 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java @@ -10,14 +10,12 @@ import com.team2813.lib2813.control.motors.TalonFXWrapper; import com.team2813.lib2813.subsystems.ElevatorBase; -import edu.wpi.first.math.MathUtil; import edu.wpi.first.math.controller.PIDController; import edu.wpi.first.networktables.BooleanPublisher; import edu.wpi.first.networktables.DoublePublisher; import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.units.measure.Angle; -import edu.wpi.first.units.measure.Current; /** * Generic configurable elevator base class. @@ -69,9 +67,9 @@ protected ElevatorBase( * @param setpoint - the PID setpoint of the motor */ @Override - protected void useOutput(double output, double setpoint) { - // Default clamp [-6,6], can override in child if needed - super.useOutput(MathUtil.clamp(output, -6, 6), setpoint); + protected double clampOutput(double output) { + // TODO Auto-generated method stub + return super.clampOutput(output); } /** Telemetry updates */ From a59fe763bc72417efb13aef5deb48ff81c06617f Mon Sep 17 00:00:00 2001 From: codingman106 Date: Fri, 17 Oct 2025 23:41:42 -0700 Subject: [PATCH 4/4] ran gradle spotlessApply --- .../lib2813/subsystems/ElevatorBase.java | 130 +++++++++--------- 1 file changed, 64 insertions(+), 66 deletions(-) diff --git a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java index 06d4b168..a5bc2dc4 100644 --- a/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java +++ b/lib/src/main/java/com/team2813/lib2813/subsystems/ElevatorBase.java @@ -2,93 +2,91 @@ import static edu.wpi.first.units.Units.Radians; -import java.util.function.Supplier; - import com.ctre.phoenix6.signals.NeutralModeValue; import com.team2813.lib2813.control.ControlMode; import com.team2813.lib2813.control.InvertType; import com.team2813.lib2813.control.motors.TalonFXWrapper; -import com.team2813.lib2813.subsystems.ElevatorBase; - import edu.wpi.first.math.controller.PIDController; import edu.wpi.first.networktables.BooleanPublisher; import edu.wpi.first.networktables.DoublePublisher; import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.units.measure.Angle; +import java.util.function.Supplier; /** - * Generic configurable elevator base class. - * Extend this to create specific elevator implementations + * Generic configurable elevator base class. Extend this to create specific elevator implementations * (set motor IDs, PID values, enum positions, etc.). * - * Author: Team 2813 + *

Author: Team 2813 */ public abstract class ElevatorBase extends MotorSubsystem { - /** Defines an elevator position with a unit-safe angle */ - public interface PositionBase extends Supplier{ - Angle get(); - } + /** Defines an elevator position with a unit-safe angle */ + public interface PositionBase extends Supplier { + Angle get(); + } - protected final TalonFXWrapper motor; - protected final PIDController pid; + protected final TalonFXWrapper motor; + protected final PIDController pid; - protected final BooleanPublisher atPos; - protected final DoublePublisher pos; + protected final BooleanPublisher atPos; + protected final DoublePublisher pos; - /** - * @param motor the TalonFXWrapper to control this elevator - * @param pid PID controller for closed-loop position control - * @param gearRatio mechanism gear ratio (rotations -> mechanism movement) - * @param ntInstance NetworkTables instance for telemetry - */ - protected ElevatorBase( - TalonFXWrapper motor, - PIDController pid, - NetworkTableInstance ntInstance, - double acceptableError - ) { - super(new MotorSubsystemConfiguration(motor) - .controlMode(ControlMode.VOLTAGE) - .acceptableError(acceptableError) - .rotationUnit(Radians) - .controller(pid)); - this.motor = motor; - this.pid = pid; - NetworkTable nt = ntInstance.getTable("Elevator"); - atPos = nt.getBooleanTopic("at position").publish(); - pos = nt.getDoubleTopic("position").publish(); - } + /** + * @param motor the TalonFXWrapper to control this elevator + * @param pid PID controller for closed-loop position control + * @param gearRatio mechanism gear ratio (rotations -> mechanism movement) + * @param ntInstance NetworkTables instance for telemetry + */ + protected ElevatorBase( + TalonFXWrapper motor, + PIDController pid, + NetworkTableInstance ntInstance, + double acceptableError) { + super( + new MotorSubsystemConfiguration(motor) + .controlMode(ControlMode.VOLTAGE) + .acceptableError(acceptableError) + .rotationUnit(Radians) + .controller(pid)); + this.motor = motor; + this.pid = pid; + NetworkTable nt = ntInstance.getTable("Elevator"); + atPos = nt.getBooleanTopic("at position").publish(); + pos = nt.getDoubleTopic("position").publish(); + } - /** Clamp/control how output is sent to the motor - * - * @param output - the output sent to the motor - * @param setpoint - the PID setpoint of the motor - */ - @Override - protected double clampOutput(double output) { - // TODO Auto-generated method stub - return super.clampOutput(output); - } + /** + * Clamp/control how output is sent to the motor + * + * @param output - the output sent to the motor + * @param setpoint - the PID setpoint of the motor + */ + @Override + protected double clampOutput(double output) { + // TODO Auto-generated method stub + return super.clampOutput(output); + } - /** Telemetry updates */ - @Override - public void periodic() { - super.periodic(); - atPos.set(atPosition()); - pos.set(getMeasurement()); - } + /** Telemetry updates */ + @Override + public void periodic() { + super.periodic(); + atPos.set(atPosition()); + pos.set(getMeasurement()); + } - /** Utility method for making a default-configured motor - * - * @param masterID - the CAN ID of the master motor - * @param followerID - the CAN ID of the follower motor - */ - protected static TalonFXWrapper makeMotor(int masterID, int followerID) { - TalonFXWrapper wrapper = new TalonFXWrapper(masterID, InvertType.CLOCKWISE); - wrapper.setNeutralMode(NeutralModeValue.Brake); - wrapper.addFollower(followerID, InvertType.FOLLOW_MASTER); - return wrapper; - } + /** + * Utility method for making a default-configured motor + * + * @param masterID - the CAN ID of the master motor + * @param followerID - the CAN ID of the follower motor + */ + protected static TalonFXWrapper makeMotor(int masterID, int followerID) { + TalonFXWrapper wrapper = new TalonFXWrapper(masterID, InvertType.CLOCKWISE); + wrapper.setNeutralMode(NeutralModeValue.Brake); + wrapper.addFollower(followerID, InvertType.FOLLOW_MASTER); + return wrapper; + } }