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/2] 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/2] 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