From 4ef804c4ce047ccd17884518200bf2dcf036f65e Mon Sep 17 00:00:00 2001 From: Shikhar Date: Tue, 27 Jan 2026 19:15:37 -0700 Subject: [PATCH] Shooter finish --- .../subsystems/shooter/ShooterConstants.java | 11 +++- .../robot/subsystems/shooter/ShooterIO.java | 10 +++- .../robot/subsystems/shooter/ShooterReal.java | 58 +++++-------------- 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/src/main/java/frc4388/robot/subsystems/shooter/ShooterConstants.java b/src/main/java/frc4388/robot/subsystems/shooter/ShooterConstants.java index 857bbeb..e938be4 100644 --- a/src/main/java/frc4388/robot/subsystems/shooter/ShooterConstants.java +++ b/src/main/java/frc4388/robot/subsystems/shooter/ShooterConstants.java @@ -4,6 +4,7 @@ import static edu.wpi.first.units.Units.Degrees; import com.ctre.phoenix6.configs.CurrentLimitsConfigs; import com.ctre.phoenix6.configs.MotorOutputConfigs; +import com.ctre.phoenix6.configs.Slot0Configs; import com.ctre.phoenix6.configs.TalonFXConfiguration; import com.ctre.phoenix6.signals.NeutralModeValue; @@ -12,14 +13,18 @@ import frc4388.utility.status.CanDevice; public class ShooterConstants { // Motor conversions - // public static final double ANGLE_MOTOR_GEAR_RATIO = 1.; - public static final double PITCH_MOTOR_GEAR_RATIO = 1.; - public static final double FLYWHEEL_GEAR_RATIO = 1.; + public static final double FEEDER_INCHES_PER_ROT = 1.; public static final double SHOOTERMOTOR1_GEAR_RATIO = 1.; public static final double SHOOTERMOTOR2_GEAR_RATIO = 1.; public static final double INDEXER_GEAR_RATIO = 1.; + public static Slot0Configs SHOOTER_PID = new Slot0Configs() + .withKV(0.0) + .withKP(0.0) + .withKI(0.0) + .withKD(0.0); + // Limits // 0 is the forward angle on the robot. diff --git a/src/main/java/frc4388/robot/subsystems/shooter/ShooterIO.java b/src/main/java/frc4388/robot/subsystems/shooter/ShooterIO.java index 1ea9a10..5f0a1b8 100644 --- a/src/main/java/frc4388/robot/subsystems/shooter/ShooterIO.java +++ b/src/main/java/frc4388/robot/subsystems/shooter/ShooterIO.java @@ -27,12 +27,16 @@ public interface ShooterIO { AngularVelocity motor1TargetVelocity = RotationsPerSecond.of(0); AngularVelocity motor2TargetVelocity = RotationsPerSecond.of(0); AngularVelocity indexerTargetVelocity = RotationsPerSecond.of(0); + + AngularVelocity motor1Velocity = RotationsPerSecond.of(0); + AngularVelocity motor2Velocity = RotationsPerSecond.of(0); + AngularVelocity indexerVelocity = RotationsPerSecond.of(0); + Current motor1Current = Amps.of(0); + Current motor2Current = Amps.of(0); + Current indexerCurrent = Amps.of(0); LinearVelocity motorLinearVelocity = InchesPerSecond.of(0); - AngularVelocity motorVelocity = RotationsPerSecond.of(0); - AngularVelocity motorTargetVelocity = RotationsPerSecond.of(0); - Current motor2Current = Amps.of(0); } // public default void setShooterAngle(ShooterState state, Angle angle) {} diff --git a/src/main/java/frc4388/robot/subsystems/shooter/ShooterReal.java b/src/main/java/frc4388/robot/subsystems/shooter/ShooterReal.java index 0f35c0c..159c70b 100644 --- a/src/main/java/frc4388/robot/subsystems/shooter/ShooterReal.java +++ b/src/main/java/frc4388/robot/subsystems/shooter/ShooterReal.java @@ -12,7 +12,7 @@ import edu.wpi.first.units.measure.AngularVelocity; import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc4388.utility.configurable.ConfigurableDouble; -public class ShooterReal extends SubsystemBase implements ShooterIO { +public class ShooterReal implements ShooterIO { TalonFX m_shooter1Motor; TalonFX m_shooter2Motor; @@ -30,7 +30,10 @@ public class ShooterReal extends SubsystemBase implements ShooterIO { m_shooter1Motor= shooter1Motor; m_shooter2Motor= shooter2Motor; m_indexerMotor = indexerMotor; - + m_shooter1Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID); + m_shooter2Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID); + m_indexerMotor.getConfigurator().apply(ShooterConstants.SHOOTER_PID); + m_shooter1Motor.getConfigurator().apply(ShooterConstants.SHOOTER1_MOTOR_CONFIG); m_shooter2Motor.getConfigurator().apply(ShooterConstants.SHOOTER2_MOTOR_CONFIG); @@ -47,24 +50,9 @@ public class ShooterReal extends SubsystemBase implements ShooterIO { } } - public static Slot0Configs SHOOTER_PID; - - static { - SHOOTER_PID = new Slot0Configs(); - SHOOTER_PID.kV = 0.0; - SHOOTER_PID.kP = 0.0; - SHOOTER_PID.kI = 0.0; - SHOOTER_PID.kD = 0.0; - } - ConfigurableDouble kV = new ConfigurableDouble("Shooter kV", 0.12); - ConfigurableDouble kP = new ConfigurableDouble("Shooter kP", 0.11); - ConfigurableDouble kI = new ConfigurableDouble("Shooter kI", 0.48); - ConfigurableDouble kD = new ConfigurableDouble("Shooter kD", 0.01); - - - + // // TODO: Test // @Override @@ -96,32 +84,15 @@ public class ShooterReal extends SubsystemBase implements ShooterIO { // m_pitchMotor.setControl(posRequest); // } - @Override - public void periodic() { - - SHOOTER_PID = new Slot0Configs(); - SHOOTER_PID.kV = kV.get(); - SHOOTER_PID.kP = kP.get(); - SHOOTER_PID.kI = kI.get(); - SHOOTER_PID.kD = kD.get(); - - m_shooter1Motor.getConfigurator().apply(SHOOTER_PID); - m_shooter2Motor.getConfigurator().apply(SHOOTER_PID); - } - @Override public void setMotor1Velocity(ShooterState state, AngularVelocity target) { + state.motor1TargetVelocity = target; state.motor2TargetVelocity = target; + double motorRps = target.in(RotationsPerSecond) / ShooterConstants.INDEXER_GEAR_RATIO; - m_indexerMotor.setControl(new VelocityDutyCycle(motorRps)); - } - - @Override - public void setMotor2Velocity(ShooterState state, AngularVelocity target) { - state.motor2TargetVelocity = target; - double motorRps = target.in(RotationsPerSecond) / ShooterConstants.INDEXER_GEAR_RATIO; - m_indexerMotor.setControl(new VelocityDutyCycle(motorRps)); + m_shooter1Motor.setControl(new VelocityDutyCycle(motorRps)); + m_shooter2Motor.setControl(new VelocityDutyCycle(motorRps)); } @Override @@ -134,12 +105,15 @@ public class ShooterReal extends SubsystemBase implements ShooterIO { @Override public void updateInputs(ShooterState state) { - state.motorVelocity = m_shooter1Motor.getVelocity().getValue(); - state.motorVelocity = m_shooter2Motor.getVelocity().getValue(); - state.motorVelocity = m_indexerMotor.getVelocity().getValue(); + state.motor1Velocity = m_shooter1Motor.getVelocity().getValue(); + state.motor2Velocity = m_shooter2Motor.getVelocity().getValue(); + state.indexerVelocity = m_indexerMotor.getVelocity().getValue(); state.motorLinearVelocity = InchesPerSecond.of(m_shooter1Motor.getVelocity().getValue().in(RotationsPerSecond) * ShooterConstants.FEEDER_INCHES_PER_ROT); + state.motor1Current = m_shooter1Motor.getStatorCurrent().getValue(); + state.motor2Current = m_shooter2Motor.getStatorCurrent().getValue(); + state.indexerCurrent = m_indexerMotor.getStatorCurrent().getValue(); } }